Beispiel #1
0
        private bool WereChanges(IERowSet row, IResource email, out bool checkForDateTimeNeeded)
        {
            checkForDateTimeNeeded = false;
            DateTime lastModifiedDate = row.GetDateTimeProp(2);

            if (lastModifiedDate != DateTime.MinValue)
            {
                lastModifiedDate = lastModifiedDate.ToUniversalTime();
            }
            else
            {
                checkForDateTimeNeeded = true;
            }
            bool bWereChanges = lastModifiedDate.CompareTo(email.GetProp(PROP.LastModifiedTime)) != 0;

            if (!bWereChanges)
            {
                long mesFlags = row.GetLongProp(4);
                bool unread   = (mesFlags & 1) == 0;
                if (unread != email.HasProp(Core.Props.IsUnread))
                {
                    bWereChanges = true;
                }
            }
            return(bWereChanges);
        }
Beispiel #2
0
        private string ProcessRow(IERowSet row, FolderDescriptor folder,
                                  IEFolder mapiFolder, ref int indexed)
        {
            string entryID = row.GetBinProp(1);

            if (entryID == null)
            {
                entryID = row.GetBinProp(0);
            }
            string messageClass = row.GetStringProp(3);

            if (messageClass == null)
            {
                messageClass = string.Empty;
            }

            IResource email =
                Core.ResourceStore.FindUniqueResource(STR.Email, PROP.EntryID, entryID);

            if (email != null)
            {
                _mailsInOldIndex.TestID(email.Id);
                UpdateMail(row, email, messageClass, entryID, folder, mapiFolder);
                indexed++;
            }
            else
            {
                AddMail(messageClass, entryID, folder, mapiFolder, row.GetStringProp(7));
                indexed++;
            }
            OutlookSession.ProcessJobs();
            return(entryID);
        }
Beispiel #3
0
        public ContactDescriptor(IERowSet rowSet, int rowNum, string entryID, OutlookAddressBook addressBook)
        {
            _entryID       = entryID;
            _searchEntryID = _entryID;
            _addressBook   = addressBook;

            _emailAddresses = GetEmailAddresses( );
            if (_emailAddresses == null || _emailAddresses.Count == 0)
            {
                _contactNames.EmailAddress = rowSet.GetStringProp(2, rowNum);  //row.FindStringProp( MAPIConst.PR_EMAIL_ADDRESS );
            }
            else
            {
                _contactNames.EmailAddress = _emailAddresses[0] as string;
            }

            string fullName = rowSet.GetStringProp(1, rowNum);  //row.FindStringProp( MAPIConst.PR_DISPLAY_NAME );

            if (fullName != null)
            {
                fullName = fullName.Trim();
            }
            _contactNames.FullName = fullName;
            //_phones = contactProperties.GetPhones();
            //_birthday = contactProperties.BirthDay;
        }
Beispiel #4
0
        private static int GetAttachNum(IEMessage message, int index)
        {
            IETable table = message.GetAttachments();

            if (table == null)
            {
                return(0);
            }
            using ( table )
            {
                int count = table.GetRowCount();
                for (int i = 0; i < count; i++)
                {
                    IERowSet row = table.GetNextRow();
                    if (row != null)
                    {
                        using ( row )
                        {
                            if (index == i)
                            {
                                return(row.FindLongProp(MAPIConst.PR_ATTACH_NUM));
                            }
                        }
                    }
                    if (index < i)
                    {
                        break;
                    }
                }
            }
            return(0);
        }
Beispiel #5
0
            private void ProcessRow(IERowSet row, IEFolder mapiFolder)
            {
                mapiFolder = mapiFolder;
                string entryID = row.GetBinProp(1);

                if (entryID == null)
                {
                    entryID = row.GetBinProp(0);
                }
                string messageClass = row.GetStringProp(3);

                messageClass = messageClass;
            }
Beispiel #6
0
        private void ProcessGlobalAddressBook(IEABContainer abContainer)
        {
            IERowSet rowSet = abContainer.GetRowSet();

            if (rowSet == null)
            {
                return;
            }
            using ( rowSet )
            {
                string    entryID   = abContainer.GetBinProp(MAPIConst.PR_ENTRYID);
                IResource outlookAB = Core.ResourceStore.FindUniqueResource(STR.OutlookABDescriptor, PROP.EntryID, entryID);
                if (outlookAB == null)
                {
                    return;
                }
                if (!Folder.IsIgnoreImport(outlookAB))
                {
                    string             curName = abContainer.GetStringProp(MAPIConst.PR_DISPLAY_NAME);
                    string             abName  = OutlookAddressBook.GetProposedName(curName, entryID);
                    OutlookAddressBook AB      = new OutlookAddressBook(abName, entryID, false);
                    AB.RunAB();
                    int count = rowSet.GetRowCount();
                    for (int i = 0; i < count; i++)
                    {
                        if (ShuttingDown)
                        {
                            return;
                        }
                        OutlookSession.ProcessJobs();

                        string ABentryID = rowSet.GetBinProp(0, i /*MAPIConst.PR_ENTRYID*/);
                        if (ABentryID == null)
                        {
                            continue;
                        }
                        Core.ResourceAP.QueueJob(new ContactDescriptor(rowSet, i, ABentryID, AB));
                    }
                }
                else
                {
                    IResource AB = Core.ResourceStore.FindUniqueResource(STR.AddressBook, PROP.EntryID, entryID);
                    if (AB != null)
                    {
                        new ResourceProxy(AB).DeleteAsync();
                    }
                }
            }
        }
