From 4bc52888be74b720431df2fbe3409c6e11a3029f Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Sat, 14 Feb 2009 21:25:22 +0000 Subject: Thank you, DoranZemlja, for a patch that implements local inter-object email delivery. Leaving Mantis #3145 open so that more code can be added. --- .../Scripting/EMailModules/EmailModule.cs | 166 ++++++++++++++++----- .../Shared/Api/Implementation/LSL_Api.cs | 9 +- 2 files changed, 135 insertions(+), 40 deletions(-) (limited to 'OpenSim/Region') 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 private string SMTP_SERVER_LOGIN = string.Empty; private string SMTP_SERVER_PASSWORD = string.Empty; + private int m_MaxQueueSize = 50; // maximum size of an object mail queue + private Dictionary> m_MailQueues = new Dictionary>(); + private string m_InterObjectHostname; + // Scenes by Region Handle private Dictionary m_Scenes = new Dictionary(); private bool m_Enabled = false; + public void InsertEmail(UUID to, Email email) + { + if (!m_MailQueues.ContainsKey(to)) + { + m_MailQueues.Add(to, new List()); + } + + if (m_MailQueues[to].Count >= m_MaxQueueSize) + { + // fail silently + return; + } + + m_MailQueues[to].Add(email); + } + public void Initialise(Scene scene, IConfigSource config) { m_Config = config; @@ -93,7 +113,8 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules } m_HostName = SMTPConfig.GetString("host_domain_header_from", m_HostName); - SMTP_SERVER_HOSTNAME = SMTPConfig.GetString("SMTP_SERVER_HOSTNAME",SMTP_SERVER_HOSTNAME); + m_InterObjectHostname = SMTPConfig.GetString("internal_object_host", "lsl.secondlife.com"); + SMTP_SERVER_HOSTNAME = SMTPConfig.GetString("SMTP_SERVER_HOSTNAME", SMTP_SERVER_HOSTNAME); SMTP_SERVER_PORT = SMTPConfig.GetInt("SMTP_SERVER_PORT", SMTP_SERVER_PORT); SMTP_SERVER_LOGIN = SMTPConfig.GetString("SMTP_SERVER_LOGIN", SMTP_SERVER_LOGIN); SMTP_SERVER_PASSWORD = SMTPConfig.GetString("SMTP_SERVER_PASSWORD", SMTP_SERVER_PASSWORD); @@ -160,6 +181,12 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules } } + private bool IsLocal(UUID objectID) + { + string unused; + return (null != findPrim(objectID, out unused)); + } + private SceneObjectPart findPrim(UUID objectID, out string ObjectRegionName) { lock (m_Scenes) @@ -228,47 +255,81 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules return; } - try + string LastObjectName = string.Empty; + string LastObjectPosition = string.Empty; + string LastObjectRegionName = string.Empty; + //DONE: Message as Second Life style + //20 second delay - AntiSpam System - for now only 10 seconds + DelayInSeconds(10); + + resolveNamePositionRegionName(objectID, out LastObjectName, out LastObjectPosition, out LastObjectRegionName); + + if (!address.EndsWith(m_InterObjectHostname)) { - string LastObjectName = string.Empty; - string LastObjectPosition = string.Empty; - string LastObjectRegionName = string.Empty; - //DONE: Message as Second Life style - //20 second delay - AntiSpam System - for now only 10 seconds - DelayInSeconds(10); - //Creation EmailMessage - EmailMessage emailMessage = new EmailMessage(); - //From - emailMessage.FromAddress = new EmailAddress(objectID.ToString()+"@"+m_HostName); - //To - Only One - emailMessage.AddToAddress(new EmailAddress(address)); - //Subject - emailMessage.Subject = subject; - //TEXT Body - resolveNamePositionRegionName(objectID, out LastObjectName, out LastObjectPosition, out LastObjectRegionName); - emailMessage.TextPart = new TextAttachment("Object-Name: " + LastObjectName + - "\r\nRegion: " + LastObjectRegionName + "\r\nLocal-Position: " + - LastObjectPosition+"\r\n\r\n\r\n" + body); - //HTML Body - emailMessage.HtmlPart = new HtmlAttachment("

" + - "
Object-Name: " + LastObjectName + - "
Region: " + LastObjectRegionName + - "
Local-Position: " + LastObjectPosition + "


" - +body+"\r\n

