Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
Email Email_Module  

Email_Module

The script

Category: Email
By : Christopher Omega
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for Email_Module
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Email_Module_1.lsl
Get file # 2. Email_Module_2.lsl
Get file # 3. Email_Module_3.lsl
1 // In order to preserve the integrity of the sent data, a seperater
2 // (declared below as a global constant) is prepended the message before it is sent.
3 // This is so programs can easily discard the additional data Linden Lab's email
4 // server prepends to the message passed to llEmail.
5
6 // The suffix added to an object's UUID to send an email
7 // to it via llEmail.
8 string OBJECT_EMAIL_SUFFIX = "@lsl.secondlife.com";
9
10 // Specifies the amount of time between object email polls.
11 float EMAIL_POLL_INTERVAL = 5.0;
12
13 // Seperator between crap LL prepends to llEmail-sent messages and the real message.
14 string REAL_DATA_SEPERATOR = "#_|#|_#";
15
16 // Name of llEmail-calling worker object.
17 string EMAIL_OBJECT_NAME = "email";
18
19
20 // ========== For method invocation ==========
21 string randomSeperator(integer len) {
22 integer firstChar = (integer)llFrand(60) + 20; // Range of printable chars = 0x20 to 0x7E
23 if(len <= 1)
24 return llUnescapeURL("%"+(string)firstChar);
25 integer lastChar;
26 do { // Last char must not equal first char.
27 lastChar = (integer)llFrand(60) + 20;
28 } while(lastChar == firstChar);
29 string ret = llUnescapeURL("%"+(string)firstChar);
30 for (len -= 2; len > 0; --len)
31 ret += llUnescapeURL("%" + (string)((integer)llFrand(60) + 20));
32 return ret + llUnescapeURL("%"+(string)lastChar);
33 }
34
35 string listToString(list src) {
36 string chars = (string) src; // Squashes all elements together.
37 string seperator;
38 do { // Find a seperator that's not in the list's string form
39 seperator = randomSeperator(3); // so we dont kill data.
40 } while(llSubStringIndex(chars, seperator) != -1);
41 return seperator + llDumpList2String(src, seperator);
42 }
43
44 list stringToList(string src) { // First 3 chars is seperator.
46 [llGetSubString(src, 0, 2)], []);
47 }
48
49 callMethod(integer identifyer, string methodName, list parameters) {
50 llMessageLinked(LINK_THIS, identifyer, // ID only necessary for return value.
51 listToString(parameters), methodName);
52 }
53
54 returnValue(integer identifyer, string methodName, list value) {
55 callMethod(identifyer, methodName + "_ret", value);
56 }
57 // =============================================
58
59 // Events triggered by this module:
60 m_receivedEmailData(string timestamp, string senderAddress, string senderSubject, string senderMessage) {
61 callMethod(0, "receivedEmailData", [timestamp, senderAddress, senderSubject, senderMessage]);
62 }
63
64 m_moduleReset(string moduleName) {
65 callMethod(0, "moduleReset", [moduleName]);
66 }
67
68 // Methods called:
69 m_chat(integer channel, string message) {
70 callMethod(0, "chat", [channel, message]);
71 }
72
73 sendEmail(string address, string subject, string message) {
75 integer chan = (integer) llFrand(10394) + 1;
76 // Scripts in the email object do the actual sending.
78 m_chat(chan, listToString([address, subject, REAL_DATA_SEPERATOR + message]));
79 } else {
80 // Unable to delegate llEmail call.
81 llEmail(address, subject, message);
82 }
83 }
84
85 // Global variables:
86 string this;
87
88 default {
89 state_entry() {
90 this = llGetScriptName();
91 m_moduleReset(this);
93 || llGetInventoryType("ChatCodec") == INVENTORY_NONE) {
94 llOwnerSay("Warning: Rapid llEmail optimization unavailable,"
95 + "missing ChatCodec module or email object.");
96 }
97 state main;
98 }
99 }
100
101 state main {
102 state_entry() {
103 llSetTimerEvent(EMAIL_POLL_INTERVAL);
104 }
105
106 link_message(integer sender, integer callId, string parameters, key methodName) {
107 if(methodName == "sendEmailData") {
108 list paramList = stringToList(parameters);
109 // Method signature:
110 // sendEmailData(string address, string subject, string message);
111 string address = llList2String(paramList, 0);
112 string subject = llList2String(paramList, 1);
113 string message = llList2String(paramList, 2);
114 sendEmail(address, subject, message);
115 } else if(methodName == "sendObjectEmail") {
116 list paramList = stringToList(parameters);
117 // Method signature:
118 // sendObjectEmail(key objectKey, string subject, string message)
119 key objectKey = (key) llList2String(paramList, 0);
120 string subject = llList2String(paramList, 1);
121 string message = llList2String(paramList, 2);
122 sendEmail((string)objectKey + OBJECT_EMAIL_SUFFIX, subject, message);
123 } else if(methodName == "moduleReady") {
124 list paramList = stringToList(parameters);
125 string module = llList2String(paramList, 0);
126 if(module == this)
127 returnValue(callId, methodName, [TRUE]);
128 }
129 }
130
131 timer() {
132 llGetNextEmail("", "");
133 }
134
135 email(string timestamp, string senderAddress, string senderSubject,
136 string senderMessage, integer numQueued) {
138 if(llSubStringIndex(senderMessage, REAL_DATA_SEPERATOR) != -1)
139 senderMessage = llDumpList2String(llDeleteSubList(llParseStringKeepNulls(senderMessage, [REAL_DATA_SEPERATOR], []), 0, 0), REAL_DATA_SEPERATOR);
140 m_receivedEmailData(timestamp, senderAddress, senderSubject, senderMessage);
141
142 if(numQueued > 0) {
143 llGetNextEmail("", "");
144 } else {
145 llSetTimerEvent(EMAIL_POLL_INTERVAL);
146 }
147 }
148 }

