private void OnSave(object sender, EventArgs e) { HandleProgressBar(true); if (!ComponentsFilled()) { HandleProgressBar(false); MessageBox.Show(Properties.Resources.config_empty, Properties.Resources.application_title); return; } _configManager.SetUsername(textbox_username.Text); _configManager.SetBaseURL(combobox_server_prefix.SelectedItem.ToString(), textbox_server.Text); _configManager.SetPassword(textbox_password.Text); string maxDownloads = textbox_maxDownloads.Text; string validity = textbox_validTill.Text; try { _configManager.SetDefaultDownloads(maxDownloads); } catch (FormatException) { MessageBox.Show("The maximum download count of a file link must be a number", Properties.Resources.application_title); return; } try { _configManager.SetDefaultDownloads(validity); } catch (FormatException) { MessageBox.Show("The validity of a file link must be a number", Properties.Resources.application_title); return; } _configManager.SetMinFileSize((trackbar_minFilesize.Value * 1024).ToString()); _configManager.SaveConfig(); PFApi apiCall = new PFApi(); if (!apiCall.TryToAuthenticate()) { HandleProgressBar(false); MessageBox.Show(Properties.Resources.http_unauthorized, Properties.Resources.application_title); return; } HandleProgressBar(false); this.Hide(); }
private void ItemSend_Thread(Dictionary<string, string> linkParams) { const string _methodname = "[ItemSend_Thread]"; if (OutlookInspector.CurrentItem is Outlook.MailItem) { try { Logger.LogThis(string.Format("{0} {1} [Saving E-Mail as Template]", _classname, _methodname), Logging.eloglevel.verbose); MailItem mail = OutlookInspector.CurrentItem as Outlook.MailItem; mail.Save(); mail.Close(OlInspectorClose.olDiscard); } catch (System.Exception e) { Logger.LogThisError(e); } } Logger.LogThis(string.Format("{0} {1} [Creating new E-Mail from Template]", _classname, _methodname), Logging.eloglevel.verbose); MailItem newEmail = OutlookApplication.CreateItemFromTemplate(currentFileName) as Outlook.MailItem; PFApi api = new PFApi(); PFResponse responseGetInfo = api.GetAccountInfo(); if (responseGetInfo == null) { MessageBox.Show("An error occured while sending the Email. Please check your logs for more informations.", Properties.Resources.application_title); newEmail.Display(); return; } if (!responseGetInfo.IsValidResponse(newEmail)) { MessageBox.Show("An error occured while sending the Email. Please check your logs for more informations.", Properties.Resources.application_title); newEmail.Display(); return; } if (responseGetInfo.Message == null) { MessageBox.Show("An error occured while sending the Email. Please check your logs for more informations.", Properties.Resources.application_title); newEmail.Display(); return; } JObject jsonResponse = JObject.Parse(responseGetInfo.Message); string accountID = jsonResponse.GetValue("ID").ToString(); const string folderName = "$mail_attachments"; string folderID = string.Format("MA-{0}", accountID); string folderIDBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(folderID)); string directoryName = CollectDetailsForSubject(newEmail); long spaceUsed = long.Parse(jsonResponse.GetValue("spaceUsed").ToString()); long spaceAllowed = long.Parse(jsonResponse.GetValue("spaceAllowed").ToString()); long attachmentsSize = 0; if (accountID.Contains("/")) { Logger.LogThis(string.Format("{0} {1} *ATTENTION* - The AccountID contains a '/'", _classname, _methodname), Logging.eloglevel.warn); } foreach (Attachment a in newEmail.Attachments) { attachmentsSize += a.Size; } try { if (attachmentsSize > (spaceAllowed - spaceUsed)) { if(MessageBox.Show(Properties.Resources.mail_quota_exceeded, Properties.Resources.application_title, MessageBoxButtons.YesNo) == DialogResult.Yes) { newMail = false; newEmail.Send(); return; } else { newEmail.Display(); return; } } } catch (System.Exception e) { Logger.LogThisError(e); return; } PFResponse responseFolderExists = api.FolderExists(folderID); if (responseFolderExists == null) { MessageBox.Show("An error occured while sending the E-Mail.\r\n" + "Please Check your logs for more information.", Properties.Resources.application_title); newEmail.Display(); return; } if (!responseFolderExists.IsValidResponse(newEmail)) { newEmail.Display(); return; } if (responseFolderExists.StatusCode == System.Net.HttpStatusCode.NotFound) { PFResponse responseCreateFolder = api.CreateFolder(folderID, folderName); if (responseCreateFolder == null) { MessageBox.Show("An error occured while sending the E-Mail.\r\n" + "Please Check your logs for more information.", Properties.Resources.application_title); newEmail.Display(); return; } if (!responseCreateFolder.IsValidResponse(newEmail)) { return; } } PFResponse responseDirectoryExists = api.DirectoryExists(folderIDBase64, directoryName); if (responseDirectoryExists == null) { MessageBox.Show("An error occured while sending the E-Mail.\r\n" + "Please Check your logs for more information.", Properties.Resources.application_title); newEmail.Display(); return; } if (!responseDirectoryExists.IsValidResponse(newEmail)) { return; } if (responseDirectoryExists.StatusCode == System.Net.HttpStatusCode.NotFound) { PFResponse responseCreateDirectory = api.CreateDirectory(folderIDBase64, directoryName); if (responseCreateDirectory == null) { MessageBox.Show("An error occured while sending the E-Mail.\r\n" + "Please Check your logs for more information.", Properties.Resources.application_title); newEmail.Display(); return; } if (!responseCreateDirectory.IsValidResponse(newEmail)) { return; } } else { folderIDBase64 = CollectDetailsForSubject(newEmail); PFResponse responseCreateDirectory = api.CreateDirectory(folderIDBase64, directoryName); if (responseCreateDirectory == null) { MessageBox.Show("An error occured while sending the E-Mail.\r\n" + "Please Check your logs for more information.", Properties.Resources.application_title); newEmail.Display(); return; } if (!responseCreateDirectory.IsValidResponse(newEmail)) { return; } } PFResponse uploadFilesResponse = api.UploadAttachments(folderIDBase64, directoryName, newEmail.Attachments); if (uploadFilesResponse == null) { MessageBox.Show("An error occured while sending the E-Mail.\r\n" + "Please Check your logs for more information.", Properties.Resources.application_title); newEmail.Display(); return; } if (!uploadFilesResponse.IsValidResponse(newEmail)) { return; } List<string> fileLinks = new List<string>(); while (newEmail.Attachments.Count != 0) { PFResponse responseStoreFileLink = api.StoreFileLink( folderIDBase64, directoryName, newEmail.Attachments[1], linkParams); if (responseStoreFileLink == null) { MessageBox.Show("An error occured while sending the E-Mail.\r\n" + "Please Check your logs for more information.", Properties.Resources.application_title); newEmail.Display(); return; } if (!responseStoreFileLink.IsValidResponse(newEmail)) { return; } PFResponse responseRecieveFileLink = api.GetFileLink( folderIDBase64, directoryName, newEmail.Attachments[1]); if (responseRecieveFileLink == null) { MessageBox.Show("An error occured while sending the E-Mail.\r\n" + "Please Check your logs for more information.", Properties.Resources.application_title); newEmail.Display(); return; } if (!responseRecieveFileLink.IsValidResponse(newEmail)) { return; } string currentFileLink = string.Empty; try { currentFileLink = JObject.Parse(responseRecieveFileLink.Message).GetValue("url").ToString(); } catch (ArgumentNullException e1) { Logger.LogThisError(e1); return; } if (string.IsNullOrEmpty(currentFileLink)) { Logger.LogThis(string.Format("{0} {1} [Error : 'Empty FileLink']", _classname, _methodname), Logging.eloglevel.error); MessageBox.Show("An error occured while sending the E-Mail.\r\n" + "Please Check your logs for more information.", Properties.Resources.application_title); newEmail.Display(); return; } if (currentFileLink.StartsWith("/")) { currentFileLink = Config.GetInstance().GetBaseUrl() + currentFileLink; } if (linkParams.ContainsKey(FileLinkContraints.PASSWORD)) { currentFileLink = currentFileLink.Replace("getlink", "dlpw"); } else { currentFileLink = currentFileLink.Replace("getlink", "dl"); } fileLinks.Add(currentFileLink); newEmail.Attachments[1].Delete(); } HtmlHandler htmlHandler = new HtmlHandler(fileLinks); if (htmlHandler.CreateTempFolder()) { Logger.LogThis(string.Format("{0} {1} [Created temp folder for html files]" , _classname, _methodname) , Logging.eloglevel.info); List<string> htmlPaths = htmlHandler.CreateHtmlFiles(newEmail.SenderEmailAddress, newEmail.To); if (!htmlHandler._innerError) { foreach (string s in htmlPaths) { newEmail.Attachments.Add(s, Outlook.OlAttachmentType.olByValue); } } else { Logger.LogThis(string.Format("{0} {1} [It was not possible to create the html files. Using file links instead]" , _classname, _methodname) , Logging.eloglevel.warn); string linkHeader = Environment.NewLine + "----------*Attachments*----------"; newEmail.Body += linkHeader; foreach (string s in fileLinks) { string current = s; current = Environment.NewLine + s; newEmail.Body += current; } newEmail.Body += linkHeader; } } else { Logger.LogThis(string.Format("{0} {1} [It was not possible to create the html files. Using file links instead]" , _classname, _methodname) , Logging.eloglevel.warn); string linkHeader = Environment.NewLine + "----------*Attachments*----------"; newEmail.Body += linkHeader; foreach (string s in fileLinks) { string current = s; current = Environment.NewLine + s; newEmail.Body += current; } newEmail.Body += linkHeader; } newEmail.Save(); newMail = false; Logger.LogThis(string.Format("{0} {1} [Successfuly edited E-Mail. Sending now...]", _classname, _methodname), Logging.eloglevel.info); newEmail.Send(); File.Delete(currentFileName); }