Thank you, DoranZemlja, for a patch that implements local inter-object email

delivery.
Leaving Mantis #3145 open so that more code can be added.
0.6.3-post-fixes
Melanie Thielker 2009-02-14 21:25:22 +00:00
parent 3542630478
commit 4bc52888be
2 changed files with 136 additions and 41 deletions

View File

@ -57,12 +57,32 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules
private string SMTP_SERVER_LOGIN = string.Empty; private string SMTP_SERVER_LOGIN = string.Empty;
private string SMTP_SERVER_PASSWORD = string.Empty; private string SMTP_SERVER_PASSWORD = string.Empty;
private int m_MaxQueueSize = 50; // maximum size of an object mail queue
private Dictionary<UUID, List<Email>> m_MailQueues = new Dictionary<UUID, List<Email>>();
private string m_InterObjectHostname;
// Scenes by Region Handle // Scenes by Region Handle
private Dictionary<ulong, Scene> m_Scenes = private Dictionary<ulong, Scene> m_Scenes =
new Dictionary<ulong, Scene>(); new Dictionary<ulong, Scene>();
private bool m_Enabled = false; private bool m_Enabled = false;
public void InsertEmail(UUID to, Email email)
{
if (!m_MailQueues.ContainsKey(to))
{
m_MailQueues.Add(to, new List<Email>());
}
if (m_MailQueues[to].Count >= m_MaxQueueSize)
{
// fail silently
return;
}
m_MailQueues[to].Add(email);
}
public void Initialise(Scene scene, IConfigSource config) public void Initialise(Scene scene, IConfigSource config)
{ {
m_Config = config; m_Config = config;
@ -93,7 +113,8 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules
} }
m_HostName = SMTPConfig.GetString("host_domain_header_from", m_HostName); 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_PORT = SMTPConfig.GetInt("SMTP_SERVER_PORT", SMTP_SERVER_PORT);
SMTP_SERVER_LOGIN = SMTPConfig.GetString("SMTP_SERVER_LOGIN", SMTP_SERVER_LOGIN); SMTP_SERVER_LOGIN = SMTPConfig.GetString("SMTP_SERVER_LOGIN", SMTP_SERVER_LOGIN);
SMTP_SERVER_PASSWORD = SMTPConfig.GetString("SMTP_SERVER_PASSWORD", SMTP_SERVER_PASSWORD); 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) private SceneObjectPart findPrim(UUID objectID, out string ObjectRegionName)
{ {
lock (m_Scenes) lock (m_Scenes)
@ -228,18 +255,24 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules
return; return;
} }
try
{
string LastObjectName = string.Empty; string LastObjectName = string.Empty;
string LastObjectPosition = string.Empty; string LastObjectPosition = string.Empty;
string LastObjectRegionName = string.Empty; string LastObjectRegionName = string.Empty;
//DONE: Message as Second Life style //DONE: Message as Second Life style
//20 second delay - AntiSpam System - for now only 10 seconds //20 second delay - AntiSpam System - for now only 10 seconds
DelayInSeconds(10); DelayInSeconds(10);
resolveNamePositionRegionName(objectID, out LastObjectName, out LastObjectPosition, out LastObjectRegionName);
if (!address.EndsWith(m_InterObjectHostname))
{
// regular email, send it out
try
{
//Creation EmailMessage //Creation EmailMessage
EmailMessage emailMessage = new EmailMessage(); EmailMessage emailMessage = new EmailMessage();
//From //From
emailMessage.FromAddress = new EmailAddress(objectID.ToString()+"@"+m_HostName); emailMessage.FromAddress = new EmailAddress(objectID.ToString() + "@" + m_HostName);
//To - Only One //To - Only One
emailMessage.AddToAddress(new EmailAddress(address)); emailMessage.AddToAddress(new EmailAddress(address));
//Subject //Subject
@ -248,18 +281,19 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules
resolveNamePositionRegionName(objectID, out LastObjectName, out LastObjectPosition, out LastObjectRegionName); resolveNamePositionRegionName(objectID, out LastObjectName, out LastObjectPosition, out LastObjectRegionName);
emailMessage.TextPart = new TextAttachment("Object-Name: " + LastObjectName + emailMessage.TextPart = new TextAttachment("Object-Name: " + LastObjectName +
"\r\nRegion: " + LastObjectRegionName + "\r\nLocal-Position: " + "\r\nRegion: " + LastObjectRegionName + "\r\nLocal-Position: " +
LastObjectPosition+"\r\n\r\n\r\n" + body); LastObjectPosition + "\r\n\r\n" + body);
//HTML Body //HTML Body
emailMessage.HtmlPart = new HtmlAttachment("<html><body><p>" + emailMessage.HtmlPart = new HtmlAttachment("<html><body><p>" +
"<BR>Object-Name: " + LastObjectName + "<BR>Object-Name: " + LastObjectName +
"<BR>Region: " + LastObjectRegionName + "<BR>Region: " + LastObjectRegionName +
"<BR>Local-Position: " + LastObjectPosition + "<BR><BR><BR>" "<BR>Local-Position: " + LastObjectPosition + "<BR><BR><BR>"
+body+"\r\n</p></body><html>"); + body + "\r\n</p></body><html>");
//Set SMTP SERVER config //Set SMTP SERVER config
SmtpServer smtpServer=new SmtpServer(SMTP_SERVER_HOSTNAME,SMTP_SERVER_PORT); SmtpServer smtpServer = new SmtpServer(SMTP_SERVER_HOSTNAME, SMTP_SERVER_PORT);
//Authentication //Authentication
smtpServer.SmtpAuthToken=new SmtpAuthToken(SMTP_SERVER_LOGIN, SMTP_SERVER_PASSWORD); smtpServer.SmtpAuthToken = new SmtpAuthToken(SMTP_SERVER_LOGIN, SMTP_SERVER_PASSWORD);
//Send Email Message //Send Email Message
emailMessage.Send(smtpServer); emailMessage.Send(smtpServer);
//Log //Log
@ -267,10 +301,37 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules
} }
catch (Exception e) catch (Exception e)
{ {
m_log.Error("[EMAIL] DefaultEmailModule Exception: "+e.Message); m_log.Error("[EMAIL] DefaultEmailModule Exception: " + e.Message);
return; return;
} }
} }
else
{
// 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
}
}
}
/// <summary> /// <summary>
/// ///
@ -281,6 +342,33 @@ namespace OpenSim.Region.CoreModules.Scripting.EmailModules
/// <returns></returns> /// <returns></returns>
public Email GetNextEmail(UUID objectID, string sender, string subject) public Email GetNextEmail(UUID objectID, string sender, string subject)
{ {
if (m_MailQueues.ContainsKey(objectID))
{
List<Email> 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; return null;
} }
} }

