add error handling
parent
5a6179ed6e
commit
649829f307
|
@ -70,12 +70,15 @@ namespace OpenSim.Modules.EMail
|
||||||
scene.RegisterModuleInterface<IEmailModule>(this);
|
scene.RegisterModuleInterface<IEmailModule>(this);
|
||||||
m_scene = scene;
|
m_scene = scene;
|
||||||
|
|
||||||
m_timer = new Timer();
|
if(IMAP_SERVER_HOSTNAME != String.Empty)
|
||||||
|
{
|
||||||
|
m_timer = new Timer();
|
||||||
|
|
||||||
m_timer.Interval = 1000 * 60;
|
m_timer.Interval = 1000 * 60;
|
||||||
m_timer.Elapsed += checkForMails;
|
m_timer.Elapsed += checkForMails;
|
||||||
m_timer.Enabled = true;
|
m_timer.Enabled = true;
|
||||||
m_timer.Start();
|
m_timer.Start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Close()
|
public void Close()
|
||||||
|
@ -129,58 +132,64 @@ namespace OpenSim.Modules.EMail
|
||||||
|
|
||||||
private void checkForMails(object sender, ElapsedEventArgs e)
|
private void checkForMails(object sender, ElapsedEventArgs e)
|
||||||
{
|
{
|
||||||
m_log.Info("[" + Name + "] checkForMails");
|
try
|
||||||
|
|
||||||
using (var client = new ImapClient())
|
|
||||||
{
|
{
|
||||||
client.CheckCertificateRevocation = false;
|
m_log.Info("[" + Name + "] checkForMails");
|
||||||
|
|
||||||
if (IMAP_SERVER_SSL == true)
|
using (var client = new ImapClient())
|
||||||
{
|
{
|
||||||
m_log.Info("[" + Name + "] Connect SSL");
|
client.CheckCertificateRevocation = false;
|
||||||
client.Connect(IMAP_SERVER_HOSTNAME, IMAP_SERVER_PORT, SecureSocketOptions.Auto);
|
|
||||||
}
|
|
||||||
else if (IMAP_SERVER_TLS == true)
|
|
||||||
{
|
|
||||||
m_log.Info("[" + Name + "] Connect TLS");
|
|
||||||
client.Connect(IMAP_SERVER_HOSTNAME, IMAP_SERVER_PORT, SecureSocketOptions.StartTlsWhenAvailable);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_log.Info("[" + Name + "] Connect None");
|
|
||||||
client.Connect(IMAP_SERVER_HOSTNAME, IMAP_SERVER_PORT, SecureSocketOptions.None);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (IMAP_SERVER_LOGIN != String.Empty && IMAP_SERVER_PASSWORD != String.Empty)
|
if (IMAP_SERVER_SSL == true)
|
||||||
{
|
|
||||||
m_log.Info("[" + Name + "] Login with " + IMAP_SERVER_LOGIN + ";" + IMAP_SERVER_PASSWORD);
|
|
||||||
client.Authenticate(IMAP_SERVER_LOGIN, IMAP_SERVER_PASSWORD);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
IMailFolder IMAPInbox = client.Inbox;
|
|
||||||
IMAPInbox.Open(FolderAccess.ReadWrite);
|
|
||||||
|
|
||||||
m_log.Info("[" + Name + "] Found "+ IMAPInbox.Count + " messages.");
|
|
||||||
for (int i = 0; i < IMAPInbox.Count; i++)
|
|
||||||
{
|
|
||||||
MimeMessage message = IMAPInbox.GetMessage(i);
|
|
||||||
|
|
||||||
foreach(MailboxAddress adress in message.To.Mailboxes)
|
|
||||||
{
|
{
|
||||||
SceneObjectPart sceneObject = m_scene.GetSceneObjectPart(adress.Address.Split('@')[0]);
|
m_log.Info("[" + Name + "] Connect SSL");
|
||||||
|
client.Connect(IMAP_SERVER_HOSTNAME, IMAP_SERVER_PORT, SecureSocketOptions.Auto);
|
||||||
|
}
|
||||||
|
else if (IMAP_SERVER_TLS == true)
|
||||||
|
{
|
||||||
|
m_log.Info("[" + Name + "] Connect TLS");
|
||||||
|
client.Connect(IMAP_SERVER_HOSTNAME, IMAP_SERVER_PORT, SecureSocketOptions.StartTlsWhenAvailable);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_log.Info("[" + Name + "] Connect None");
|
||||||
|
client.Connect(IMAP_SERVER_HOSTNAME, IMAP_SERVER_PORT, SecureSocketOptions.None);
|
||||||
|
}
|
||||||
|
|
||||||
if(sceneObject != null)
|
if (IMAP_SERVER_LOGIN != String.Empty && IMAP_SERVER_PASSWORD != String.Empty)
|
||||||
|
{
|
||||||
|
m_log.Info("[" + Name + "] Login with " + IMAP_SERVER_LOGIN + ";" + IMAP_SERVER_PASSWORD);
|
||||||
|
client.Authenticate(IMAP_SERVER_LOGIN, IMAP_SERVER_PASSWORD);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
IMailFolder IMAPInbox = client.Inbox;
|
||||||
|
IMAPInbox.Open(FolderAccess.ReadWrite);
|
||||||
|
|
||||||
|
m_log.Info("[" + Name + "] Found " + IMAPInbox.Count + " messages.");
|
||||||
|
for (int i = 0; i < IMAPInbox.Count; i++)
|
||||||
|
{
|
||||||
|
MimeMessage message = IMAPInbox.GetMessage(i);
|
||||||
|
|
||||||
|
foreach (MailboxAddress adress in message.To.Mailboxes)
|
||||||
{
|
{
|
||||||
m_messages.Add(message);
|
SceneObjectPart sceneObject = m_scene.GetSceneObjectPart(adress.Address.Split('@')[0]);
|
||||||
IMAPInbox.SetFlags(i, MessageFlags.Deleted, true);
|
|
||||||
m_log.Info("[" + Name + "] Get Message for objekt " + sceneObject.Name + " (" + sceneObject.UUID + ")");
|
if (sceneObject != null)
|
||||||
|
{
|
||||||
|
m_messages.Add(message);
|
||||||
|
IMAPInbox.SetFlags(i, MessageFlags.Deleted, true);
|
||||||
|
m_log.Info("[" + Name + "] Get Message for objekt " + sceneObject.Name + " (" + sceneObject.UUID + ")");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
IMAPInbox.Expunge();
|
IMAPInbox.Expunge();
|
||||||
client.Disconnect(true);
|
client.Disconnect(true);
|
||||||
|
}
|
||||||
|
}catch(Exception _error)
|
||||||
|
{
|
||||||
|
m_log.Error("[" + Name + "] " + _error.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue