private ConfirmationModel PrepareConfirmationModel(TfsFacade tfs, MailMessage mail, int workItemId)
        {
            var model = new ConfirmationModel()
            {
                WorkItemType    = configuration.TFS.WorkItemType,
                WorkItemId      = workItemId,
                WorkItemUrl     = tfs.GetWorkItemUrl(workItemId),
                Requester       = mail.From.DisplayName,
                OriginalSubject = mail.Subject,
            };

            return(model);
        }
        public void Run()
        {
            string tempFolder = Path.Combine(Path.GetTempPath(), "Mail2WorkItem");

            Directory.CreateDirectory(tempFolder);

            try
            {
                var picker = new MailPicker(
                    this.logger,
                    configuration.Pop3.Hostname, configuration.Pop3.Port, configuration.Pop3.UseSsl,
                    configuration.Pop3.Username, configuration.Pop3.Password,
                    tempFolder);
                var messages = picker.ReadAll();

                if (messages.Count > 0)
                {
                    var tfs = new TfsFacade(
                        this.logger,
                        new Uri(configuration.TFS.CollectionUrl), configuration.TFS.ProjectName,
                        configuration.TFS.WorkItemType);
                    foreach (var mail in messages)
                    {
                        int workItemId = tfs.AddWorkItem(mail);
                        var model      = PrepareConfirmationModel(tfs, mail, workItemId);
                        SendConfirmation(mail.From, model);
                    } //for
                }     //if
            }
            catch (Exception e)
            {
                logger.UnexpectedError(e);
            }
            finally
            {
                logger.RemovingTemporaryFolder(tempFolder);
                Directory.Delete(tempFolder, true);
            }//try
        }