-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from checkymander/Dev
Dev
- Loading branch information
Showing
9 changed files
with
949 additions
and
369 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
using Carbuncle.Helpers; | ||
using Microsoft.Office.Interop.Outlook; | ||
using System; | ||
using System.IO; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace Carbuncle.Commands | ||
{ | ||
public class AttachmentSearcher | ||
{ | ||
bool download { get; set; } | ||
string downloadFolder { get; set; } | ||
public AttachmentSearcher(bool download = false, string downloadFolder = "") | ||
{ | ||
this.download = download; | ||
this.downloadFolder = downloadFolder; | ||
} | ||
public void GetAttachmentsByID(string ID, OlDefaultFolders folder) | ||
{ | ||
try | ||
{ | ||
Application outlookApplication = new Application(); | ||
NameSpace outlookNamespace = outlookApplication.GetNamespace("MAPI"); | ||
MAPIFolder inboxFolder = outlookNamespace.GetDefaultFolder(folder); | ||
var item = outlookNamespace.GetItemFromID(ID); | ||
if (item is MailItem mailItem) | ||
{ | ||
if (mailItem.Attachments.Count > 0) | ||
{ | ||
if (download) | ||
{ | ||
foreach (Attachment attachment in mailItem.Attachments) | ||
{ | ||
attachment.SaveAsFile(downloadFolder.TrimEnd('\\') + "\\" + attachment.FileName); | ||
} | ||
} | ||
else | ||
{ | ||
Common.DisplayMailItem(mailItem); | ||
} | ||
} | ||
} | ||
else if (item is MeetingItem meetingItem) | ||
{ | ||
if (meetingItem.Attachments.Count > 0) | ||
{ | ||
if (download) | ||
{ | ||
foreach (Attachment attachment in meetingItem.Attachments) | ||
{ | ||
attachment.SaveAsFile(downloadFolder.TrimEnd('\\') + "\\" + attachment.FileName); | ||
} | ||
} | ||
else | ||
{ | ||
Common.DisplayMeetingItem(meetingItem); | ||
} | ||
} | ||
} | ||
} | ||
catch (System.Exception e) | ||
{ | ||
Console.WriteLine(e.Message); | ||
} | ||
} | ||
public void GetAttachmentsByKeyword(string keyword) | ||
{ | ||
GetAttachmentsByRegex($"({keyword})"); | ||
} | ||
public void GetAttachmentsByRegex(string regex) | ||
{ | ||
MailSearcher ms = new MailSearcher(); | ||
Items mailItems = ms.GetInboxItems(OlDefaultFolders.olFolderInbox); | ||
foreach (var item in ms.GetInboxItems(OlDefaultFolders.olFolderInbox)) | ||
{ | ||
try | ||
{ | ||
if (item is MailItem mailItem) | ||
{ | ||
if (mailItem.Attachments.Count > 0) | ||
{ | ||
foreach (Attachment attachment in mailItem.Attachments) | ||
{ | ||
if (Regex.Match(attachment.FileName, regex).Success) | ||
{ | ||
if (download) | ||
{ | ||
attachment.SaveAsFile(downloadFolder.TrimEnd('\\') + "\\" + attachment.FileName); | ||
} | ||
else | ||
{ | ||
Common.DisplayMailItem(mailItem); | ||
} | ||
} | ||
|
||
} | ||
} | ||
} | ||
else if (item is MeetingItem meetingItem) | ||
{ | ||
if (meetingItem.Attachments.Count > 0) | ||
{ | ||
foreach (Attachment attachment in meetingItem.Attachments) | ||
{ | ||
if(Regex.Match(attachment.FileName, regex).Success) | ||
{ | ||
if (download) | ||
{ | ||
attachment.SaveAsFile(downloadFolder.TrimEnd('\\') + "\\" + attachment.FileName); | ||
} | ||
else | ||
{ | ||
Common.DisplayMeetingItem(meetingItem); | ||
} | ||
} | ||
|
||
} | ||
} | ||
} | ||
} | ||
catch (System.Exception e) | ||
{ | ||
Console.WriteLine(e.Message); | ||
} | ||
} | ||
} | ||
public void GetAllAttachments() | ||
{ | ||
Console.WriteLine("Getting All Attachments\r\nDownload = " + download); | ||
Console.WriteLine(downloadFolder); | ||
MailSearcher ms = new MailSearcher(); | ||
//Items mailItems = ms.GetInboxItems(OlDefaultFolders.olFolderInbox); | ||
|
||
foreach (var item in ms.GetInboxItems(OlDefaultFolders.olFolderInbox)) | ||
{ | ||
try | ||
{ | ||
if (item is MailItem mailItem) | ||
{ | ||
if (mailItem.Attachments.Count > 0) | ||
{ | ||
if (download) | ||
{ | ||
foreach (Attachment attachment in mailItem.Attachments) | ||
{ | ||
attachment.SaveAsFile(downloadFolder.TrimEnd('\\') + "\\" + attachment.FileName); | ||
} | ||
} | ||
else | ||
{ | ||
Common.DisplayMailItem(mailItem); | ||
} | ||
} | ||
} | ||
else if (item is MeetingItem meetingItem) | ||
{ | ||
if (meetingItem.Attachments.Count > 0) | ||
{ | ||
if (download) | ||
{ | ||
foreach (Attachment attachment in meetingItem.Attachments) | ||
{ | ||
attachment.SaveAsFile(downloadFolder.TrimEnd('\\') + "\\" + attachment.FileName); | ||
} | ||
} | ||
else | ||
{ | ||
Common.DisplayMeetingItem(meetingItem); | ||
} | ||
} | ||
} | ||
} | ||
catch (System.Exception e) | ||
{ | ||
Console.WriteLine(e.Message); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using Microsoft.Office.Interop.Outlook; | ||
using System; | ||
using System.IO; | ||
using Carbuncle.Helpers; | ||
|
||
namespace Carbuncle.Commands | ||
{ | ||
public class MailMonitor | ||
{ | ||
public MailMonitor() | ||
{ | ||
|
||
} | ||
private void NewEmailEvent(object item) | ||
{ | ||
if (item is MailItem mailItem) | ||
{ | ||
Common.DisplayMailItem(mailItem); | ||
} | ||
|
||
if (item is MeetingItem meetingItem) | ||
{ | ||
Common.DisplayMeetingItem(meetingItem); | ||
|
||
} | ||
} | ||
public void Start() | ||
{ | ||
MonitorEmail(); | ||
} | ||
public void Start(string regex) | ||
{ | ||
MonitorEmailRegex(regex); | ||
} | ||
|
||
private void MonitorEmail() | ||
{ | ||
MailSearcher ms = new MailSearcher(); | ||
Console.WriteLine("[+] Starting e-mail monitoring..."); | ||
Items mailItems = ms.GetInboxItems(OlDefaultFolders.olFolderInbox); | ||
mailItems.ItemAdd += new ItemsEvents_ItemAddEventHandler(NewEmailEvent); | ||
Console.WriteLine("[+] Started, press Ctrl+Z to exit"); | ||
} | ||
private void MonitorEmailRegex(string regex) | ||
{ | ||
MailSearcher ms = new MailSearcher(); | ||
Console.WriteLine("[+] Starting e-mail monitoring..."); | ||
Items mailItems = ms.GetInboxItems(OlDefaultFolders.olFolderInbox); | ||
mailItems.ItemAdd += new ItemsEvents_ItemAddEventHandler(NewEmailEvent); | ||
Console.WriteLine("[+] Started, press Ctrl+Z to exit"); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.