2 回答

TA貢獻1841條經驗 獲得超3個贊
首先,您的代碼無法編譯——對象上沒有ItemAdd
事件MAPIFolder
。它由Items
對象公開(從MAPIFolder.Items
屬性返回)。
其次,引發(fā)事件 ( Items
) 的對象必須保持活動狀態(tài) - 在類級別聲明它,而不是作為局部變量,在ThisAddIn_Startup
方法退出時由垃圾收集器釋放。

TA貢獻1836條經驗 獲得超13個贊
工作代碼就像
public partial class ThisAddIn
{
Outlook.Items items=null;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Outlook.MAPIFolder inbox =
Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
items=inbox.Items;
items.ItemAdd += new
Outlook.ItemsEvents_ItemAddEventHandler(InboxFolderItemAdded);
}
private void InboxFolderItemAdded(object Item)
{
if (Item is Outlook.MailItem)
{
Debug.WriteLine("I'm in!");
Outlook.MailItem mail = (Outlook.MailItem)Item;
int[] answer = Predict(mail);
if(answer[0] == 0) // Not spam
{
Outlook.MAPIFolder inboxFolder = ((Outlook.MAPIFolder)this.Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox));
mail.Move(inboxFolder);
}
else if(answer[0] == 1) // Spam
{
Outlook.MAPIFolder junkFolder = ((Outlook.MAPIFolder)this.Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderJunk));
mail.Move(junkFolder);
}
}
}
private int[] Predict(Outlook.MailItem mailBody)
{
Debug.WriteLine("I'm inside in predict function");
double[]feature = featureExtraction.findFeatureIncomingMail(mailBody.Body);
int[] answer = tree.Decide(feature);
return answer;
}
}
- 2 回答
- 0 關注
- 107 瀏覽
添加回答
舉報