Beispiel #7
0
        private void UpdateMail(IERowSet row, IResource email, string messageClass, string entryId,
                                FolderDescriptor folder, IEFolder mapiFolder)
        {
            Guard.NullArgument(messageClass, "messageClass");

            bool checkForDateTimeNeeded = false;
            bool bWereChanges           = false;
            bool interpretAsMail        = MessageType.InterpretAsMail(messageClass);

            if (interpretAsMail)
            {
                bWereChanges = WereChanges(row, email, out checkForDateTimeNeeded);
            }

            if (bWereChanges)
            {
                IEMessage message = OutlookSession.OpenMessage(folder.FolderIDs.EntryId, mapiFolder, entryId);
                if (message == null)
                {
                    return;
                }

                using ( message )
                {
                    if (checkForDateTimeNeeded)
                    {
                        DateTime lastModifiedDate = message.GetDateTimeProp(MAPIConst.PR_LAST_MODIFICATION_TIME);
                        lastModifiedDate = lastModifiedDate.ToUniversalTime();
                        if (lastModifiedDate.Equals(email.GetProp(PROP.LastModifiedTime)))
                        {
                            bWereChanges = false;
                        }
                    }
                    if (bWereChanges)
                    {
                        Core.ResourceAP.QueueJob(new MailDescriptor(folder, entryId, message, MailDescriptor.UpdateState, row.GetStringProp(7)));
                    }
                    else
                    {
                        Core.ResourceAP.QueueJob(new SyncOnlyMailDescriptor(folder, entryId, message));
                    }
                }
            }
            else
            {
                MailSyncToFolder.LinkOrDelete(folder, email);
            }
        }
Beispiel #8
0
        public static bool ProcessIMAPMessage(IEFolder folder, string entryID)
        {
            Tracer._Trace("ProcessIMAPMessage");
            IETable table = folder.GetEnumTable(DateTime.MinValue);

            if (table == null)
            {
                return(false);
            }
            using ( table )
            {
                int count = table.GetRowCount();
                if (count > 0)
                {
                    table.Sort(MAPIConst.PR_MESSAGE_DELIVERY_TIME, false);
                }
                for (uint i = 0; i < count; i++)
                {
                    IERowSet row = table.GetNextRow();
                    if (row == null)
                    {
                        continue;
                    }
                    using ( row )
                    {
                        if (row.GetBinProp(0) == entryID)
                        {
                            if (row.GetLongProp(6) == 1)
                            {
                                Tracer._Trace("ProcessIMAPMessage FALSE");
                                //folder.SetMessageStatus( entryID, 0x1000, 0x1000 );
                                return(false);
                            }
                            else
                            {
                                Tracer._Trace("ProcessIMAPMessage TRUE");
                                return(true);
                            }
                        }
                    }
                }
            }
            return(false);
        }
