29 using System.Collections.Generic;
30 using System.Reflection;
31 using System.Text.RegularExpressions;
33 using DotNetOpenMail.SmtpAuth;
37 using OpenSim.Framework;
38 using OpenSim.Region.Framework.Interfaces;
39 using OpenSim.Region.Framework.Scenes;
44 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"EmailModule")]
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
55 private IConfigSource m_Config;
56 private string m_HostName = string.Empty;
58 private string SMTP_SERVER_HOSTNAME = string.Empty;
59 private int SMTP_SERVER_PORT = 25;
60 private string SMTP_SERVER_LOGIN = string.Empty;
61 private string SMTP_SERVER_PASSWORD = string.Empty;
63 private int m_MaxQueueSize = 50;
64 private Dictionary<UUID, List<Email>> m_MailQueues =
new Dictionary<UUID, List<Email>>();
65 private Dictionary<UUID, DateTime> m_LastGetEmailCall =
new Dictionary<UUID, DateTime>();
66 private TimeSpan m_QueueTimeout =
new TimeSpan(2, 0, 0);
67 private string m_InterObjectHostname =
"lsl.opensim.local";
69 private int m_MaxEmailSize = 4096;
72 private Dictionary<ulong, Scene> m_Scenes =
73 new Dictionary<ulong, Scene>();
75 private bool m_Enabled =
false;
77 #region ISharedRegionModule
87 IConfig startupConfig = m_Config.Configs[
"Startup"];
89 m_Enabled = (startupConfig.GetString(
"emailmodule",
"DefaultEmailModule") ==
"DefaultEmailModule");
94 if ((SMTPConfig = m_Config.Configs[
"SMTP"]) == null)
100 if (!SMTPConfig.GetBoolean(
"enabled",
false))
106 m_HostName = SMTPConfig.GetString(
"host_domain_header_from", m_HostName);
107 m_InterObjectHostname = SMTPConfig.GetString(
"internal_object_host", m_InterObjectHostname);
108 SMTP_SERVER_HOSTNAME = SMTPConfig.GetString(
"SMTP_SERVER_HOSTNAME", SMTP_SERVER_HOSTNAME);
109 SMTP_SERVER_PORT = SMTPConfig.GetInt(
"SMTP_SERVER_PORT", SMTP_SERVER_PORT);
110 SMTP_SERVER_LOGIN = SMTPConfig.GetString(
"SMTP_SERVER_LOGIN", SMTP_SERVER_LOGIN);
111 SMTP_SERVER_PASSWORD = SMTPConfig.GetString(
"SMTP_SERVER_PASSWORD", SMTP_SERVER_PASSWORD);
112 m_MaxEmailSize = SMTPConfig.GetInt(
"email_max_size", m_MaxEmailSize);
116 m_log.Error(
"[EMAIL] DefaultEmailModule not configured: " + e.Message);
137 m_Scenes[scene.RegionInfo.RegionHandle] = scene;
141 m_Scenes.Add(scene.RegionInfo.RegionHandle, scene);
145 m_log.Info(
"[EMAIL] Activated DefaultEmailModule");
162 get {
return "DefaultEmailModule"; }
165 public Type ReplaceableInterface
184 if (m_MailQueues.ContainsKey(to))
186 if (m_MailQueues[to].Count >= m_MaxQueueSize)
192 lock (m_MailQueues[to])
194 m_MailQueues[to].Add(email);
200 private bool IsLocal(UUID objectID)
203 return (null != findPrim(objectID, out unused));
206 private SceneObjectPart findPrim(UUID objectID, out
string ObjectRegionName)
210 foreach (
Scene s
in m_Scenes.Values)
215 ObjectRegionName = s.RegionInfo.RegionName;
216 uint localX = s.RegionInfo.WorldLocX;
217 uint localY = s.RegionInfo.WorldLocY;
218 ObjectRegionName = ObjectRegionName +
" (" + localX +
", " + localY +
")";
223 ObjectRegionName = string.Empty;
227 private bool resolveNamePositionRegionName(UUID objectID, out
string ObjectName, out
string ObjectAbsolutePosition, out
string ObjectRegionName)
229 ObjectName = ObjectAbsolutePosition = ObjectRegionName = String.Empty;
230 string m_ObjectRegionName;
238 objectLocY = (
int)part.AbsolutePosition.Y;
240 ObjectAbsolutePosition =
"(" + objectLocX +
", " + objectLocY +
", " + objectLocZ +
")";
241 ObjectName = part.
Name;
242 ObjectRegionName = m_ObjectRegionName;
255 public void SendEmail(UUID objectID,
string address,
string subject,
string body)
258 if (address ==
string.Empty)
262 string EMailpatternStrict =
@"^(([^<>()[\]\\.,;:\s@\""]+"
263 +
@"(\.[^<>()[\]\\.,;:\s@\""]+)*)|(\"".+\""))@"
264 +
@"((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
265 +
@"\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+"
266 +
@"[a-zA-Z]{2,}))$";
267 Regex EMailreStrict =
new Regex(EMailpatternStrict);
268 bool isEMailStrictMatch = EMailreStrict.IsMatch(address);
269 if (!isEMailStrictMatch)
271 m_log.Error(
"[EMAIL] REGEX Problem in EMail Address: "+address);
274 if ((subject.Length + body.Length) > m_MaxEmailSize)
276 m_log.Error(
"[EMAIL] subject + body larger than limit of " + m_MaxEmailSize +
" bytes");
280 string LastObjectName = string.Empty;
281 string LastObjectPosition = string.Empty;
282 string LastObjectRegionName = string.Empty;
284 if (!resolveNamePositionRegionName(objectID, out LastObjectName, out LastObjectPosition, out LastObjectRegionName))
287 if (!address.EndsWith(m_InterObjectHostname))
293 EmailMessage emailMessage =
new EmailMessage();
295 emailMessage.FromAddress =
new EmailAddress(objectID.ToString() +
"@" + m_HostName);
297 emailMessage.AddToAddress(
new EmailAddress(address));
299 emailMessage.Subject = subject;
301 if (!resolveNamePositionRegionName(objectID, out LastObjectName, out LastObjectPosition, out LastObjectRegionName))
303 emailMessage.BodyText =
"Object-Name: " + LastObjectName +
304 "\nRegion: " + LastObjectRegionName +
"\nLocal-Position: " +
305 LastObjectPosition +
"\n\n" + body;
309 SmtpServer smtpServer=
new SmtpServer(SMTP_SERVER_HOSTNAME,SMTP_SERVER_PORT);
312 if (SMTP_SERVER_LOGIN !=
String.Empty && SMTP_SERVER_PASSWORD !=
String.Empty)
315 smtpServer.SmtpAuthToken=
new SmtpAuthToken(SMTP_SERVER_LOGIN, SMTP_SERVER_PASSWORD);
318 emailMessage.Send(smtpServer);
321 m_log.Info(
"[EMAIL] EMail sent to: " + address +
" from object: " + objectID.ToString() +
"@" + m_HostName);
325 m_log.Error(
"[EMAIL] DefaultEmailModule Exception: " + e.Message);
332 email.time = ((int)((DateTime.UtcNow -
new DateTime(1970,1,1,0,0,0)).TotalSeconds)).ToString();
333 email.subject = subject;
334 email.sender = objectID.ToString() +
"@" + m_InterObjectHostname;
335 email.message =
"Object-Name: " + LastObjectName +
336 "\nRegion: " + LastObjectRegionName +
"\nLocal-Position: " +
337 LastObjectPosition +
"\n\n" + body;
339 string guid = address.Substring(0, address.IndexOf(
"@"));
345 InsertEmail(toID, email);
364 List<Email> queue = null;
366 lock (m_LastGetEmailCall)
368 if (m_LastGetEmailCall.ContainsKey(objectID))
370 m_LastGetEmailCall.Remove(objectID);
373 m_LastGetEmailCall.Add(objectID, DateTime.Now);
376 DateTime now = DateTime.Now;
377 List<UUID> removal =
new List<UUID>();
378 foreach (
UUID uuid
in m_LastGetEmailCall.Keys)
380 if ((now - m_LastGetEmailCall[uuid]) > m_QueueTimeout)
386 foreach (
UUID remove in removal)
388 m_LastGetEmailCall.Remove(
remove);
391 m_MailQueues.Remove(
remove);
398 if (m_MailQueues.ContainsKey(objectID))
400 queue = m_MailQueues[objectID];
412 for (i = 0; i < queue.Count; i++)
414 if ((sender == null || sender.Equals(
"") || sender.Equals(queue[i].sender)) &&
415 (subject == null || subject.Equals(
"") || subject.Equals(queue[i].subject)))
421 if (i != queue.Count)
423 Email ret = queue[i];
425 ret.numLeft = queue.Count;
435 m_MailQueues.Add(objectID,
new List<Email>());
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
void Initialise(IConfigSource config)
This is called to initialize the region module. For shared modules, this is called exactly once...
void PostInitialise()
This is called exactly once after all the shared region-modules have been instanciated and IRegionMod...
Email GetNextEmail(UUID objectID, string sender, string subject)
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
void SendEmail(UUID objectID, string address, string subject, string body)
SendMail function utilized by llEMail
Interactive OpenSim region server
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
virtual RegionInfo RegionInfo
void InsertEmail(UUID to, Email email)