aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
authorMelanie Thielker2009-02-14 21:25:22 +0000
committerMelanie Thielker2009-02-14 21:25:22 +0000
commit4bc52888be74b720431df2fbe3409c6e11a3029f (patch)
treef4674616768deff7134b33a61e9ca74ce915b132 /OpenSim/Region
parentRemove the "?" that I inadvertently got into the first line (diff)
downloadopensim-SC_OLD-4bc52888be74b720431df2fbe3409c6e11a3029f.zip
opensim-SC_OLD-4bc52888be74b720431df2fbe3409c6e11a3029f.tar.gz
opensim-SC_OLD-4bc52888be74b720431df2fbe3409c6e11a3029f.tar.bz2
opensim-SC_OLD-4bc52888be74b720431df2fbe3409c6e11a3029f.tar.xz
Thank you, DoranZemlja, for a patch that implements local inter-object email
delivery. Leaving Mantis #3145 open so that more code can be added.
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/CoreModules/Scripting/EMailModules/EmailModule.cs166
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs9
2 files changed, 135 insertions, 40 deletions
diff --git a/OpenSim/Region/CoreModules/Scripting/EMailModules/EmailModule.cs b/OpenSim/Region/CoreModules/Scripting/EMailModules/EmailModule.cs
index 81d3600..5775b56 100644
--- a/OpenSim/Region/CoreModules/Scripting/EMailModules/EmailModule.cs
+++ b/OpenSim/Region/CoreModules/Scripting/EMailModules/EmailModule.cs
@@ -57,12 +57,32 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules
57 private string SMTP_SERVER_LOGIN = string.Empty; 57 private string SMTP_SERVER_LOGIN = string.Empty;
58 private string SMTP_SERVER_PASSWORD = string.Empty; 58 private string SMTP_SERVER_PASSWORD = string.Empty;
59 59
60 private int m_MaxQueueSize = 50; // maximum size of an object mail queue
61 private Dictionary<UUID, List<Email>> m_MailQueues = new Dictionary<UUID, List<Email>>();
62 private string m_InterObjectHostname;
63
60 // Scenes by Region Handle 64 // Scenes by Region Handle
61 private Dictionary<ulong, Scene> m_Scenes = 65 private Dictionary<ulong, Scene> m_Scenes =
62 new Dictionary<ulong, Scene>(); 66 new Dictionary<ulong, Scene>();
63 67
64 private bool m_Enabled = false; 68 private bool m_Enabled = false;
65 69
70 public void InsertEmail(UUID to, Email email)
71 {
72 if (!m_MailQueues.ContainsKey(to))
73 {
74 m_MailQueues.Add(to, new List<Email>());
75 }
76
77 if (m_MailQueues[to].Count >= m_MaxQueueSize)
78 {
79 // fail silently
80 return;
81 }
82
83 m_MailQueues[to].Add(email);
84 }
85
66 public void Initialise(Scene scene, IConfigSource config) 86 public void Initialise(Scene scene, IConfigSource config)
67 { 87 {
68 m_Config = config; 88 m_Config = config;
@@ -93,7 +113,8 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules
93 } 113 }
94 114
95 m_HostName = SMTPConfig.GetString("host_domain_header_from", m_HostName); 115 m_HostName = SMTPConfig.GetString("host_domain_header_from", m_HostName);
96 SMTP_SERVER_HOSTNAME = SMTPConfig.GetString("SMTP_SERVER_HOSTNAME",SMTP_SERVER_HOSTNAME); 116 m_InterObjectHostname = SMTPConfig.GetString("internal_object_host", "lsl.secondlife.com");
117 SMTP_SERVER_HOSTNAME = SMTPConfig.GetString("SMTP_SERVER_HOSTNAME", SMTP_SERVER_HOSTNAME);
97 SMTP_SERVER_PORT = SMTPConfig.GetInt("SMTP_SERVER_PORT", SMTP_SERVER_PORT); 118 SMTP_SERVER_PORT = SMTPConfig.GetInt("SMTP_SERVER_PORT", SMTP_SERVER_PORT);
98 SMTP_SERVER_LOGIN = SMTPConfig.GetString("SMTP_SERVER_LOGIN", SMTP_SERVER_LOGIN); 119 SMTP_SERVER_LOGIN = SMTPConfig.GetString("SMTP_SERVER_LOGIN", SMTP_SERVER_LOGIN);
99 SMTP_SERVER_PASSWORD = SMTPConfig.GetString("SMTP_SERVER_PASSWORD", SMTP_SERVER_PASSWORD); 120 SMTP_SERVER_PASSWORD = SMTPConfig.GetString("SMTP_SERVER_PASSWORD", SMTP_SERVER_PASSWORD);
@@ -160,6 +181,12 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules
160 } 181 }
161 } 182 }
162 183
184 private bool IsLocal(UUID objectID)
185 {
186 string unused;
187 return (null != findPrim(objectID, out unused));
188 }
189
163 private SceneObjectPart findPrim(UUID objectID, out string ObjectRegionName) 190 private SceneObjectPart findPrim(UUID objectID, out string ObjectRegionName)
164 { 191 {
165 lock (m_Scenes) 192 lock (m_Scenes)
@@ -228,47 +255,81 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules
228 return; 255 return;
229 } 256 }
230 257
231 try 258 string LastObjectName = string.Empty;
259 string LastObjectPosition = string.Empty;
260 string LastObjectRegionName = string.Empty;
261 //DONE: Message as Second Life style
262 //20 second delay - AntiSpam System - for now only 10 seconds
263 DelayInSeconds(10);
264
265 resolveNamePositionRegionName(objectID, out LastObjectName, out LastObjectPosition, out LastObjectRegionName);
266
267 if (!address.EndsWith(m_InterObjectHostname))
232 { 268 {
233 string LastObjectName = string.Empty; 269 // regular email, send it out
234 string LastObjectPosition = string.Empty; 270 try
235 string LastObjectRegionName = string.Empty; 271 {
236 //DONE: Message as Second Life style 272 //Creation EmailMessage
237 //20 second delay - AntiSpam System - for now only 10 seconds 273 EmailMessage emailMessage = new EmailMessage();
238 DelayInSeconds(10); 274 //From
239 //Creation EmailMessage 275 emailMessage.FromAddress = new EmailAddress(objectID.ToString() + "@" + m_HostName);
240 EmailMessage emailMessage = new EmailMessage(); 276 //To - Only One
241 //From 277 emailMessage.AddToAddress(new EmailAddress(address));
242 emailMessage.FromAddress = new EmailAddress(objectID.ToString()+"@"+m_HostName); 278 //Subject
243 //To - Only One 279 emailMessage.Subject = subject;
244 emailMessage.AddToAddress(new EmailAddress(address)); 280 //TEXT Body
245 //Subject 281 resolveNamePositionRegionName(objectID, out LastObjectName, out LastObjectPosition, out LastObjectRegionName);
246 emailMessage.Subject = subject; 282 emailMessage.TextPart = new TextAttachment("Object-Name: " + LastObjectName +
247 //TEXT Body 283 "\r\nRegion: " + LastObjectRegionName + "\r\nLocal-Position: " +
248 resolveNamePositionRegionName(objectID, out LastObjectName, out LastObjectPosition, out LastObjectRegionName); 284 LastObjectPosition + "\r\n\r\n" + body);
249 emailMessage.TextPart = new TextAttachment("Object-Name: " + LastObjectName + 285
250 "\r\nRegion: " + LastObjectRegionName + "\r\nLocal-Position: " + 286 //HTML Body
251 LastObjectPosition+"\r\n\r\n\r\n" + body); 287 emailMessage.HtmlPart = new HtmlAttachment("<html><body><p>" +
252 //HTML Body 288 "<BR>Object-Name: " + LastObjectName +
253 emailMessage.HtmlPart = new HtmlAttachment("<html><body><p>" + 289 "<BR>Region: " + LastObjectRegionName +
254 "<BR>Object-Name: " + LastObjectName + 290 "<BR>Local-Position: " + LastObjectPosition + "<BR><BR><BR>"
255 "<BR>Region: " + LastObjectRegionName + 291 + body + "\r\n</p></body><html>");
256 "<BR>Local-Position: " + LastObjectPosition + "<BR><BR><BR>" 292
257 +body+"\r\n</p></body><html>"); 293 //Set SMTP SERVER config
258 294 SmtpServer smtpServer = new SmtpServer(SMTP_SERVER_HOSTNAME, SMTP_SERVER_PORT);
259 //Set SMTP SERVER config 295 //Authentication
260 SmtpServer smtpServer=new SmtpServer(SMTP_SERVER_HOSTNAME,SMTP_SERVER_PORT); 296 smtpServer.SmtpAuthToken = new SmtpAuthToken(SMTP_SERVER_LOGIN, SMTP_SERVER_PASSWORD);
261 //Authentication 297 //Send Email Message
262 smtpServer.SmtpAuthToken=new SmtpAuthToken(SMTP_SERVER_LOGIN, SMTP_SERVER_PASSWORD); 298 emailMessage.Send(smtpServer);
263 //Send Email Message 299 //Log
264 emailMessage.Send(smtpServer); 300 m_log.Info("[EMAIL] EMail sent to: " + address + " from object: " + objectID.ToString());
265 //Log 301 }
266 m_log.Info("[EMAIL] EMail sent to: " + address + " from object: " + objectID.ToString()); 302 catch (Exception e)
303 {
304 m_log.Error("[EMAIL] DefaultEmailModule Exception: " + e.Message);
305 return;
306 }
267 } 307 }
268 catch (Exception e) 308 else
269 { 309 {
270 m_log.Error("[EMAIL] DefaultEmailModule Exception: "+e.Message); 310 // inter object email, keep it in the family
271 return; 311 Email email = new Email();
312 email.time = ((DateTime.UtcNow - new DateTime(1970,1,1,0,0,0)).TotalSeconds).ToString();
313 email.subject = subject;
314 email.sender = objectID.ToString() + "@" + m_InterObjectHostname;
315 email.message = "Object-Name: " + LastObjectName +
316 "\nRegion: " + LastObjectRegionName + "\nLocal-Position: " +
317 LastObjectPosition + "\n\n" + body;
318
319 UUID toID = new UUID(address.Substring(0, address.IndexOf("@")));
320
321 String unused;
322
323 if (IsLocal(toID)) // TODO FIX check to see if it is local
324 {
325 // object in this region
326 InsertEmail(toID, email);
327 }
328 else
329 {
330 // object on another region
331 // TODO FIX
332 }
272 } 333 }
273 } 334 }
274 335
@@ -281,6 +342,33 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules
281 /// <returns></returns> 342 /// <returns></returns>
282 public Email GetNextEmail(UUID objectID, string sender, string subject) 343 public Email GetNextEmail(UUID objectID, string sender, string subject)
283 { 344 {
345 if (m_MailQueues.ContainsKey(objectID))
346 {
347 List<Email> queue = m_MailQueues[objectID];
348
349 if (queue.Count > 0)
350 {
351 int i;
352
353 for (i = 0; i < queue.Count; i++)
354 {
355 if ((sender == null || sender.Equals("") || sender.Equals(queue[i].sender)) &&
356 (subject == null || subject.Equals("") || subject.Equals(queue[i].subject)))
357 {
358 break;
359 }
360 }
361
362 if (i != queue.Count)
363 {
364 Email ret = queue[i];
365 queue.Remove(ret);
366 ret.numLeft = queue.Count;
367 return ret;
368 }
369 }
370 }
371
284 return null; 372 return null;
285 } 373 }
286 } 374 }
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index ed9d3ee..9f5d143 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -2702,7 +2702,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2702 m_host.AddScriptLPS(1); 2702 m_host.AddScriptLPS(1);
2703 IEmailModule emailModule = m_ScriptEngine.World.RequestModuleInterface<IEmailModule>(); 2703 IEmailModule emailModule = m_ScriptEngine.World.RequestModuleInterface<IEmailModule>();
2704 if (emailModule == null) 2704 if (emailModule == null)
2705 {
2706 ShoutError("llEmail: email module not configured");
2705 return; 2707 return;
2708 }
2706 2709
2707 emailModule.SendEmail(m_host.UUID, address, subject, message); 2710 emailModule.SendEmail(m_host.UUID, address, subject, message);
2708 // ScriptSleep(20000); 2711 // ScriptSleep(20000);
@@ -2713,7 +2716,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2713 m_host.AddScriptLPS(1); 2716 m_host.AddScriptLPS(1);
2714 IEmailModule emailModule = m_ScriptEngine.World.RequestModuleInterface<IEmailModule>(); 2717 IEmailModule emailModule = m_ScriptEngine.World.RequestModuleInterface<IEmailModule>();
2715 if (emailModule == null) 2718 if (emailModule == null)
2719 {
2720 ShoutError("llGetNextEmail: email module not configured");
2716 return; 2721 return;
2722 }
2717 Email email; 2723 Email email;
2718 2724
2719 email = emailModule.GetNextEmail(m_host.UUID, address, subject); 2725 email = emailModule.GetNextEmail(m_host.UUID, address, subject);
@@ -3668,11 +3674,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3668 3674
3669 UUID partItemID; 3675 UUID partItemID;
3670 foreach (SceneObjectPart part in parts) 3676 foreach (SceneObjectPart part in parts)
3677 {
3671 foreach (TaskInventoryItem item in part.TaskInventory.Values) 3678 foreach (TaskInventoryItem item in part.TaskInventory.Values)
3672 { 3679 {
3673 if (item.Type == ScriptBaseClass.INVENTORY_SCRIPT) 3680 if (item.Type == ScriptBaseClass.INVENTORY_SCRIPT)
3674 { 3681 {
3675
3676 partItemID = item.ItemID; 3682 partItemID = item.ItemID;
3677 int linkNumber = m_host.LinkNum; 3683 int linkNumber = m_host.LinkNum;
3678 if (m_host.ParentGroup.Children.Count == 1) 3684 if (m_host.ParentGroup.Children.Count == 1)
@@ -3689,6 +3695,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3689 resobj, new DetectParams[0])); 3695 resobj, new DetectParams[0]));
3690 } 3696 }
3691 } 3697 }
3698 }
3692 } 3699 }
3693 3700
3694 public void llPushObject(string target, LSL_Vector impulse, LSL_Vector ang_impulse, int local) 3701 public void llPushObject(string target, LSL_Vector impulse, LSL_Vector ang_impulse, int local)