"); - - //Set SMTP SERVER config - SmtpServer smtpServer=new SmtpServer(SMTP_SERVER_HOSTNAME,SMTP_SERVER_PORT); - //Authentication - smtpServer.SmtpAuthToken=new SmtpAuthToken(SMTP_SERVER_LOGIN, SMTP_SERVER_PASSWORD); - //Send Email Message - emailMessage.Send(smtpServer); - //Log - m_log.Info("[EMAIL] EMail sent to: " + address + " from object: " + objectID.ToString()); + // regular email, send it out + try + { + //Creation EmailMessage + EmailMessage emailMessage = new EmailMessage(); + //From + emailMessage.FromAddress = new EmailAddress(objectID.ToString() + "@" + m_HostName); + //To - Only One + emailMessage.AddToAddress(new EmailAddress(address)); + //Subject + emailMessage.Subject = subject; + //TEXT Body + resolveNamePositionRegionName(objectID, out LastObjectName, out LastObjectPosition, out LastObjectRegionName); + emailMessage.TextPart = new TextAttachment("Object-Name: " + LastObjectName + + "\r\nRegion: " + LastObjectRegionName + "\r\nLocal-Position: " + + LastObjectPosition + "\r\n\r\n" + body); + + //HTML Body + emailMessage.HtmlPart = new HtmlAttachment("

" + + "
Object-Name: " + LastObjectName + + "
Region: " + LastObjectRegionName + + "
Local-Position: " + LastObjectPosition + "


" + + body + "\r\n

"); + + //Set SMTP SERVER config + SmtpServer smtpServer = new SmtpServer(SMTP_SERVER_HOSTNAME, SMTP_SERVER_PORT); + //Authentication + smtpServer.SmtpAuthToken = new SmtpAuthToken(SMTP_SERVER_LOGIN, SMTP_SERVER_PASSWORD); + //Send Email Message + emailMessage.Send(smtpServer); + //Log + m_log.Info("[EMAIL] EMail sent to: " + address + " from object: " + objectID.ToString()); + } + catch (Exception e) + { + m_log.Error("[EMAIL] DefaultEmailModule Exception: " + e.Message); + return; + } } - catch (Exception e) + else { - m_log.Error("[EMAIL] DefaultEmailModule Exception: "+e.Message); - return; + // inter object email, keep it in the family + Email email = new Email(); + email.time = ((DateTime.UtcNow - new DateTime(1970,1,1,0,0,0)).TotalSeconds).ToString(); + email.subject = subject; + email.sender = objectID.ToString() + "@" + m_InterObjectHostname; + email.message = "Object-Name: " + LastObjectName + + "\nRegion: " + LastObjectRegionName + "\nLocal-Position: " + + LastObjectPosition + "\n\n" + body; + + UUID toID = new UUID(address.Substring(0, address.IndexOf("@"))); + + String unused; + + if (IsLocal(toID)) // TODO FIX check to see if it is local + { + // object in this region + InsertEmail(toID, email); + } + else + { + // object on another region + // TODO FIX + } } } @@ -281,6 +342,33 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules /// public Email GetNextEmail(UUID objectID, string sender, string subject) { + if (m_MailQueues.ContainsKey(objectID)) + { + List queue = m_MailQueues[objectID]; + + if (queue.Count > 0) + { + int i; + + for (i = 0; i < queue.Count; i++) + { + if ((sender == null || sender.Equals("") || sender.Equals(queue[i].sender)) && + (subject == null || subject.Equals("") || subject.Equals(queue[i].subject))) + { + break; + } + } + + if (i != queue.Count) + { + Email ret = queue[i]; + queue.Remove(ret); + ret.numLeft = queue.Count; + return ret; + } + } + } + return null; } } 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 m_host.AddScriptLPS(1); IEmailModule emailModule = m_ScriptEngine.World.RequestModuleInterface(); if (emailModule == null) + { + ShoutError("llEmail: email module not configured"); return; + } emailModule.SendEmail(m_host.UUID, address, subject, message); // ScriptSleep(20000); @@ -2713,7 +2716,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api m_host.AddScriptLPS(1); IEmailModule emailModule = m_ScriptEngine.World.RequestModuleInterface(); if (emailModule == null) + { + ShoutError("llGetNextEmail: email module not configured"); return; + } Email email; email = emailModule.GetNextEmail(m_host.UUID, address, subject); @@ -3668,11 +3674,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api UUID partItemID; foreach (SceneObjectPart part in parts) + { foreach (TaskInventoryItem item in part.TaskInventory.Values) { if (item.Type == ScriptBaseClass.INVENTORY_SCRIPT) { - partItemID = item.ItemID; int linkNumber = m_host.LinkNum; if (m_host.ParentGroup.Children.Count == 1) @@ -3689,6 +3695,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api resobj, new DetectParams[0])); } } + } } public void llPushObject(string target, LSL_Vector impulse, LSL_Vector ang_impulse, int local) -- cgit v1.1