aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorMelanie Thielker2009-02-15 01:06:03 +0000
committerMelanie Thielker2009-02-15 01:06:03 +0000
commit7ea2812a9e9a76f71d56f3db3b01e88aa2c6e7ee (patch)
tree418467fec5d5bba1bd2bf0870ca1c6a5856604b2 /OpenSim
parentMantis 3164. Thank you kindly, TLaukkan (Tommil) for a patch that: (diff)
downloadopensim-SC_OLD-7ea2812a9e9a76f71d56f3db3b01e88aa2c6e7ee.zip
opensim-SC_OLD-7ea2812a9e9a76f71d56f3db3b01e88aa2c6e7ee.tar.gz
opensim-SC_OLD-7ea2812a9e9a76f71d56f3db3b01e88aa2c6e7ee.tar.bz2
opensim-SC_OLD-7ea2812a9e9a76f71d56f3db3b01e88aa2c6e7ee.tar.xz
Thank you, DoranZemlja, for a patch that addresses some moe llGetNextEmail
issues. Fixes Mantis #3145.
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/CoreModules/Scripting/EMailModules/EmailModule.cs125
1 files changed, 88 insertions, 37 deletions
diff --git a/OpenSim/Region/CoreModules/Scripting/EMailModules/EmailModule.cs b/OpenSim/Region/CoreModules/Scripting/EMailModules/EmailModule.cs
index 5775b56..9e2abf2 100644
--- a/OpenSim/Region/CoreModules/Scripting/EMailModules/EmailModule.cs
+++ b/OpenSim/Region/CoreModules/Scripting/EMailModules/EmailModule.cs
@@ -59,7 +59,9 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules
59 59
60 private int m_MaxQueueSize = 50; // maximum size of an object mail queue 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>>(); 61 private Dictionary<UUID, List<Email>> m_MailQueues = new Dictionary<UUID, List<Email>>();
62 private string m_InterObjectHostname; 62 private Dictionary<UUID, DateTime> m_LastGetEmailCall = new Dictionary<UUID, DateTime>();
63 private TimeSpan m_QueueTimeout = new TimeSpan(2, 0, 0); // 2 hours without llGetNextEmail drops the queue
64 private string m_InterObjectHostname = "lsl.opensim.local";
63 65
64 // Scenes by Region Handle 66 // Scenes by Region Handle
65 private Dictionary<ulong, Scene> m_Scenes = 67 private Dictionary<ulong, Scene> m_Scenes =
@@ -69,18 +71,26 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules
69 71
70 public void InsertEmail(UUID to, Email email) 72 public void InsertEmail(UUID to, Email email)
71 { 73 {
72 if (!m_MailQueues.ContainsKey(to)) 74 // It's tempting to create the queue here. Don't; objects which have
73 { 75 // not yet called GetNextEmail should have no queue, and emails to them
74 m_MailQueues.Add(to, new List<Email>()); 76 // should be silently dropped.
75 }
76 77
77 if (m_MailQueues[to].Count >= m_MaxQueueSize) 78 lock (m_MailQueues)
78 { 79 {
79 // fail silently 80 if (m_MailQueues.ContainsKey(to))
80 return; 81 {
81 } 82 if (m_MailQueues[to].Count >= m_MaxQueueSize)
83 {
84 // fail silently
85 return;
86 }
82 87
83 m_MailQueues[to].Add(email); 88 lock (m_MailQueues[to])
89 {
90 m_MailQueues[to].Add(email);
91 }
92 }
93 }
84 } 94 }
85 95
86 public void Initialise(Scene scene, IConfigSource config) 96 public void Initialise(Scene scene, IConfigSource config)
@@ -113,7 +123,7 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules
113 } 123 }
114 124
115 m_HostName = SMTPConfig.GetString("host_domain_header_from", m_HostName); 125 m_HostName = SMTPConfig.GetString("host_domain_header_from", m_HostName);
116 m_InterObjectHostname = SMTPConfig.GetString("internal_object_host", "lsl.secondlife.com"); 126 m_InterObjectHostname = SMTPConfig.GetString("internal_object_host", m_InterObjectHostname);
117 SMTP_SERVER_HOSTNAME = SMTPConfig.GetString("SMTP_SERVER_HOSTNAME", SMTP_SERVER_HOSTNAME); 127 SMTP_SERVER_HOSTNAME = SMTPConfig.GetString("SMTP_SERVER_HOSTNAME", SMTP_SERVER_HOSTNAME);
118 SMTP_SERVER_PORT = SMTPConfig.GetInt("SMTP_SERVER_PORT", SMTP_SERVER_PORT); 128 SMTP_SERVER_PORT = SMTPConfig.GetInt("SMTP_SERVER_PORT", SMTP_SERVER_PORT);
119 SMTP_SERVER_LOGIN = SMTPConfig.GetString("SMTP_SERVER_LOGIN", SMTP_SERVER_LOGIN); 129 SMTP_SERVER_LOGIN = SMTPConfig.GetString("SMTP_SERVER_LOGIN", SMTP_SERVER_LOGIN);
@@ -279,16 +289,9 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules
279 emailMessage.Subject = subject; 289 emailMessage.Subject = subject;
280 //TEXT Body 290 //TEXT Body
281 resolveNamePositionRegionName(objectID, out LastObjectName, out LastObjectPosition, out LastObjectRegionName); 291 resolveNamePositionRegionName(objectID, out LastObjectName, out LastObjectPosition, out LastObjectRegionName);
282 emailMessage.TextPart = new TextAttachment("Object-Name: " + LastObjectName + 292 emailMessage.BodyText = "Object-Name: " + LastObjectName +
283 "\r\nRegion: " + LastObjectRegionName + "\r\nLocal-Position: " + 293 "\nRegion: " + LastObjectRegionName + "\nLocal-Position: " +
284 LastObjectPosition + "\r\n\r\n" + body); 294 LastObjectPosition + "\n\n" + body;
285
286 //HTML Body
287 emailMessage.HtmlPart = new HtmlAttachment("<html><body><p>" +
288 "<BR>Object-Name: " + LastObjectName +
289 "<BR>Region: " + LastObjectRegionName +
290 "<BR>Local-Position: " + LastObjectPosition + "<BR><BR><BR>"
291 + body + "\r\n</p></body><html>");
292 295
293 //Set SMTP SERVER config 296 //Set SMTP SERVER config
294 SmtpServer smtpServer = new SmtpServer(SMTP_SERVER_HOSTNAME, SMTP_SERVER_PORT); 297 SmtpServer smtpServer = new SmtpServer(SMTP_SERVER_HOSTNAME, SMTP_SERVER_PORT);
@@ -309,7 +312,7 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules
309 { 312 {
310 // inter object email, keep it in the family 313 // inter object email, keep it in the family
311 Email email = new Email(); 314 Email email = new Email();
312 email.time = ((DateTime.UtcNow - new DateTime(1970,1,1,0,0,0)).TotalSeconds).ToString(); 315 email.time = ((int)((DateTime.UtcNow - new DateTime(1970,1,1,0,0,0)).TotalSeconds)).ToString();
313 email.subject = subject; 316 email.subject = subject;
314 email.sender = objectID.ToString() + "@" + m_InterObjectHostname; 317 email.sender = objectID.ToString() + "@" + m_InterObjectHostname;
315 email.message = "Object-Name: " + LastObjectName + 318 email.message = "Object-Name: " + LastObjectName +
@@ -342,32 +345,80 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules
342 /// <returns></returns> 345 /// <returns></returns>
343 public Email GetNextEmail(UUID objectID, string sender, string subject) 346 public Email GetNextEmail(UUID objectID, string sender, string subject)
344 { 347 {
345 if (m_MailQueues.ContainsKey(objectID)) 348 List<Email> queue = null;
349
350 lock (m_LastGetEmailCall)
346 { 351 {
347 List<Email> queue = m_MailQueues[objectID]; 352 if (m_LastGetEmailCall.ContainsKey(objectID))
353 {
354 m_LastGetEmailCall.Remove(objectID);
355 }
356
357 m_LastGetEmailCall.Add(objectID, DateTime.Now);
358
359 // Hopefully this isn't too time consuming. If it is, we can always push it into a worker thread.
360 DateTime now = DateTime.Now;
361 List<UUID> removal = new List<UUID>();
362 foreach (UUID uuid in m_LastGetEmailCall.Keys)
363 {
364 if ((now - m_LastGetEmailCall[uuid]) > m_QueueTimeout)
365 {
366 removal.Add(uuid);
367 }
368 }
348 369
349 if (queue.Count > 0) 370 foreach (UUID remove in removal)
350 { 371 {
351 int i; 372 m_LastGetEmailCall.Remove(remove);
373 lock (m_MailQueues)
374 {
375 m_MailQueues.Remove(remove);
376 }
377 }
378 }
352 379
353 for (i = 0; i < queue.Count; i++) 380 lock (m_MailQueues)
381 {
382 if (m_MailQueues.ContainsKey(objectID))
383 {
384 queue = m_MailQueues[objectID];
385 }
386 }
387
388 if (queue != null)
389 {
390 lock (queue)
391 {
392 if (queue.Count > 0)
354 { 393 {
355 if ((sender == null || sender.Equals("") || sender.Equals(queue[i].sender)) && 394 int i;
356 (subject == null || subject.Equals("") || subject.Equals(queue[i].subject))) 395
396 for (i = 0; i < queue.Count; i++)
357 { 397 {
358 break; 398 if ((sender == null || sender.Equals("") || sender.Equals(queue[i].sender)) &&
399 (subject == null || subject.Equals("") || subject.Equals(queue[i].subject)))
400 {
401 break;
402 }
359 } 403 }
360 }
361 404
362 if (i != queue.Count) 405 if (i != queue.Count)
363 { 406 {
364 Email ret = queue[i]; 407 Email ret = queue[i];
365 queue.Remove(ret); 408 queue.Remove(ret);
366 ret.numLeft = queue.Count; 409 ret.numLeft = queue.Count;
367 return ret; 410 return ret;
411 }
368 } 412 }
369 } 413 }
370 } 414 }
415 else
416 {
417 lock (m_MailQueues)
418 {
419 m_MailQueues.Add(objectID, new List<Email>());
420 }
421 }
371 422
372 return null; 423 return null;
373 } 424 }