private void DoMoveBetweenStorages(IResource resMail, IEMessage message, PairIDs messageIDs, PairIDs selectedFolderIDs) { using ( message ) { IEFolder folder = OutlookSession.OpenFolder(selectedFolderIDs.EntryId, selectedFolderIDs.StoreId); if (folder == null) { return; } using ( folder ) { IEMessage newMessage = folder.CreateMessage("IPM.note"); using ( newMessage ) { message.CopyTo(newMessage); string entryID = newMessage.GetBinProp(MAPIConst.PR_ENTRYID); OutlookSession.SaveChanges(true, "Save mail for moving between storages resource id = " + resMail.Id, newMessage, entryID); if (_copy) { return; } if (!string.IsNullOrEmpty(entryID) && !resMail.HasProp(-PROP.Attachment)) { new ResourceProxy(resMail).SetProp(PROP.EntryID, entryID); } OutlookSession.DeleteMessage(messageIDs.StoreId, messageIDs.EntryId, false); } } } }
private void LoadMessageID() { IEFolder folderFirst = OutlookSession.OpenFolder(_folderFirst.FolderIDs.EntryId, _folderFirst.FolderIDs.StoreId); Assert.IsNotNull(folderFirst); using ( folderFirst ) { IEMessages messages = folderFirst.GetMessages(); Assert.IsNotNull(messages); using ( messages ) { if (messages.GetCount() == 0) { Assert.Fail("Source folder should have at least one message"); } if (messages.GetCount() != 1) { Assert.Fail("Source folder should have one message"); } IEMessage message = messages.OpenMessage(0); Assert.IsNotNull(message); using ( message ) { _messageID = OutlookSession.GetMessageID(message); _recordKey = message.GetBinProp(MAPIConst.PR_RECORD_KEY); } } } Assert.IsNotNull(_messageID); }
protected override void ExecuteAction(IResource resource, PairIDs pairIDs) { Tracer._Trace("Execute action: SaveToMSGAction"); Trace.WriteLine(">>> SaveToMSGAction.ExecuteAction"); if (pairIDs != null) { IEMessage message = OutlookSession.OpenMessage(pairIDs.EntryId, pairIDs.StoreId); if (message == null) { return; } using ( message ) { string fileName = null; if (!_single) { string subject = message.GetStringProp(MAPIConst.PR_SUBJECT); CorrectFileName(ref subject); if (subject == null || subject.Length == 0) { subject = message.GetBinProp(MAPIConst.PR_ENTRYID); } fileName = Path.Combine(_path, subject + ".msg"); } else { fileName = _path; } ExecuteActionImpl(message, fileName); } } Trace.WriteLine("<<< SaveToMSGAction.ExecuteAction"); }
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" ); } }
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 void DoMoveImpl(IEMessage message, PairIDs messageIDs, PairIDs selectedFolderIDs) { string parentID = string.Empty; using ( message ) { parentID = message.GetBinProp(MAPIConst.PR_PARENT_ENTRYID); } IEFolder parentFolder = OutlookSession.OpenFolder(parentID, messageIDs.StoreId); if (parentFolder == null) { return; } using ( parentFolder ) { IEFolder folder = OutlookSession.OpenFolder(selectedFolderIDs.EntryId, selectedFolderIDs.StoreId); if (folder == null) { return; } using ( folder ) { if (_copy) { parentFolder.CopyMessage(messageIDs.EntryId, folder); } else { parentFolder.MoveMessage(messageIDs.EntryId, folder); } } } }
private void ExecuteImpl() { bool wasChanges = false; IEMessage message = OpenMessage(ref wasChanges); if (message == null) { return; } using ( message ) { SetPriority(message, ref wasChanges); SetSubject(message, ref wasChanges); SetDescription(message, ref wasChanges); SetDueDate(message, ref wasChanges); SetStartDate(message, ref wasChanges); SetRemindDate(message, ref wasChanges); SetRemindActive(message, ref wasChanges); SetStatus(message, ref wasChanges); if (Settings.SyncTaskCategory) { SetCategories(message, ref wasChanges); } SetOMTaskID(message, ref wasChanges); if (wasChanges) { OutlookSession.SaveChanges(_created, "Export task resource id = " + _task.Id, message, message.GetBinProp(MAPIConst.PR_ENTRYID)); } } }
protected void Init(FolderDescriptor folderDescriptor, string entryID, IEMessage message, string longBody) { _longBody = longBody; _folder = folderDescriptor; _messageClass = MessageType.GetMessageClass(message); if (!Settings.ProcessAllPropertiesForMessage) { _subject = "test"; return; } string folderID = message.GetBinProp(MAPIConst.PR_PARENT_ENTRYID); if (folderID != null) { string storeID = message.GetBinProp(MAPIConst.PR_STORE_ENTRYID); IEFolder folder = OutlookSession.OpenFolder(folderID, storeID); if (folder != null) { using ( folder ) { _folder = FolderDescriptor.Get(folder); } } } _entryID = entryID; if (_folder != null && Folder.IsIgnored(_folder)) { _toDeleteResource = true; return; } int tag = message.GetIDsFromNames(ref GUID.set1, lID.msgDeletedInIMAP, PropType.PT_LONG); _deletedInIMAP = message.GetLongProp(tag) == 1; if (_deletedInIMAP && Settings.IgnoreDeletedIMAPMessages) { _toDeleteResource = true; return; } _subject = message.GetStringProp(MAPIConst.PR_SUBJECT); if (_subject == null) { _subject = string.Empty; } _unread = message.IsUnread(); _lastModifiedDate = message.GetDateTimeProp(MAPIConst.PR_LAST_MODIFICATION_TIME); _lastModifiedDate = _lastModifiedDate.ToUniversalTime(); _messageSize = message.GetLongProp(MAPIConst.PR_MESSAGE_SIZE); _iconIndex = message.GetLongProp(MAPIConst.PR_ICON_INDEX); _priority = message.GetLongProp(MAPIConst.PR_PRIORITY); int importance = message.GetLongProp(MAPIConst.PR_IMPORTANCE, true); if (importance == -9999) { importance = 1; } _importance = importance - 1; _flagStatus = message.GetLongProp(MAPIConst.PR_FLAG_STATUS); if (_flagStatus == 2) { _flagColor = message.GetLongProp(MAPIConst.PR_FLAG_COLOR, true); if (_flagColor == -9999) { _flagColor = 6; } } _internetMessageID = message.GetStringProp(MAPIConst.PR_INTERNET_MESSAGE_ID); _recordKey = message.GetBinProp(MAPIConst.PR_RECORD_KEY); _conversationIndex = message.GetBinProp(MAPIConst.PR_CONVERSATION_INDEX); _replyToID = message.GetStringProp(MAPIConst.PR_IN_REPLY_TO_ID); _internetReferences = message.GetStringProp(MAPIConst.PR_INTERNET_REFERENCES); if (Settings.CreateAnnotationFromFollowup) { int annotationTag = message.GetIDsFromNames(ref GUID.set1, lID.msgFlagAnnotation, PropType.PT_STRING8); _flag = message.GetStringProp(annotationTag); } _outlookCategories = OutlookSession.GetCategories(message);; _receivedTime = message.GetDateTimeProp(MAPIConst.PR_MESSAGE_DELIVERY_TIME); _sentOn = message.GetDateTimeProp(MAPIConst.PR_CLIENT_SUBMIT_TIME); if (_receivedTime == DateTime.MinValue) { _receivedTime = _sentOn; } _listUnsubscribe = message.GetStringProp(MAPIConst.PR_LIST_UNSUBSCRIBE); if (_listUnsubscribe != null) { _listUnsubscribe = ExtractUnsubscribeEmail(_listUnsubscribe); } _contactCreated = MailSenderHelper.LoadSenderInfo(message, out _senderName, out _senderEmail); if (Settings.ProcessRecipients) { _state.EndOfInit(this, message); } }
public override void OnMailMove(MAPIFullNtf ntf) { Console.WriteLine("OnMailMove: " + _count); Console.WriteLine("ntf.EntryID: " + ntf.EntryID); Console.WriteLine("ntf.OntryID: " + ntf.OldEntryID); IEMessage message = null; string msgId = null; string recordKey = null; switch (_count) { case 0: message = OutlookSession.OpenMessage(ntf.EntryID, _storeID); if (message == null) { return; } Console.WriteLine("Subject + " + message.GetStringProp(MAPIConst.PR_SUBJECT)); Assert.IsNotNull(message); using ( message ) { msgId = OutlookSession.GetMessageID(message); recordKey = message.GetBinProp(MAPIConst.PR_RECORD_KEY); } Console.WriteLine("Id1: " + msgId); Console.WriteLine("Id2: " + _messageID); if (msgId != _messageID) { if (recordKey == _recordKey) { _messageID = msgId; } else { return; } } Console.WriteLine("PID = " + ntf.ParentID); Console.WriteLine("OID = " + ntf.OldParentID); Console.WriteLine("FID = " + _folderFirst.FolderIDs.EntryId); Console.WriteLine("SID = " + _folderSecond.FolderIDs.EntryId); Assert.AreEqual(GetFolderID(ntf.ParentID), _folderSecond.FolderIDs.EntryId); Assert.AreEqual(GetFolderID(ntf.OldParentID), _folderFirst.FolderIDs.EntryId); ++_count; _complete = true; break; case 1: message = OutlookSession.OpenMessage(ntf.EntryID, _storeID); if (message == null) { return; } Console.WriteLine(message.GetStringProp(MAPIConst.PR_SUBJECT)); Assert.IsNotNull(message); using ( message ) { msgId = OutlookSession.GetMessageID(message); recordKey = message.GetBinProp(MAPIConst.PR_RECORD_KEY); } Console.WriteLine("Id1: " + msgId); Console.WriteLine("Id2: " + _messageID); if (msgId != _messageID) { if (recordKey == _recordKey) { _messageID = msgId; } else { return; } } Assert.AreEqual(GetFolderID(ntf.ParentID), _folderFirst.FolderIDs.EntryId); Assert.AreEqual(GetFolderID(ntf.OldParentID), _folderSecond.FolderIDs.EntryId); ++_count; _complete = true; break; } }
private void ExportFlag(IEMessage message, int flagStatus, int flagColor) { bool wasChanges = false; if (_flagged) { if (_completed) { SetCompleteFlag(message, flagStatus, flagColor, ref wasChanges); } else { SetColorFlag(message, flagStatus, flagColor, ref wasChanges); } } else { ClearFlag(message, flagStatus, flagColor, ref wasChanges); } if (wasChanges) { OutlookSession.SaveChanges("Export email flag for resource id = " + _emailResource.Id, message, message.GetBinProp(MAPIConst.PR_ENTRYID)); } }
private void OnMailMoveImpl(MAPIFullNtf ntf) { if (CheckStorageIgnored(_storeID)) { return; } FolderDescriptor folderDescriptor = FolderDescriptor.Get(ntf.ParentID, _storeID); if (folderDescriptor == null) { return; } try { IEMessage message = OutlookSession.OpenMessage(ntf.EntryID, _storeID); if (message == null) { return; } using ( message ) { string realID = message.GetBinProp(MAPIConst.PR_ENTRYID); if (realID == null) { realID = ntf.EntryID; } else { if (OutlookSession.IsMailExported(realID)) { return; } } string messageClass = MessageType.GetMessageClass(message); if (MessageType.InterpretAsMail(messageClass)) { Core.ResourceAP.QueueJob(JobPriority.AboveNormal, new MailMovedDescriptor(ntf, _storeID)); } else if (MessageType.InterpretAsContact(messageClass)) { if (folderDescriptor.ContainerClass != FolderType.Contact) { _tracer.Trace("Contact was moved to deleted items"); IResource contact = Core.ResourceStore.FindUniqueResource(STR.Contact, PROP.EntryID, realID); string entryID = realID; if (contact == null && ntf.OldEntryID != null) { _tracer.Trace("contact not found"); contact = Core.ResourceStore.FindUniqueResource(STR.Contact, PROP.EntryID, ntf.OldEntryID); entryID = ntf.EntryID; } if (contact != null) { _tracer.Trace("contact found"); _tracer.Trace("RemoveFromSync"); Contact.RemoveFromSync(contact, entryID); } else { _tracer.Trace("ClearInvalidEntryIDFromContacts"); _jobStrategy.QueueJob(new MethodInvoker(REGISTRY.ClearInvalidEntryIDFromContacts)); } } else { string searchEntryID = realID; if (realID != ntf.OldEntryID) { searchEntryID = ntf.OldEntryID; } _tracer.Trace("ContactDescriptorWrapper process moving"); ContactDescriptorWrapper.Do(_jobStrategy.JobPriority, folderDescriptor, realID, searchEntryID); } //OutlookSession.OutlookProcessor.QueueJob( new ContactDescriptorWrapper( folderDescriptor, ntf.EntryID ) ); } else if (MessageType.InterpretAsTask(messageClass)) { _tracer.Trace("Task was moved"); if (Core.ResourceStore.FindUniqueResource(STR.Task, PROP.EntryID, realID) != null) { TaskDescriptor.Do(JobPriority.AboveNormal, folderDescriptor, message, realID); } else { RefreshTaskFolder(folderDescriptor); FolderDescriptor oldFolderDescriptor = FolderDescriptor.Get(ntf.OldParentID, _storeID); if (oldFolderDescriptor != null) { RefreshTaskFolder(oldFolderDescriptor); } } } else { _tracer.Trace("Unknown item of class " + messageClass + " was moved"); } } } catch (System.Threading.ThreadAbortException ex) { Tracer._TraceException(ex); } catch (Exception exception) { Core.ReportBackgroundException(exception); } }
public static string GetMessageID(IEMessage message) { return(message.GetBinProp(MAPIConst.PR_ENTRYID)); }
public void RemoveDeletedMailsFromIndex() { try { int count = 0; MailInIndexEnum mailEnum = _mailsInOldIndex.GetEnumerator(); int total = mailEnum.Count; // _tracer.Trace( "Start RemoveDeletedMailsFromIndex" ); // _tracer.Trace( "RemoveDeletedMailsFromIndex : mail to remove " + total.ToString() ); int curTickCount = Environment.TickCount; for (int i = 0; i < total; i++) { OutlookSession.ProcessJobs(); if (OutlookSession.OutlookProcessor.ShuttingDown) { break; } if (_idle && Settings.IdleModeManager.CheckInterruptIdle()) { break; } int percentage = (total == 0) ? 100 : ++count * 100 / total; if (percentage > 100) { percentage = 100; } if (Environment.TickCount - curTickCount > 500) { string statusText = "Synchronizing mails(" + count + "/" + total + ")..."; Settings.UpdateProgress(percentage, statusText, string.Empty); curTickCount = Environment.TickCount; } IResource resMail = mailEnum.GetResource(i); if (resMail == null || !Guard.IsResourceLive(resMail)) { // _tracer.Trace( "RemoveDeletedMailsFromIndex : resMail == null" ); continue; } PairIDs messageIDs = PairIDs.Get(resMail); if (messageIDs == null) { if (!resMail.HasProp(PROP.EmbeddedMessage)) { new ResourceProxy(resMail).DeleteAsync(); } continue; } string storeID = messageIDs.StoreId; string folderID = null; IEMessage mapiMessage = OutlookSession.OpenMessage(messageIDs.EntryId, storeID); if (mapiMessage != null) { using ( mapiMessage ) { folderID = mapiMessage.GetBinProp(MAPIConst.PR_PARENT_ENTRYID); } } FolderDescriptor folder = null; if (folderID != null) { folder = FolderDescriptor.Get(folderID, storeID); } MailSyncToFolder.LinkOrDelete(folder, resMail); OutlookSession.ProcessJobs(); } } finally { _mailsInOldIndex.Clear(); } OutlookSession.ProcessJobs(); }
private void FindResourceToDelete(IEFolder parentFolder, IResource parentMAPIFolder, string storeId) { // NOTE: In Cached Exchange mode (at least), messages can be opened successfully // immediately after they are permanently deleted, but opening them through // the short-term entry ID that we got in the notification still does not work. // Thus, if the message was permanently deleted in Outlook, the code below will // not find the deleted message, and we will have to rely on background enumeration // to delete it. // When the message is permanently deleted in OmniaMea, we immediately delete // the resource as well. IResourceList children = parentMAPIFolder.GetLinksOfType(null, PROP.MAPIFolder); foreach (IResource child in children.ValidResources) { if (child.HasProp(PROP.EntryID)) { IEMessage deletedItem = OutlookSession.OpenMessage(child.GetStringProp(PROP.EntryID), storeId); if (deletedItem != null) { // Item exists in the folder, the object is not needed anymore deletedItem.Dispose(); } else { Trace.WriteLine("Failed to open resource with ID=" + child.Id + ", queueing for delete"); _resourceToDelete = child; break; } } } if (_resourceToDelete == null) { HashSet set = new HashSet(children.Count); Tracer._Trace("Cannot find deleted mail."); Tracer._Trace("Try another algorithm."); foreach (IResource child in children.ValidResources) { if (!child.HasProp(PROP.EntryID)) { continue; } set.Add(child.GetStringProp(PROP.EntryID)); } IEMessages messages = parentFolder.GetMessages(); if (messages != null) { using ( messages ) { for (int i = 0; i < messages.GetCount(); i++) { IEMessage message = messages.OpenMessage(i); if (message != null) { using ( message ) { string entryid = message.GetBinProp(MAPIConst.PR_ENTRYID); if (entryid != null) { set.Remove(entryid); } } } } } } if (set.Count > 0) { foreach (HashSet.Entry entry in set) { FindResourcesByEntryId((string)entry.Key); if (_resourceToDelete != null) { Tracer._Trace("Resource found for deleting."); break; } } } } }