Example #1
0
        public void DeleteMessage(EmailMessage email)
        {
            using (ImapClient client = new ImapClient(imapHost, 993, username, password, AuthMethod.Login, true))
            {

                try { client.MoveMessage(email.getUID(), "[Gmail]/Trash"); }
                catch (BadServerResponseException e)
                {
                    //be really sad
                }catch(Exception e)
                {
                    ALSMessageBox mb = new ALSMessageBox("Unknown error occurred");
                    mb.Show();
                }

            }
        }
Example #2
0
   //ReadEmail is the handler for email based detectors. It is designed
   //to retrieve email from a configured email service and parse the alerts
   public static void ReadEmail(string sVendor, string sFolderName, string sFolderNameTest, string sDetectorEmail, bool isParamTest)
    {
      switch (sVendor)
      {
        //Outlook based email plugin which requires the Outlook client to be installed.
        case "outlook":
        #region Microsoft Outlook Plugin
          //try
          //{
          //  //Setup connection information to mailstore
          //  //If logon information is null then mailstore must be open already
          //  //var oApp = new Microsoft.Office.Interop.Outlook.Application();
          //  //var sFolder = new Microsoft.Office.Interop.Outlook.Folder(sFolderName);
          //  //var oNameSpace = oApp.GetNamespace("MAPI");
          //  //oNameSpace.Logon(null, null, true, true);
          //  //var oInboxFolder = oNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
          //  //Outlook.Folder oFolder = oInboxFolder.Folder[sFolderName];

          //  //logging
          //  //Logging_Fido.Main.RunLogging("Running FIDO on file " + sFolderName);

          //  ////attach to folder and for each item in the folder then loop. During loop assign subject, body and detect malware type
          //  //foreach (var item in sFolder.Items)
          //  //{
          //  //  var oMailItem = item as Microsoft.Office.Interop.Outlook._MailItem;
          //  //  if (oMailItem != null)
          //  //  {
          //  //    var sMessageBody = oMailItem.Body;
          //  //  }
          //  //  if (oMailItem != null)
          //  //  {
          //  //    var sSubject = oMailItem.Subject;
          //  //  }
          //    //List<string> sERet = scan_email(sSubject, sMessageBody, sFolderName);
          //  //  if (sERet.First() == "Test Email")
          //  //  {
          //  //    oMailItem.Delete();
          //  //  }
          //  //  else
          //  //  {
          //  //    fido.Form1.Run_FIDO(sMessageBody, sERet, "fubar", false, false, true, sVendor);//MalwareType
          //  //    oMailItem.Delete();
          //  //  }
          //  }
            #endregion

          //}
          //catch (Exception e)
          //{
          //  Fido_Modules.Fido.Fido_EventHandler.SendEmail("Fido Error", "Fido Failed: {0} Exception caught in Outlook emailreceive area:" + e);
          //}
          break;

        case "exchange":
        #region Microsoft Exchange Plugin
          //still need to build out direct Exchange access
          #endregion
          break;
        
        //IMAP based email plugin which has been verified to work with Gmail
        case "imap":
        #region IMAP Plugin
          try
          {
            //get encrypted password and decrypt
            //then login
            var sfidoemail = Object_Fido_Configs.GetAsString("fido.email.fidoemail", null);
            var sfidopwd = Object_Fido_Configs.GetAsString("fido.email.fidopwd", null);
            var sfidoacek = Object_Fido_Configs.GetAsString("fido.email.fidoacek", null);
            var sImapServer = Object_Fido_Configs.GetAsString("fido.email.imapserver", null);
            var iImapPort = Object_Fido_Configs.GetAsInt("fido.email.imapport", 0);
            sfidoacek = Aes_Crypto.DecryptStringAES(sfidoacek, "1");
            sfidopwd = Aes_Crypto.DecryptStringAES(sfidopwd, sfidoacek);
            IImapClient gLogin = new ImapClient(sImapServer, iImapPort, sfidoemail, sfidopwd, AuthMethod.Login, true);

            var sSeperator = new[] { "," };
            gLogin.DefaultMailbox = isParamTest ? sFolderNameTest : sFolderName;
            var listUids = new List<uint>();

            //seperate out list of email addresses handed to emailreceive
            //then run query based on each email from the specified folder
            //and finally convert to array
            string[] aryInboxSearch = sDetectorEmail.Split(sSeperator, StringSplitOptions.RemoveEmptyEntries);
            foreach (var search in aryInboxSearch)
            {
              listUids.AddRange(gLogin.Search(SearchCondition.From(search)).ToList());
            }
            var uids = listUids.ToArray();
            uids = uids.Take(50).ToArray();
            var msg = gLogin.GetMessages(uids);
            var mailMessages = msg as MailMessage[] ?? msg.ToArray();
            for (var i = 0; i < mailMessages.Count(); i++)
            {
              var sMessageBody = mailMessages[i].Body;
              var sSubject = mailMessages[i].Subject;
              var sERet = ScanEmail(sSubject, sMessageBody, sFolderName, isParamTest);
              if (sERet == "Test Email")
              {
                Console.WriteLine(@"Test email found, putting in processed folder.");
                gLogin.MoveMessage(uids[i], "Processed");
              }
              else
              {
                Console.WriteLine(@"Finished processing email alert, puttig in processed folder.");
                gLogin.MoveMessage(uids[i], "Processed");
              }
            }
            #endregion
          }
          catch (Exception e)
          {
            Fido_EventHandler.SendEmail("Fido Error", "Fido Failed: {0} Exception caught in IMAP emailreceive area:" + e);
          }
          Console.WriteLine(@"Finished processing email alerts.");
          break;
      }
    }