View File

@ -2702,7 +2702,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
m_host.AddScriptLPS(1); m_host.AddScriptLPS(1);
IEmailModule emailModule = m_ScriptEngine.World.RequestModuleInterface<IEmailModule>(); IEmailModule emailModule = m_ScriptEngine.World.RequestModuleInterface<IEmailModule>();
if (emailModule == null) if (emailModule == null)
{
ShoutError("llEmail: email module not configured");
return; return;
}
emailModule.SendEmail(m_host.UUID, address, subject, message); emailModule.SendEmail(m_host.UUID, address, subject, message);
// ScriptSleep(20000); // ScriptSleep(20000);
@ -2713,7 +2716,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
m_host.AddScriptLPS(1); m_host.AddScriptLPS(1);
IEmailModule emailModule = m_ScriptEngine.World.RequestModuleInterface<IEmailModule>(); IEmailModule emailModule = m_ScriptEngine.World.RequestModuleInterface<IEmailModule>();
if (emailModule == null) if (emailModule == null)
{
ShoutError("llGetNextEmail: email module not configured");
return; return;
}
Email email; Email email;
email = emailModule.GetNextEmail(m_host.UUID, address, subject); email = emailModule.GetNextEmail(m_host.UUID, address, subject);
@ -3668,11 +3674,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
UUID partItemID; UUID partItemID;
foreach (SceneObjectPart part in parts) foreach (SceneObjectPart part in parts)
{
foreach (TaskInventoryItem item in part.TaskInventory.Values) foreach (TaskInventoryItem item in part.TaskInventory.Values)
{ {
if (item.Type == ScriptBaseClass.INVENTORY_SCRIPT) if (item.Type == ScriptBaseClass.INVENTORY_SCRIPT)
{ {
partItemID = item.ItemID; partItemID = item.ItemID;
int linkNumber = m_host.LinkNum; int linkNumber = m_host.LinkNum;
if (m_host.ParentGroup.Children.Count == 1) if (m_host.ParentGroup.Children.Count == 1)
@ -3690,6 +3696,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
} }
} }
} }
}
public void llPushObject(string target, LSL_Vector impulse, LSL_Vector ang_impulse, int local) public void llPushObject(string target, LSL_Vector impulse, LSL_Vector ang_impulse, int local)
{ {