Beispiel #1
0
 /// <summary>
 /// Moves Mail item into new folder
 /// </summary>
 /// <param name="newFolder" - Folder object representing Folder to move to></param>
 public void Move(MailFolder newFolder)
 {
     _mailitem = _mailitem.Move(newFolder.OutlookFolderItem);
 }
        /// <summary>
        /// Handle the email
        /// </summary>
        /// <param name="entryIdItem">The email we want to handle.</param>
        /// <returns></returns>
        private async Task <bool> HandleItemFlagedAsBeingProcessedInLock(string entryIdItem)
        {
            Outlook._MailItem mailItem = null;
            try
            {
                // new email has arrived, we need to try and classify it.
                mailItem = _session.GetItemFromID(entryIdItem, System.Reflection.Missing.Value) as Outlook._MailItem;
            }
            catch (Exception e)
            {
                _engine.Logger.LogException(e);
            }

            if (mailItem == null)
            {
                _engine.Logger.LogWarning($"Could not locate mail item {entryIdItem} to move.");
                return(false);
            }

            // did we send this email?
            if (MailWasSentByUs(mailItem))
            {
                _engine.Logger.LogWarning($"Mail item {entryIdItem} was sent by us and will not be classified.");
                return(false);
            }

            // either way, this is a valid 'processed' email
            UpdateLastProcessedEmailInLock(mailItem);

            // the message note.
            if (!IsUsableClassNameForClassification(mailItem.MessageClass))
            {
                return(false);
            }

            // start the watch
            var watch = StopWatch.Start(_engine.Logger);

            // look for the category
            var guessCategoryResponse = await CategorizeAsync(mailItem).ConfigureAwait(false);

            //
            var categoryId    = guessCategoryResponse.CategoryId;
            var wasMagnetUsed = guessCategoryResponse.WasMagnetUsed;

            // did we find a category?
            if (-1 == categoryId)
            {
                _engine.Logger.LogVerbose($"I could not classify the new message {entryIdItem} into any categories. ('{mailItem.Subject}')");
                watch.Checkpoint("I could not classify the new message into any categories: (in: {0})");
                return(false);
            }

            //
            watch.Checkpoint($"I classified the new message category : {categoryId} (in: {{0}})");

            //
            // Do we want to train this
            var options = _engine.Options;

            if (options.ReAutomaticallyTrainMessages || (wasMagnetUsed && options.ReAutomaticallyTrainMagnetMessages))
            {
                // get the weight
                var weight = (wasMagnetUsed ? options.MagnetsWeight : 1);

                // we can now classify it.
                await ClassifyAsync(mailItem, (uint)categoryId, weight).ConfigureAwait(false);
            }

            try
            {
                // get the posible folder.
                var folderId = _engine.Categories.FindFolderIdByCategoryId(categoryId);
                if (string.IsNullOrEmpty(folderId))
                {
                    _engine.Logger.LogWarning($"Could not locate folder id for category {categoryId}, cannot move item.");

                    //  the user does not want to move to another folder.
                    return(false);
                }

                var folder = _engine.Folders.FindFolderById(folderId);
                if (null == folder)
                {
                    //
                    _engine.Logger.LogWarning($"Could not locate folder for category {categoryId}, cannot move item.");

                    //  the user does not want to move to another folder.
                    return(false);
                }

                // don't move it if we don't need to.
                var currentFolder = (Outlook.MAPIFolder)mailItem.Parent;

                // if they are not the same, we can move it.
                if (currentFolder.EntryID == folder.Id())
                {
                    _engine.Logger.LogVerbose($"No need to move mail, '{mailItem.Subject}', to folder, '{folder.Name()}', already in folder");
                    return(true);
                }

                // if this is an ignored conversation, we will not move it.
                if (IsIgnoredConversation(mailItem))
                {
                    _engine.Logger.LogVerbose($"Mail, '{mailItem.Subject}' is part of an ignored conversation and will not be moved.");
                    return(true);
                }

                // this is where we want to move to.
                var itemToFolder = (folder as OutlookFolder)?.Folder;
                if (null == itemToFolder)
                {
                    throw new Exception($"The folder {folder.Name()} does not seem to be of type 'Folder' and cannot be used.");
                }

                // try and move
                mailItem.Move(itemToFolder);

                // and log it.
                _engine.Logger.LogVerbose($"Moved mail, '{mailItem.Subject}', to folder, '{folder.Name()}'");
            }
            catch (Exception ex)
            {
                _engine.Logger.LogException(ex);
                return(false);
            }
            return(true);
        }
Beispiel #3
0
        public void Move(IMailFolder newFolder)
        {
            var provider = newFolder as MailFolderProviderOM;

            _mailItem = _mailItem.Move(provider.Handle);
        }