add some debug

master
Christopher 2020-06-30 17:11:03 +02:00
parent fa4f21b587
commit be11b1e01c
1 changed files with 39 additions and 11 deletions

View File

@ -1,4 +1,5 @@
using MailKit;
using log4net;
using MailKit;
using MailKit.Net.Imap;
using MailKit.Net.Smtp;
using MailKit.Security;
@ -11,6 +12,7 @@ using OpenSim.Region.Framework.Scenes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
@ -22,6 +24,8 @@ namespace OpenSim.Modules.EMail
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "MailKitMailModule")]
class MailKitMailModule : INonSharedRegionModule, IEmailModule
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private IConfigSource m_config = null;
private bool m_enabled = false;
@ -125,30 +129,39 @@ namespace OpenSim.Modules.EMail
private void checkForMails(object sender, ElapsedEventArgs e)
{
m_log.Info("[" + Name + "] checkForMails");
using (var client = new ImapClient())
{
client.CheckCertificateRevocation = false;
if (IMAP_SERVER_SSL == true)
{
m_log.Info("[" + Name + "] Connect SSL");
client.Connect(IMAP_SERVER_HOSTNAME, IMAP_SERVER_PORT, SecureSocketOptions.Auto);
}
else if (IMAP_SERVER_SSL == true)
{
m_log.Info("[" + Name + "] Connect TLS");
client.Connect(IMAP_SERVER_HOSTNAME, IMAP_SERVER_PORT, SecureSocketOptions.StartTlsWhenAvailable);
}
else
{
client.Connect(IMAP_SERVER_HOSTNAME, IMAP_SERVER_PORT, SecureSocketOptions.None);
}
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);
@ -161,6 +174,7 @@ namespace OpenSim.Modules.EMail
{
m_messages.Add(message);
IMAPInbox.SetFlags(i, MessageFlags.Deleted, true);
m_log.Info("[" + Name + "] Get Message for objekt " + sceneObject.Name + " (" + sceneObject.UUID + ")");
}
}
}
@ -212,26 +226,40 @@ namespace OpenSim.Modules.EMail
public Email GetNextEmail(UUID objectID, string sender, string subject)
{
SceneObjectPart sceneObject = m_scene.GetSceneObjectPart(objectID);
m_log.Info("[" + Name + "] GetNextEmail: " + sceneObject.Name + " (" + sceneObject.UUID + ")");
List<MimeMessage> messages = m_messages.FindAll(X => X.Subject.Contains(subject) && X.Sender.GetAddress(true).Contains(sender));
MimeMessage lastMessage = null;
Email lslMessage = null;
foreach (MimeMessage message in messages)
{
if (lslMessage != null)
continue;
lastMessage = message;
foreach (MailboxAddress adress in message.To.Mailboxes)
{
Email lslMessage = new Email();
lslMessage.time = messages[0].Date.ToUnixTimeSeconds().ToString();
lslMessage.message = messages[0].Body.ToString();
lslMessage.sender = messages[0].Sender.GetAddress(true);
lslMessage.subject = messages[0].Subject;
m_messages.Remove(messages[0]);
if (lslMessage != null)
continue;
lslMessage = new Email();
lslMessage.time = lastMessage.Date.ToUnixTimeSeconds().ToString();
lslMessage.message = lastMessage.Body.ToString();
lslMessage.sender = lastMessage.Sender.GetAddress(true);
lslMessage.subject = lastMessage.Subject;
lslMessage.numLeft = messages.Count - 1;
return lslMessage;
}
}
return null;
if(lastMessage != null)
m_messages.Remove(lastMessage);
return lslMessage;
}
}
}