void _getMails(object param) { helpers.addLog("_getMails() started..."); OnStateChanged(new StatusEventArgs(StatusType.busy, "looking thru eMails")); OutlookMail _olk = (OutlookMail)param; //need an instance _olk.OnStateChanged(new StatusEventArgs(StatusType.busy, "_getMails() started...")); try { _olk.OnStateChanged(new StatusEventArgs(StatusType.ews_pulse, "looking thru emails")); Outlook.Items items = MyInbox.Items; items.Sort("[ReceivedTime]"); foreach (object o in items)// MyInbox.Items.Sort("[ReceivedTime]")) { processMail(o); /* * if (o == null) * continue; * int foundAttachements=0; * if (o == null) * continue; * Outlook.MailItem mitem = o as Outlook.MailItem; * if (mitem == null) * continue; * if(mitem.Subject!=null) * helpers.addLog(string.Format("looking at: {0}\n", mitem.Subject)); * else * helpers.addLog(string.Format("looking at: {0}\n", mitem.EntryID)); * * if (mitem.Attachments.Count == 0) * continue; * else * { * //look for .xml * foreach (Outlook.Attachment att in mitem.Attachments) * { * if (att.FileName.EndsWith("xml")) * foundAttachements++; * } * } * if (foundAttachements == 0) * continue; //no attachement ending in xml * if(mitem.Subject.IndexOf(helpers.filterSubject)==-1) * continue; * if (mitem.Subject.IndexOf(sMailHasAlreadyProcessed) > 0) //do not process mail again * continue; * * //process mail * helpers.addLog(string.Format("### mail found: {0},\n{1}\n\n", mitem.Subject, mitem.Body)); * _olk.OnStateChanged(new StatusEventArgs(StatusType.ews_pulse, "getMail: processing eMail " + mitem.Subject)); * MailMsg myMailMsg = new MailMsg(mitem, _olk._userData.sUser); * int iRet = _olk._licenseMail.processMail(myMailMsg); * //change subject * mitem.Subject += sMailHasAlreadyProcessed; * mitem.Close(Outlook.OlInspectorClose.olSave); * Thread.Sleep(100); * Thread.Yield(); */ } } catch (System.Exception ex) { helpers.addExceptionLog(ex.StackTrace); } _olk.OnStateChanged(new StatusEventArgs(StatusType.ews_pulse, "read mail done")); }