public override bool DisplayMessage(string EntryID, string StoreID) { try { IEMsgStore msgStore = OutlookSession.OpenMsgStore(StoreID); if (msgStore != null) { return(msgStore.DisplayMessage(EntryID, OutlookSession.GetDefaultMsgStore())); } } catch (Exception exception) { ReportProblem(exception); } return(false); }
protected override void Execute() { IEMessage message = OutlookSession.OpenMessage(_messageIDs.EntryId, _messageIDs.StoreId); if (message == null) { return; } using ( message ) { int flagStatus = 0; int flagColor = 0; GetCurrentFlag(message, out flagStatus, out flagColor); ExportFlag(message, flagStatus, flagColor); } }
public IEMessage OpenMessage() { IResource mail = Core.ResourceStore.LoadResource(_sourceMailID); if (mail == null) { return(null); } PairIDs messageIDs = PairIDs.Get(mail); if (messageIDs == null) { return(null); } return(OutlookSession.OpenMessage(messageIDs.EntryId, messageIDs.StoreId)); }
private static void ExportAnnotationImpl(IResource emailResource) { Guard.NullArgument(emailResource, "emailResource"); if (emailResource.Type != STR.Email) { throw new ArgumentException("Expected 'Email' resource but was " + emailResource.Type); } if (Mail.MailInIMAP(emailResource)) { return; } PairIDs messageIDs = PairIDs.Get(emailResource); if (messageIDs == null) { return; } IEMessage message = OutlookSession.OpenMessage(messageIDs.EntryId, messageIDs.StoreId); if (message == null) { return; } using ( message ) { string annotation = emailResource.GetPropText(Core.Props.Annotation); int tag = message.GetIDsFromNames(ref GUID.set1, lID.msgFlagAnnotation, PropType.PT_STRING8); string oldAnnotation = message.GetStringProp(tag); if (oldAnnotation == null) { oldAnnotation = string.Empty; } if (!oldAnnotation.Equals(annotation)) { if (annotation.Length == 0) { message.DeleteProp(tag); } else { message.SetStringProp(tag, annotation); } OutlookSession.SaveChanges("ExportAnnotation for resource id = " + emailResource.Id, message, messageIDs.EntryId); } } }
public void DeleteMessage(string entryID) { IResource mail = Core.ResourceStore.FindUniqueResource(STR.Email, PROP.EntryID, entryID); if (mail != null) { PairIDs mailIDs = PairIDs.Get(mail); if (mailIDs != null) { OutlookSession.DeleteMessage(mailIDs.StoreId, entryID, false); } else { Mail.ForceDelete(mail); } } }
public static IEFolders GetFolders(IEFolder folder, FolderDescriptor folderDescriptor) { try { if (folderDescriptor == null) { folderDescriptor = FolderDescriptor.Get(folder); } return(folder.GetFolders()); } catch (COMException exception) { _tracer.TraceException(exception); OutlookSession.ProblemWithOpeningFolder(folderDescriptor.FolderIDs.EntryId); } return(null); }
private void SynchronizeMAPIInfoStoresImpl() { bool isInitialStart = IsInitialStart(); HashMap infoStores = new HashMap(); foreach (IResource infoStore in Core.ResourceStore.GetAllResources(STR.MAPIInfoStore).ValidResources) { string storeId = infoStore.GetStringProp(PROP.EntryID); if (storeId != null) { if (!OutlookSession.WereProblemWithOpeningStorage(storeId)) { infoStores.Add(storeId, infoStore); } } else { new ResourceProxy(infoStore).DeleteAsync(); } } foreach (IEMsgStore msgStore in OutlookSession.GetMsgStores()) { if (msgStore == null) { continue; } string storeID = msgStore.GetBinProp(MAPIConst.PR_ENTRYID); infoStores.Remove(storeID); MAPIInfoStoreDescriptor infoStoreJob = new MAPIInfoStoreDescriptor(msgStore); if (isInitialStart) { Core.ResourceAP.RunJob(infoStoreJob); } else { Core.ResourceAP.QueueJob(JobPriority.Immediate, infoStoreJob); } } foreach (HashMap.Entry entry in infoStores) { IResource infoStore = (IResource)entry.Value; new ResourceProxy(infoStore).Delete(); } }
private bool CreateNewMessage(string subject, string body, EmailBodyFormat bodyFormat, ArrayList recipients, ArrayList attachments, bool useTemplatesInBody) { try { MailBodyFormat mailBodyFormat = MailBodyFormat.HTML; if (bodyFormat == EmailBodyFormat.PlainText) { if (useTemplatesInBody && Settings.UseSignature) { body += "\r\n"; body += Settings.Signature; } mailBodyFormat = MailBodyFormat.PlainText; } else if (bodyFormat == EmailBodyFormat.Html) { body = _rxHtmlComment.Replace(body, ""); body = "<HTML><BODY>" + body; if (useTemplatesInBody && Settings.UseSignature) { body += "\r\n"; body += Settings.Signature; } body += "</BODY></HTML>"; Trace.WriteLine("HTML body for Outlook: \r\n" + body); } IEMsgStore msgStore = OutlookSession.GetDefaultMsgStore(); if (msgStore != null) { return(msgStore.CreateNewMessage(subject, body, mailBodyFormat, recipients, attachments, OutlookSession.GetOutlookDefaultEncodingOut())); } else { throw new ApplicationException("There are no default message store for outlook"); } } catch (Exception exception) { ReportProblem(exception); } return(false); }
public void Exec(IResource resource, IActionParameterStore actionStore) { Tracer._Trace("Execute rule: DeleteMessageRuleAction"); if (resource == null || resource.Type != STR.Email) { return; } try { PairIDs messageIDs = PairIDs.Get(resource); OutlookSession.DeleteMessage(messageIDs.StoreId, messageIDs.EntryId, true); } catch (Exception exception) { Tracer._TraceException(exception); } }
private void SynchronizeFolderRecursive(IEFolder folder, string name, string storeID, FolderDescriptor parentDescriptor) { if (folder == null) { return; } using ( folder ) { FolderDescriptor folderDescriptor = FolderDescriptor.Get(folder); if (name != null) { folderDescriptor.Name = name; _tracer.Trace("Folder name = " + name); } else { _tracer.Trace("Folder name is unknown"); } _folders.Remove(folderDescriptor.FolderIDs.EntryId); FolderStructureDescriptor folderStruct = new FolderStructureDescriptor(parentDescriptor, folderDescriptor); Core.ResourceAP.QueueJob(folderStruct); IEFolders folders = OutlookSession.GetFolders(folder, folderDescriptor); if (folders == null) { return; } using ( folders ) { for (int i = 0; i < folders.GetCount(); ++i) { try { SynchronizeFolderRecursive(folders.OpenFolder(i), null, storeID, folderDescriptor); } catch (COMException exception) { _tracer.TraceException(exception); OutlookSession.ProblemWithOpeningFolder(folderDescriptor.FolderIDs.EntryId); break; } } } } }
private void _outlookProcessor_ThreadFinished(object sender, EventArgs e) { Settings.LastExecutionTime.Save(DateTime.Now); OutlookSession.OutlookProcessor.ProcessJobs(); try { OutlookSession.Uninitialize(); } catch (Exception exception) { _tracer.TraceException(exception); SetLastException(exception); } if (_aborted) { _finished = true; } }
public override bool ReplyMessage(IResource mail, string EntryID, string StoreID) { try { OutlookSession.EMAPISession.SetQuoter(new ReplyQuoter(mail)); IEMsgStore msgStore = OutlookSession.OpenMsgStore(StoreID); if (msgStore != null) { return(msgStore.ReplyMessage(EntryID, OutlookSession.GetDefaultMsgStore())); } return(true); } catch (Exception exception) { ReportProblem(exception); } return(false); }
private bool CheckArgument(string category, MAPINtf ntf) { Guard.NullArgument(ntf, "ntf"); if (_bTrace) { Trace(category, ntf); } if (ntf.EntryID != null && ntf.EntryID.Length > 0) { bool ret = OutlookSession.IsMailExported(ntf.EntryID); if (ret) { Trace(category + ": event is ignored"); } return(!ret); } return(true); }
protected override void Execute() { IEMAPIProp message = OpenMessage(_contact, false, true, true); if (message == null) { if (_newCreated) { _tracer.Trace("Cannot Export NEW contact for resource id = " + _contact.Id); } _tracer.Trace("Cannot Export contact for resource id = " + _contact.Id); return; } using ( message ) { ExportCategories.ProcessCategories(message, _contact); OutlookSession.SaveChanges(_newCreated, "Export contact for resource id = " + _contact.Id, message, message.GetBinProp(MAPIConst.PR_ENTRYID)); } }
public static bool IsStorageSupported(IEMsgStore msgStore) { if (Settings.SupportIMAP) { return(true); } IEFolder root = msgStore.GetRootFolder(); if (root == null) { return(true); } using ( root ) { IEFolders folders = OutlookSession.GetFolders(root); if (folders == null) { return(true); } using ( folders ) { int count = folders.GetCount(); for (int i = 0; i < count; ++i) { IEFolder folder = OpenFolder(folders, i); if (folder == null) { continue; } using ( folder ) { string containerClass = folder.GetStringProp(MAPIConst.PR_CONTAINER_CLASS); if (FolderType.IMAP == containerClass) { return(false); } } } } } return(true); }
protected override void Execute() { if (IsDataCorrect(_folder)) { PairIDs folderIDs = _folder.FolderIDs; IEMessage message = OutlookSession.OpenMessage(_entryID, folderIDs.StoreId); if (message == null) { return; } using ( message ) { OutlookAddressBook AB = new OutlookAddressBook(_folder.Name, _folder.FolderIDs, true); ContactDescriptor contactDescriptor = new ContactDescriptor(message, _entryID, _searchEntryID, AB); Core.ResourceAP.QueueJob(contactDescriptor); } } }
public static Icon[] GetOverlayIcon(IResource resource) { PairIDs folderIDs = PairIDs.Get(resource); if (folderIDs != null) { if (OutlookSession.WereProblemWithOpeningStorage(folderIDs.StoreId) || OutlookSession.WereProblemWithOpeningFolder(folderIDs.EntryId)) { if (_problem == null) { _problem = new Icon[1]; _problem[0] = OutlookPlugin.LoadIconFromAssembly("OutlookPlugin.Icons.inaccessible.ico"); } return(_problem); } } return(null); }
private void OnMailModifyImpl(MAPIFullNtf ntf) { if (CheckStorageIgnored(_storeID)) { return; } try { IEFolder folder = OutlookSession.OpenFolder(ntf.ParentID, _storeID); if (folder == null) { return; } using ( folder ) { FolderDescriptor folderDescriptor = FolderDescriptor.Get(folder); if (folderDescriptor.ContainerClass == FolderType.IMAP) { if (!ProcessMailAddNtf.ProcessIMAPMessage(folder, ntf.EntryID)) { return; } } IEMessage message = OutlookSession.OpenMessage(ntf.EntryID, _storeID); if (message == null) { return; } using ( message ) { ProcessMailModifyImpl(ntf, message, folderDescriptor); } } } catch (System.Threading.ThreadAbortException ex) { Tracer._TraceException(ex); } catch (Exception exception) { Core.ReportBackgroundException(exception); } }
private void ProcessContactFolders(int processedABs, int totalABs) { ArrayList toDeleteFolders = new ArrayList(); foreach (IResource contactFolder in Folder.GetFolders(FolderType.Contact).ValidResources) { if (ShuttingDown) { break; } OutlookSession.ProcessJobs(); processedABs++; int percentage = (processedABs * 100) / totalABs; Settings.UpdateProgress(percentage, "Indexing Address Books", processedABs.ToString()); PairIDs folderIDs = PairIDs.Get(contactFolder); if (folderIDs == null) { toDeleteFolders.Add(contactFolder); continue; } string abName = OutlookAddressBook.GetProposedName(contactFolder.GetPropText(Core.Props.Name), folderIDs.EntryId); Core.ResourceAP.QueueJob(new OutlookAddressBookReName(folderIDs.EntryId, abName)); if (!Folder.IsIgnoreImport(contactFolder)) { ProcessContactFolder(folderIDs, abName); } else { IResource AB = Core.ResourceStore.FindUniqueResource(STR.AddressBook, PROP.EntryID, folderIDs.EntryId); if (AB != null) { new ResourceProxy(AB).DeleteAsync(); } } } foreach (IResource contactFolder in toDeleteFolders) // delete corrupted 'MAPIFolder' resources { new ResourceProxy(contactFolder).DeleteAsync(); } }
public void Enumerate() { IEFolder folder = _msgStore.GetRootFolder(); if (folder != null) { using ( folder ) { FolderDescriptor tag = null; FolderDescriptor folderDescriptor = FolderDescriptor.Get(_storeID, folder); folderDescriptor.Name = _storeName; bool continueEnumerate = _enumListener.FolderFetched(null, folderDescriptor, out tag); if (continueEnumerate) { OutlookSession.ProcessJobs(); EnumerateInternal(folder, tag); } } } }
public override void OK() { // Workaround of OM-13897, calling an OutlookSession in the shutdown // state causes unpredictable results. if (Core.State == CoreState.Running) { _treeView.SaveCheckedState(); MAPIIDs IDs = OutlookSession.GetInboxIDs(); if (IDs != null) { IResource folder = Folder.Find(IDs.EntryID); if (folder != null && !Folder.IsIgnored(folder)) { Core.UIManager.CreateShortcutToResource(folder); } } SettingSaver.Save(Controls); Settings.LoadSettings(); } }
public static IEMessage OpenMessage(string parentFolderId, IEFolder folder, string entryId) { try { return(OpenMessage(folder, entryId)); } catch (COMException exception) { if (exception.ErrorCode == (unchecked ((int)0x8004060E))) //Folder is in offline mode { OutlookSession.ProblemWithOpeningFolder(parentFolderId); return(null); } if (exception.ErrorCode == (unchecked ((int)0x80004005)) || exception.ErrorCode == (unchecked ((int)0x80040608))) { return(null); } throw exception; } }
public void EnumerateMessageItems(FolderDescriptor folderDescriptor) { if (OutlookSession.WereProblemWithOpeningStorage(folderDescriptor.FolderIDs.StoreId) || OutlookSession.WereProblemWithOpeningFolder(folderDescriptor.FolderIDs.EntryId)) { return; } try { IEFolder mapiFolder = OutlookSession.OpenFolder(folderDescriptor.FolderIDs.EntryId, folderDescriptor.FolderIDs.StoreId); if (mapiFolder == null) { return; } using ( mapiFolder ) { string containerClass = mapiFolder.GetStringProp(MAPIConst.PR_CONTAINER_CLASS); bool taskFolder = (FolderType.Task.Equals(containerClass)); if (taskFolder) { EnumerateTasks(folderDescriptor, mapiFolder); } else { EnumerateMail(folderDescriptor, mapiFolder); } } } catch (COMException exception) { _tracer.TraceException(exception); if (exception.ErrorCode == MapiError.MAPI_E_NOT_ENOUGH_DISK) { StandartJobs.MessageBox("Outlook reports that there is no enough disk space.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } OutlookSession.ProblemWithOpeningFolder(folderDescriptor.FolderIDs.EntryId); return; } }
private TaskDescriptor(FolderDescriptor folder, IEMessage message, string entryID) { _folder = folder; _entryID = entryID; if (message != null) { _subject = Task.GetSubject(message); _description = Task.GetDescription(message); _priority = Task.GetPriority(message); _dueDate = Task.GetDueDate(message); _dueDate = _dueDate.ToUniversalTime(); _startDate = Task.GetStartDate(message); _startDate = _startDate.ToUniversalTime(); _remindDate = Task.GetRemindDate(message); _OMTaskId = Task.GetOMTaskID(message); _reminderActive = Task.GetReminderActive(message); _status = Task.GetStatus(message, false); _outlookCategories = OutlookSession.GetCategories(message); } }
private void Init(bool computeCounts, DateTime indexStartDate, bool idle) { _idle = idle; _indexStartDate = indexStartDate; _mailsInOldIndex = new MailInIndex(); if (computeCounts) { Settings.UpdateProgress(0, "Computing Outlook Folders count...", ""); int Start = Environment.TickCount; _foldersCount = OutlookSession.ComputeFolders(); int Finish = Environment.TickCount - Start; Trace.WriteLine("folder enumeration: " + Finish.ToString()); Trace.WriteLine("folders count: " + _foldersCount.ToString()); Start = Environment.TickCount; } }
private static void TryAgainToAddMail(FolderDescriptor folderDescriptor, string entryID, string longBody) { IEMessage message = null; try { message = OutlookSession.OpenMessage(entryID, folderDescriptor.FolderIDs.StoreId); } catch (COMException exception) { if (exception.ErrorCode == MapiError.MAPI_E_SUBMITTED) { Core.NetworkAP.QueueJobAt(DateTime.Now.AddMinutes(1), new DelegateTryAgainToAddMail(TryAgainToAddMail), folderDescriptor, entryID, longBody); } } using ( message ) { Core.ResourceAP.QueueJob(new MailDescriptor(folderDescriptor, entryID, message, longBody)); } }
private void SynchronizeContactsImpl() { _tracer.Trace("Start SynchronizeContactsImpl"); Settings.UpdateProgress(0, "Computing Address Books count...", ""); int totalABs = Folder.GetFolders(FolderType.Contact).Count; int processedABs = 0; IEAddrBook addrBook = OutlookSession.GetAddrBook(); if (addrBook != null) { int count = addrBook.GetCount(); totalABs += count; for (int i = 0; i < count; ++i) { if (ShuttingDown) { return; } OutlookSession.ProcessJobs(); ++processedABs; int percentage = (processedABs * 100) / totalABs; Settings.UpdateProgress(percentage, "Synchronizing Address Books", processedABs.ToString()); IEABContainer abContainer = addrBook.OpenAB(i); if (abContainer == null) { continue; } using ( abContainer ) { ProcessGlobalAddressBook(abContainer); } } } ProcessContactFolders(processedABs, totalABs); _tracer.Trace("Finish SynchronizeContactsImpl"); Settings.UpdateProgress(100, "Synchronizing Address Books", totalABs.ToString()); }
public static bool DeleteMessage(string storeId, string entryId, bool DeletedItems) { if (!DeletedItems) { OutlookSession.DeleteMessageImpl(storeId, entryId, false); return(true); } PairIDs folderIds = OutlookSession.GetDeletedItemsFolderIDs(storeId); if (folderIds == null) { OutlookSession.DeleteMessageImpl(storeId, entryId, false); return(true); } string folderID = null; IEMessage message = OutlookSession.OpenMessage(entryId, storeId); if (message == null) { return(false); } using ( message ) { folderID = message.GetBinProp(MAPIConst.PR_PARENT_ENTRYID); } if (folderID != null) { if (folderID != folderIds.EntryId) { if (MoveMessage(storeId, entryId, folderID, folderIds)) { return(true); } } } OutlookSession.DeleteMessageImpl(storeId, entryId, false); return(true); }
private static bool MoveMessage(string storeID, string entryID, string folderID, PairIDs delFolderIds) { if (folderID == null) { return(false); } if (folderID != delFolderIds.EntryId) { IEFolder delFolder = OutlookSession.OpenFolder(delFolderIds.EntryId, delFolderIds.StoreId); if (delFolder == null) { return(false); } using ( delFolder ) { IEFolder folder = OutlookSession.OpenFolder(folderID, storeID); if (folder == null) { return(false); } using ( folder ) { try { folder.MoveMessage(entryID, delFolder); return(true); } catch (COMException exception) { _tracer.TraceException(exception); StandartJobs.MessageBox("Cannot complete deleting mail. Reason: " + exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } } } return(false); }
private void ProcessMailModifyImpl(MAPIFullNtf ntf, IEMessage message, FolderDescriptor folderDescriptor) { string messageClass = MessageType.GetMessageClass(message); if (MessageType.InterpretAsMail(messageClass)) { string entryId = OutlookSession.GetMessageID(message); if (OutlookSession.IsMailExported(entryId)) { return; } new MailDescriptor(folderDescriptor, entryId, message, MailDescriptor.UpdateState).QueueJob(JobPriority.AboveNormal); } else if (MessageType.InterpretAsContact(messageClass)) { string realEntryId = message.GetBinProp(MAPIConst.PR_ENTRYID); if (OutlookSession.IsMailExported(realEntryId)) { return; } ContactDescriptorWrapper.Do(folderDescriptor, realEntryId, realEntryId); } else if (MessageType.InterpretAsTask(messageClass)) { _tracer.Trace("Task was modified"); string realEntryId = message.GetBinProp(MAPIConst.PR_ENTRYID); if (OutlookSession.IsMailExported(realEntryId)) { return; } TaskDescriptor.Do(JobPriority.AboveNormal, folderDescriptor, message, realEntryId); } else { ntf = ntf; // _tracer.Trace( "Unknown item of class " + messageClass + " was modified" ); } }