Email_Module

To use this module, copy and paste the above into a script and name it "EmailModule". The script requires ChatCodec in the same object's inventory. To send emails, an object named "email" must be in the same object's inventory as EmailModule. The object named "email" must also contain ChatCodec and the script below:

Category: Email
By : Christopher Omega
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

1 // Copyright (c) 2006 Francisco V. Saldana (Christopher Omega)
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy of
4 // this software and associated documentation files (the "Software"), to deal in
5 // the Software without restriction, including without limitation the rights to use,
6 // copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
7 // Software, and to permit persons to whom the Software is furnished to do so,
8 // subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in all
11 // copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17 // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18 // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
20 // Deligates llEmail-calling duties, so EmailModule doesn't need to incur the 20-second delay.
21 // Requires ChatCodec.
22
23 // ========== For method invocation ==========
24 string randomSeperator(integer len) {
25 integer firstChar = (integer)llFrand(60) + 20; // Range of printable chars = 0x20 to 0x7E
26 if(len <= 1)
27 return llUnescapeURL("%"+(string)firstChar);
28 integer lastChar;
29 do { // Last char must not equal first char.
30 lastChar = (integer)llFrand(60) + 20;
31 } while(lastChar == firstChar);
32 string ret = llUnescapeURL("%"+(string)firstChar);
33 for (len -= 2; len > 0; --len)
34 ret += llUnescapeURL("%" + (string)((integer)llFrand(60) + 20));
35 return ret + llUnescapeURL("%"+(string)lastChar);
36 }
37
38 string listToString(list src) {
39 string chars = (string) src; // Squashes all elements together.
40 string seperator;
41 do { // Find a seperator that's not in the list's string form
42 seperator = randomSeperator(3); // so we dont kill data.
43 } while(llSubStringIndex(chars, seperator) != -1);
44 return seperator + llDumpList2String(src, seperator);
45 }
46
47 list stringToList(string src) { // First 3 chars is seperator.
49 [llGetSubString(src, 0, 2)], []);
50 }
51
52 callMethod(integer identifyer, string methodName, list parameters) {
53 llMessageLinked(LINK_THIS, identifyer, // ID only necessary for return value.
54 listToString(parameters), methodName);
55 }
56
57 returnValue(integer identifyer, string methodName, list value) {
58 callMethod(identifyer, methodName + "_ret", value);
59 }
60 // =============================================
61
62 m_addChatHandle(string moduleName, integer channel) {
63 callMethod(0, "addChatHandle", [moduleName, channel]);
64 }
65
66 m_moduleReset(string moduleName) {
67 callMethod(0, "moduleName", []);
68 }
69
70 string this;
71 default {
72 state_entry() {
73 this = llGetScriptName();
74 m_moduleReset(this);
75 }
76 on_rez(integer param) {
77 if(param != 0) {
79 m_addChatHandle(this, param);
80 }
81 }
82 link_message(integer sender, integer call, string params, key methodName) {
83 if(methodName == "receivedChatData") {
84 list paramList = stringToList(params);
85 // Method sig:
86 // receivedChatData(integer channel, string name, key id, string message)
87 integer channel = (integer) llList2String(paramList, 0);
88 string name = llList2String(paramList, 1);
89 key id = (key) llList2String(paramList, 2);
90 string message = llList2String(paramList, 3);
91 if(channel == llGetStartParameter()) {
92 list paramList = stringToList(message);
93 llEmail(llList2String(paramList, 0), llList2String(paramList, 1), llList2String(paramList, 2));
94 llDie();
95 }
96 }
97 }
98 }

