The integration has two goal:
1. Scan the email not only when received but also the past emails
2. Don't waste CPU time and IO disk to scan by outside, but scan the emails from inside the Thunderbird database
The emails are sent by socket to the service-mode application
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
using System.Windows.Forms;
using Giesa.Base;
using OpenAVUserMode.servicecom;
namespace MultiAntivirusForOutlook
{
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.NewMail += new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_NewMailEventHandler(ThisApplication_NewMail);
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
// Nota: Outlook non genera più questo evento. Se è presente codice che
// deve essere eseguito all'arresto di Outlook, vedere https://go.microsoft.com/fwlink/?LinkId=506785
}
private void ThisApplication_NewMail()
{
Outlook.MAPIFolder inBox = this.Application.ActiveExplorer()
.Session.GetDefaultFolder(Outlook
.OlDefaultFolders.olFolderInbox);
Outlook.Items inBoxItems = inBox.Items;
Outlook.MailItem newEmail = null;
inBoxItems = inBoxItems.Restrict("[Unread] = true");
VFS vfs = new VFS();
try
{
foreach (object collectionItem in inBoxItems)
{
newEmail = collectionItem as Outlook.MailItem;
if (newEmail != null)
{
if (newEmail.Attachments.Count > 0)
{
for (int i = newEmail.Attachments.Count; i > 0 ; i--)
{
GString gs = new GString();
gs.initRandomUUID();
newEmail.Attachments[i].SaveAsFile
(@"C:\ProgramData\AntiVirusScanning\" +
gs.toString());//newEmail.Attachments[i].FileName
ManualScan MS = new ManualScan();
InfoRetBool scan = MS.ScanSyncFile("C:\\ProgramData\\AntiVirusScanning\\" + gs.toString());
if (scan.noFault())
{
if (scan.retVar)
{
//don't remove the file, the service will do it after quarantene it
newEmail.Attachments.Remove(i);
}
else
{
vfs.FileKillIfExist(new MAC("IntegrationOutlook"), "/C:/ProgramData/AntiVirusScanning/" + gs.toString());
}
}
}
}
}
}
}
catch (System.Exception ex)
{
/*string errorInfo = (string)ex.Message.Substring(0, 11);
if (errorInfo == "Cannot save")
{
//MessageBox.Show(@"Create Folder C:\TestFileSave");
}*/
}
}
#region Codice generato da VSTO
///
/// Metodo richiesto per il supporto della finestra di progettazione. Non modificare
/// il contenuto del metodo con l'editor di codice.
///
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}
If you want to integrate your application with MultiAntivirus plese contact us, we will help you for the integration