aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorCharles Krinke2008-07-12 17:23:30 +0000
committerCharles Krinke2008-07-12 17:23:30 +0000
commit33971a7ce84da3d2471ad4d8f268a9210f28b1c2 (patch)
tree37d5f5ad1e0fcc6b6ceaf5e4a3dc7b2ae2cf6d5a
parentMantis#1718. Thank you kindly, Mircea for a patch that: (diff)
downloadopensim-SC_OLD-33971a7ce84da3d2471ad4d8f268a9210f28b1c2.zip
opensim-SC_OLD-33971a7ce84da3d2471ad4d8f268a9210f28b1c2.tar.gz
opensim-SC_OLD-33971a7ce84da3d2471ad4d8f268a9210f28b1c2.tar.bz2
opensim-SC_OLD-33971a7ce84da3d2471ad4d8f268a9210f28b1c2.tar.xz
Mantis#1681. Thank you kindly, Vytek for a patch that:
Adds additional support for llEmail().
-rw-r--r--OpenSim/Region/Environment/Modules/Scripting/EMailModules/EmailModule.cs187
-rw-r--r--OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs6
-rw-r--r--prebuild.xml1
3 files changed, 185 insertions, 9 deletions
diff --git a/OpenSim/Region/Environment/Modules/Scripting/EMailModules/EmailModule.cs b/OpenSim/Region/Environment/Modules/Scripting/EMailModules/EmailModule.cs
index 77b2d29..26174e2 100644
--- a/OpenSim/Region/Environment/Modules/Scripting/EMailModules/EmailModule.cs
+++ b/OpenSim/Region/Environment/Modules/Scripting/EMailModules/EmailModule.cs
@@ -28,12 +28,15 @@
28using System; 28using System;
29using System.Reflection; 29using System.Reflection;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text.RegularExpressions;
31using libsecondlife; 32using libsecondlife;
32using OpenSim.Framework; 33using OpenSim.Framework;
33using OpenSim.Region.Environment.Interfaces; 34using OpenSim.Region.Environment.Interfaces;
34using OpenSim.Region.Environment.Scenes; 35using OpenSim.Region.Environment.Scenes;
35using log4net; 36using log4net;
36using Nini.Config; 37using Nini.Config;
38using DotNetOpenMail;
39using DotNetOpenMail.SmtpAuth;
37 40
38namespace OpenSim.Region.Environment.Modules.Scripting.EmailModules 41namespace OpenSim.Region.Environment.Modules.Scripting.EmailModules
39{ 42{
@@ -48,6 +51,12 @@ namespace OpenSim.Region.Environment.Modules.Scripting.EmailModules
48 // Module vars 51 // Module vars
49 // 52 //
50 private IConfigSource m_Config; 53 private IConfigSource m_Config;
54 private string m_HostName = string.Empty;
55 private string m_RegionName = string.Empty;
56 private string SMTP_SERVER_HOSTNAME = string.Empty;
57 private int SMTP_SERVER_PORT = 25;
58 private string SMTP_SERVER_LOGIN = string.Empty;
59 private string SMTP_SERVER_PASSWORD = string.Empty;
51 60
52 // Scenes by Region Handle 61 // Scenes by Region Handle
53 private Dictionary<ulong, Scene> m_Scenes = 62 private Dictionary<ulong, Scene> m_Scenes =
@@ -58,11 +67,44 @@ namespace OpenSim.Region.Environment.Modules.Scripting.EmailModules
58 public void Initialise(Scene scene, IConfigSource config) 67 public void Initialise(Scene scene, IConfigSource config)
59 { 68 {
60 m_Config = config; 69 m_Config = config;
70 IConfig SMTPConfig;
71
72 //FIXME: RegionName is correct??
73 //m_RegionName = scene.RegionInfo.RegionName;
61 74
62 IConfig startupConfig = m_Config.Configs["Startup"]; 75 IConfig startupConfig = m_Config.Configs["Startup"];
63 76
64 m_Enabled = (startupConfig.GetString("emailmodule", 77 m_Enabled = (startupConfig.GetString("emailmodule", "DefaultEmailModule") == "DefaultEmailModule");
65 "DefaultEmailModule") == "DefaultEmailModule"); 78
79 //Load SMTP SERVER config
80 try
81 {
82 if ((SMTPConfig = m_Config.Configs["SMTP"]) == null)
83 {
84 m_log.InfoFormat("[SMTP] SMTP server not configured");
85 m_Enabled = false;
86 return;
87 }
88
89 if (!SMTPConfig.GetBoolean("enabled", false))
90 {
91 m_log.InfoFormat("[SMTP] module disabled in configuration");
92 m_Enabled = false;
93 return;
94 }
95
96 m_HostName = SMTPConfig.GetString("host_domain_header_from", m_HostName);
97 SMTP_SERVER_HOSTNAME = SMTPConfig.GetString("SMTP_SERVER_HOSTNAME",SMTP_SERVER_HOSTNAME);
98 SMTP_SERVER_PORT = SMTPConfig.GetInt("SMTP_SERVER_PORT", SMTP_SERVER_PORT);
99 SMTP_SERVER_LOGIN = SMTPConfig.GetString("SMTP_SERVER_LOGIN", SMTP_SERVER_LOGIN);
100 SMTP_SERVER_PASSWORD = SMTPConfig.GetString("SMTP_SERVER_PASSWORD", SMTP_SERVER_PASSWORD);
101 }
102 catch (Exception e)
103 {
104 m_log.Error("[EMAIL] DefaultEmailModule not configured: "+ e.Message);
105 m_Enabled = false;
106 return;
107 }
66 108
67 // It's a go! 109 // It's a go!
68 if (m_Enabled) 110 if (m_Enabled)
@@ -82,7 +124,7 @@ namespace OpenSim.Region.Environment.Modules.Scripting.EmailModules
82 m_Scenes.Add(scene.RegionInfo.RegionHandle, scene); 124 m_Scenes.Add(scene.RegionInfo.RegionHandle, scene);
83 } 125 }
84 } 126 }
85 127
86 m_log.Info("[EMAIL] Activated DefaultEmailModule"); 128 m_log.Info("[EMAIL] Activated DefaultEmailModule");
87 } 129 }
88 } 130 }
@@ -104,14 +146,143 @@ namespace OpenSim.Region.Environment.Modules.Scripting.EmailModules
104 { 146 {
105 get { return true; } 147 get { return true; }
106 } 148 }
107 149
108 public void SendEmail(LLUUID objectID, string address, string subject, string body) 150 /// <summary>
151 ///
152 /// </summary>
153 /// <param name="seconds"></param>
154 private void DelayInSeconds(int seconds)
155 {
156 TimeSpan DiffDelay = new TimeSpan(0, 0, seconds);
157 DateTime EndDelay = DateTime.Now.Add(DiffDelay);
158 while (DateTime.Now < EndDelay)
159 {
160 ;//Do nothing!!
161 }
162 }
163
164 private SceneObjectPart findPrim(LLUUID objectID, out string ObjectRegionName)
109 { 165 {
166 lock (m_Scenes)
167 {
168 foreach (Scene s in m_Scenes.Values)
169 {
170 SceneObjectPart part = s.GetSceneObjectPart(objectID);
171 if (part != null)
172 {
173 ObjectRegionName = s.RegionInfo.RegionName;
174 return part;
175 }
176 }
177 }
178 ObjectRegionName = string.Empty;
179 return null;
110 } 180 }
111 181
112 public Email GetNextEmail(LLUUID objectID, string sender, string subject) 182 private void resolveNamePositionRegionName(LLUUID objectID, out string ObjectName, out string ObjectAbsolutePosition, out string ObjectRegionName)
113 { 183 {
114 return null; 184 string m_ObjectRegionName;
185 SceneObjectPart part = findPrim(objectID, out m_ObjectRegionName);
186 if (part != null)
187 {
188 ObjectAbsolutePosition = part.AbsolutePosition.ToString();
189 ObjectName = part.Name;
190 ObjectRegionName = m_ObjectRegionName;
191 return;
192 }
193 ObjectAbsolutePosition = part.AbsolutePosition.ToString();
194 ObjectName = part.Name;
195 ObjectRegionName = m_ObjectRegionName;
196 return;
115 } 197 }
116 } 198
199 /// <summary>
200 /// SendMail function utilized by llEMail
201 /// </summary>
202 /// <param name="objectID"></param>
203 /// <param name="address"></param>
204 /// <param name="subject"></param>
205 /// <param name="body"></param>
206 public void SendEmail(LLUUID objectID, string address, string subject, string body)
207 {
208 //Check if address is empty
209 if (address == string.Empty)
210 return;
211
212 //FIXED:Check the email is correct form in REGEX
213 string EMailpatternStrict = @"^(([^<>()[\]\\.,;:\s@\""]+"
214 + @"(\.[^<>()[\]\\.,;:\s@\""]+)*)|(\"".+\""))@"
215 + @"((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
216 + @"\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+"
217 + @"[a-zA-Z]{2,}))$";
218 Regex EMailreStrict = new Regex(EMailpatternStrict);
219 bool isEMailStrictMatch = EMailreStrict.IsMatch(address);
220 if (!isEMailStrictMatch)
221 {
222 m_log.Error("[EMAIL] REGEX Problem in EMail Address: "+address);
223 return;
224 }
225 //FIXME:Check if subject + body = 4096 Byte
226 if ((subject.Length + body.Length) > 1024)
227 {
228 m_log.Error("[EMAIL] subject + body > 1024 Byte");
229 return;
230 }
231
232 try
233 {
234 string LastObjectName = string.Empty;
235 string LastObjectPosition = string.Empty;
236 string LastObjectRegionName = string.Empty;
237 //DONE: Message as Second Life style
238 //20 second delay - AntiSpam System - for now only 10 seconds
239 DelayInSeconds(10);
240 //Creation EmailMessage
241 EmailMessage emailMessage = new EmailMessage();
242 //From
243 emailMessage.FromAddress = new EmailAddress(objectID.UUID.ToString()+"@"+m_HostName);
244 //To - Only One
245 emailMessage.AddToAddress(new EmailAddress(address));
246 //Subject
247 emailMessage.Subject = subject;
248 //TEXT Body
249 resolveNamePositionRegionName(objectID, out LastObjectName, out LastObjectPosition, out LastObjectRegionName);
250 emailMessage.TextPart = new TextAttachment("Object-Name: " + LastObjectName +
251 "\r\nRegion: " + LastObjectRegionName + "\r\nLocal-Position: " +
252 LastObjectPosition+"\r\n\r\n\r\n" + body);
253 //HTML Body
254 emailMessage.HtmlPart = new HtmlAttachment("<html><body><p>" +
255 "<BR>Object-Name: " + LastObjectName +
256 "<BR>Region: " + LastObjectRegionName +
257 "<BR>Local-Position: " + LastObjectPosition + "<BR><BR><BR>"
258 +body+"\r\n</p></body><html>");
259
260 //Set SMTP SERVER config
261 SmtpServer smtpServer=new SmtpServer(SMTP_SERVER_HOSTNAME,SMTP_SERVER_PORT);
262 //Authentication
263 smtpServer.SmtpAuthToken=new SmtpAuthToken(SMTP_SERVER_LOGIN, SMTP_SERVER_PASSWORD);
264 //Send Email Message
265 emailMessage.Send(smtpServer);
266 //Log
267 m_log.Info("[EMAIL] EMail sent to: " + address + " from object: " + objectID.UUID.ToString());
268 }
269 catch (Exception e)
270 {
271 m_log.Error("[EMAIL] DefaultEmailModule Exception: "+e.Message);
272 return;
273 }
274 }
275
276 /// <summary>
277 ///
278 /// </summary>
279 /// <param name="objectID"></param>
280 /// <param name="sender"></param>
281 /// <param name="subject"></param>
282 /// <returns></returns>
283 public Email GetNextEmail(LLUUID objectID, string sender, string subject)
284 {
285 return null;
286 }
287 }
117} 288}
diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs
index 53d1209..4fc4608 100644
--- a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs
+++ b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs
@@ -2222,7 +2222,11 @@ namespace OpenSim.Region.ScriptEngine.Common
2222 public void llEmail(string address, string subject, string message) 2222 public void llEmail(string address, string subject, string message)
2223 { 2223 {
2224 m_host.AddScriptLPS(1); 2224 m_host.AddScriptLPS(1);
2225 NotImplemented("llEmail"); 2225 IEmailModule emailModule = m_ScriptEngine.World.RequestModuleInterface<IEmailModule>();
2226 if (emailModule == null)
2227 return;
2228
2229 emailModule.SendEmail(m_host.UUID, address, subject, message);
2226 } 2230 }
2227 2231
2228 public void llGetNextEmail(string address, string subject) 2232 public void llGetNextEmail(string address, string subject)
diff --git a/prebuild.xml b/prebuild.xml
index 7e5bd5b..e66f470 100644
--- a/prebuild.xml
+++ b/prebuild.xml
@@ -783,6 +783,7 @@
783 <Reference name="OpenSim.Data.Base"/> 783 <Reference name="OpenSim.Data.Base"/>
784 <Reference name="Nini.dll" /> 784 <Reference name="Nini.dll" />
785 <Reference name="log4net.dll"/> 785 <Reference name="log4net.dll"/>
786 <Reference name="DotNetOpenMail.dll"/>
786 787
787 <Files> 788 <Files>
788 <Match pattern="*.cs" recurse="true"/> 789 <Match pattern="*.cs" recurse="true"/>