Email_Module


Here's an example script that utilizes this module:

Category: Email
By : Christopher Omega
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

1 // ========== For method invocation ==========
2 string randomSeperator(integer len) {
3 integer firstChar = (integer)llFrand(60) + 20; // Range of printable chars = 0x20 to 0x7E
4 if(len <= 1)
5 return llUnescapeURL("%"+(string)firstChar);
6 integer lastChar;
7 do { // Last char must not equal first char.
8 lastChar = (integer)llFrand(60) + 20;
9 } while(lastChar == firstChar);
10 string ret = llUnescapeURL("%"+(string)firstChar);
11 for (len -= 2; len > 0; --len)
12 ret += llUnescapeURL("%" + (string)((integer)llFrand(60) + 20));
13 return ret + llUnescapeURL("%"+(string)lastChar);
14 }
15
16 string listToString(list src) {
17 string chars = (string) src; // Squashes all elements together.
18 string seperator;
19 do { // Find a seperator that's not in the list's string form
20 seperator = randomSeperator(3); // so we dont kill data.
21 } while(llSubStringIndex(chars, seperator) != -1);
22 return seperator + llDumpList2String(src, seperator);
23 }
24
25 list stringToList(string src) { // First 3 chars is seperator.
27 [llGetSubString(src, 0, 2)], []);
28 }
29
30 callMethod(integer identifyer, string methodName, list parameters) {
31 llMessageLinked(LINK_THIS, identifyer, // ID only necessary for return value.
32 listToString(parameters), methodName);
33 }
34
35 returnValue(integer identifyer, string methodName, list value) {
36 callMethod(identifyer, methodName + "_ret", value);
37 }
38 // =============================================
39
40 // Replacement for llEmail:
41 m_sendEmailData(string address, string subject, string message) {
42 callMethod(0, "sendEmailData", [address, subject, message]);
43 }
44
45 // Handy wrapper that makes object<->object emails simpler:
46 m_sendObjectEmail(key uuid, string subject, string message) {
47 callMethod(0, "sendObjectEmail", [uuid, subject, message]);
48 }
49
50 default {
51 state_entry() {
52 m_sendEmailData("foo.bar@fubar.com", "BOOM!", "Happy April Fools Day!");
53 m_sendObjectEmail("a003e27c-1623-ae7d-3bdb-19e26d4986e2", "explode", "confetti");
54 }
55 link_message(integer sender, integer callIdent, string params, key methodName) {
56 if(methodName == "receivedEmailData") {
57 list paramList = stringToList(params);
58 string timestamp = llList2String(paramList, 0);
59 string from = llList2String(paramList, 1);
60 string subject = llList2String(paramList, 2);
61 string message = llList2String(paramList, 3);
62 // email event code goes here.
63 if(subject == "damn you" && from == "foo.bar@fubar.com") {
64 m_sendEmailData("foo.bar@fubar.com", ":-P", "haha");
65 }
66 }
67 }
68 }

Back to the Best Free Tools in Second Life and OpenSim.