Ejemplo n.º 1
0
        /// <summary>
        /// This method moves emails according to the parameters
        /// </summary>
        /// <param name="operation">argument for MaiMove</param>
        /// <returns>true if processed successfully, false otherwise</returns>
        private bool MailMove(MailSimOperationsMailMove operation)
        {
            // gets the Outlook destination folder
            IMailFolder destinationFolder = olMailStore.GetDefaultFolder(operation.DestinationFolder);

            if (destinationFolder == null)
            {
                Log.Out(Log.Severity.Error, operation.OperationName, "Unable to retrieve folder {0}",
                        operation.DestinationFolder);
                return(false);
            }

            var parsedOp = ParseOperation(operation, operation.SourceFolder, operation.Subject);

            return(parsedOp.Iterate((indexToMove, mails) =>
            {
                var item = mails[indexToMove];
                Log.Out(Log.Severity.Info, operation.OperationName, "Moving to {0}: {1}",
                        operation.DestinationFolder, item.Subject);

                item.Move(destinationFolder);
                mails.RemoveAt(indexToMove);
                return true;
            }));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This method moves emails according to the parameters
        /// </summary>
        /// <param name="operation">argument for MaiMove</param>
        /// <returns>true if processed successfully, false otherwise</returns>
        private bool MailMove(MailSimOperationsMailMove operation)
        {
            // gets the Outlook destination folder
            IMailFolder destinationFolder = olMailStore.GetDefaultFolder(operation.DestinationFolder);
            if (destinationFolder == null)
            {
                Log.Out(Log.Severity.Error, operation.OperationName, "Unable to retrieve folder {0}",
                    operation.DestinationFolder);
                return false;
            }

            var parsedOp = ParseOperation(operation, operation.SourceFolder, operation.Subject);

            return parsedOp.Iterate((indexToMove, mails) =>
            {
                var item = mails[indexToMove];
                Log.Out(Log.Severity.Info, operation.OperationName, "Moving to {0}: {1}",
                    operation.DestinationFolder,item.Subject);

                item.Move(destinationFolder);
                mails.RemoveAt(indexToMove);
                return true;
            });
        }
        /// <summary>
        /// This method moves emails according to the parameters
        /// </summary>
        /// <param name="operation">argument for MaiMove</param>
        /// <returns>true if processed successfully, false otherwise</returns>
        private bool MailMove(MailSimOperationsMailMove operation)
        {
            int iterations = GetIterationCount(operation.Count);
            bool random = false;

            try
            {
                // retrieves mails from Outlook
                var mails = GetMails(operation.OperationName, operation.SourceFolder, operation.Subject).ToList();
                if (mails.Any() == false)
                {
                    Log.Out(Log.Severity.Error, operation.OperationName, "Skipping MailMove");
                    return false;
                }

                // randomly generates the number of emails to forward
                if (iterations == 0)
                {
                    random = true;
                    iterations = randomNum.Next(1, mails.Count + 1);
                    Log.Out(Log.Severity.Info, operation.OperationName, "Randomly moving {0} emails", iterations);
                }

                // we need to make sure we are not moving more than what we have in the mailbox
                if (iterations > mails.Count)
                {
                    Log.Out(Log.Severity.Warning, operation.OperationName,
                        "Only {1} email(s) are in the folder, so the number of emails to move is adjusted from {0} to {1}",
                        iterations, mails.Count);
                    iterations = mails.Count;
                }

                // gets the Outlook destination folder
                IMailFolder destinationFolder = olMailStore.GetDefaultFolder(operation.DestinationFolder);
                if (destinationFolder == null)
                {
                    Log.Out(Log.Severity.Error, operation.OperationName, "Unable to retrieve folder {0}",
                        operation.DestinationFolder);
                    return false;
                }

                for (int count = 1; count <= iterations; count++)
                {
                    Log.Out(Log.Severity.Info, operation.OperationName, "Starting iteration {0}", count);

                    // just move the email in order if random is not selected,
                    // otherwise randomly pick the mail to move
                    int indexToCopy = random ? randomNum.Next(0, mails.Count) : mails.Count - 1;
                    Log.Out(Log.Severity.Info, operation.OperationName, "Moving to {0}: {1}",
                        operation.DestinationFolder, mails[indexToCopy].Subject);

                    mails[indexToCopy].Move(destinationFolder);
                    mails.RemoveAt(indexToCopy);

                    SleepOrStop(operation.OperationName, operation.Sleep);

                    Log.Out(Log.Severity.Info, operation.OperationName, "Finished iteration {0}", count);
                }
            }
            catch (Exception ex)
            {
                Log.Out(Log.Severity.Error, operation.OperationName, "Exception encountered\n" + ex);
                return false;
            }
            return true;
        }