Beispiel #9
0
        private void PrepareRecipients(IEMessage message)
        {
            IETable recips = message.GetRecipients();

            if (recips != null)
            {
                using ( recips )
                {
                    long count = recips.GetRowCount();
                    for (long i = 0; i < count; i++)
                    {
                        IERowSet rowSet = recips.GetNextRow();
                        if (rowSet != null)
                        {
                            using ( rowSet )
                            {
                                string emailAddr = rowSet.FindStringProp(MAPIConst.PR_SMTP_ADDRESS);
                                if (emailAddr == null || emailAddr.Length == 0)
                                {
                                    emailAddr = rowSet.FindStringProp(MAPIConst.PR_EMAIL_ADDRESS);
                                }
                                if (emailAddr != null && emailAddr.Length > 0)
                                {
                                    string displayName = rowSet.FindStringProp(MAPIConst.PR_DISPLAY_NAME);

                                    bool isTo   = (rowSet.FindLongProp(MAPIConst.PR_RECIPIENT_TYPE) == (int)RecipientType.To);
                                    bool mySelf = OwnerEmailDetector.IsOwnerEmail(emailAddr);

                                    if (mySelf)
                                    {
                                        _bSentToMe = true;
                                    }
                                    _recipients.Add(new RecipientHelper(emailAddr, displayName, isTo, mySelf));
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #10
0
        private static void ProcessRow(ArrayList ownerEmails, ArrayList ownerNames, IETable table)
        {
            IERowSet row = table.GetNextRow();

            if (row == null)
            {
                return;
            }
            using ( row )
            {
                string senderEmail = row.GetStringProp(0);
                string senderName  = row.GetStringProp(1);
                if (senderEmail != null && senderEmail.Length > 0 && ownerEmails.IndexOf(senderEmail) == -1)
                {
                    ownerEmails.Add(senderEmail);
                }
                if (senderName != null && senderName.Length > 0 && ownerNames.IndexOf(senderName) == -1)
                {
                    ownerNames.Add(senderName);
                }
            }
        }
Beispiel #11
0
            void EnumerateMail(IEFolder mapiFolder)
            {
                IETable table = null;

                try
                {
                    table = mapiFolder.GetEnumTable(DateTime.Now.AddDays(-3));
                }
                catch (System.UnauthorizedAccessException) {}
                if (table == null)
                {
                    return;
                }
                using ( table )
                {
                    int count = table.GetRowCount();
                    if (count > 0)
                    {
                        table.Sort(MAPIConst.PR_MESSAGE_DELIVERY_TIME, false);
                    }
                    for (uint i = 0; i < count; i++)
                    {
                        IERowSet row = table.GetNextRow();
                        if (row == null)
                        {
                            continue;
                        }
                        using ( row )
                        {
                            for (int j = 0; j < 1; ++j)
                            {
                                ProcessRow(row, mapiFolder);
                            }
                        }
                    }
                }
            }
Beispiel #12
0
        /**
         * Creates resources for the attachments of the specified e-mail
         * and adds them as links to the specified e-mail resource.
         */
        private void PrepareAttachments(IEMessage message)
        {
            // NOTE: IEMessage.GetAttachments() restricts the attachment table to a specific
            // set of columns, so if you need to process more columns here, don't forget to
            // modify the code in GetAttachments().
            IETable attaches = message.GetAttachments();

            if (attaches != null)
            {
                using ( attaches )
                {
                    long count = attaches.GetRowCount();
                    for (long i = 0; i < count; i++)
                    {
                        IERowSet rowSet = attaches.GetNextRow();
                        if (rowSet == null)
                        {
                            continue;
                        }
                        using ( rowSet )
                        {
                            int size         = rowSet.FindLongProp(MAPIConst.PR_ATTACH_SIZE);
                            int attachMethod = rowSet.FindLongProp(MAPIConst.PR_ATTACH_METHOD);

                            string strFileName = rowSet.FindStringProp(MAPIConst.PR_ATTACH_LONG_FILENAME);
                            if (strFileName == null)
                            {
                                strFileName = rowSet.FindStringProp(MAPIConst.PR_ATTACH_FILENAME);
                            }
                            if (strFileName == null)
                            {
                                strFileName = rowSet.FindStringProp(MAPIConst.PR_DISPLAY_NAME);
                            }
                            if (strFileName != null)
                            {
                                string strFileType = string.Empty;
                                int    dotIndex    = strFileName.LastIndexOf(".");
                                if (dotIndex != -1)
                                {
                                    strFileType = strFileName.Substring(dotIndex).ToUpper();
                                }
                                int      num          = rowSet.FindLongProp(MAPIConst.PR_ATTACH_NUM);
                                string   strContentID = null;
                                IEAttach attachment   = message.OpenAttach(num);
                                if (attachment != null)
                                {
                                    using ( attachment )
                                    {
                                        strContentID = attachment.GetStringProp(MAPIConst.PR_ATTACH_CONTENT_ID);
                                    }
                                }

                                AttachmentHelper attach =
                                    new AttachmentHelper(strFileName, strFileType, (int)i, size, attachMethod, strContentID, num);
                                _attachments.Add(attach);
                            }
                        }
                    }
                }
            }
        }
Beispiel #13
0
        private void EnumerateMail(FolderDescriptor folder, IEFolder mapiFolder)
        {
            try
            {
                OnFolderFetched(folder.Name);
                int indexed = 0;

                IResource resFolder  = Folder.Find(folder.FolderIDs.EntryId);
                DateTime  dtRestrict = GetRestrictDate(resFolder);

                IETable table = null;
                try
                {
                    table = mapiFolder.GetEnumTable(dtRestrict);
                }
                catch (System.UnauthorizedAccessException exception)
                {
                    _tracer.TraceException(exception);
                }
                catch (OutOfMemoryException exception)
                {
                    _tracer.TraceException(exception);
                }
                if (table == null)
                {
                    return;
                }
                using ( table )
                {
                    int count = table.GetRowCount();
                    if (count > 0)
                    {
                        table.Sort(MAPIConst.PR_MESSAGE_DELIVERY_TIME, false);
                    }
                    for (uint i = 0; i < count; i++)
                    {
                        if (OutlookSession.OutlookProcessor.ShuttingDown)
                        {
                            break;
                        }
                        if (_idle && Settings.IdleModeManager.CheckInterruptIdle())
                        {
                            break;
                        }
                        IERowSet row = row = table.GetNextRow();
                        if (row == null)
                        {
                            continue;
                        }
                        using ( row )
                        {
                            if (row.GetLongProp(6) != 1)
                            {
                                ProcessRow(row, folder, mapiFolder, ref indexed);
                            }
                        }
                    }
                }
                if (Settings.IdleModeManager.CompletedIdle)
                {
                    Folder.SetSeeAllAsync(resFolder);
                }

                _tracer.Trace("Indexed " + indexed + " messages in folder " + folder.Name);
            }
            finally
            {
                OutlookSession.ProcessJobs();
            }
        }