Пример #1
0
        /// <summary>
        /// This method deletes mail according to the parameter
        /// </summary>
        /// <param name="operation">parameters for MailDelete</param>
        /// <returns>true if processed successfully, false otherwise</returns>
        private bool MailDelete(MailSimOperationsMailDelete operation)
        {
            var parsedOp = ParseOperation(operation, operation.Folder, operation.Subject);

            return(parsedOp.Iterate((indexToDelete, mails) =>
            {
                var item = mails[indexToDelete];
                Log.Out(Log.Severity.Info, operation.OperationName, "Deleting email with subject: {0}", item.Subject);

                item.Delete();
                mails.RemoveAt(indexToDelete);
                return true;
            }));
        }
Пример #2
0
        /// <summary>
        /// This method deletes mail according to the parameter 
        /// </summary>
        /// <param name="operation">parameters for MailDelete</param>
        /// <returns>true if processed successfully, false otherwise</returns>
        private bool MailDelete(MailSimOperationsMailDelete operation)
        {
            var parsedOp = ParseOperation(operation, operation.Folder, operation.Subject);

            return parsedOp.Iterate((indexToDelete, mails) =>
            {
                var item = mails[indexToDelete];
                Log.Out(Log.Severity.Info, operation.OperationName, "Deleting email with subject: \"{0}\"", item.Subject);

                item.Delete();
                mails.RemoveAt(indexToDelete);
                return true;
            });
        }
        /// <summary>
        /// This method deletes mail according to the parameter 
        /// </summary>
        /// <param name="operation">parameters for MailDelete</param>
        /// <returns>true if processed successfully, false otherwise</returns>
        private bool MailDelete(MailSimOperationsMailDelete operation)
        {
            int iterations = GetIterationCount(operation.Count);
            bool random = false;

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

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

                // we need to make sure we are not deleting 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 delete is adjusted from {0} to {1}",
                        iterations, mails.Count);
                    iterations = mails.Count;
                }

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

                    // just delete the email in order if random is not selected,
                    // otherwise randomly pick the mail to delete
                    int indexToDelete = random ? randomNum.Next(0, mails.Count) : mails.Count - 1;

                    Log.Out(Log.Severity.Info, operation.OperationName, "Deleting email with subject: {0}", mails[indexToDelete].Subject);
                    mails[indexToDelete].Delete();
                    mails.RemoveAt(indexToDelete);

                    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;
        }