Exemplo n.º 1
0
        public static string Ask(string question, string proposed_answer, string txtOk, string txtCancel, string error)
        {
            SingleQuestionForm sqf = new SingleQuestionForm();

            sqf.SetQuestion(question);
            sqf.PresetAnswer(proposed_answer);
            sqf.SetOkButtonText(txtOk);
            sqf.SetCancelButtonText(txtCancel);
            sqf.SetError(error);
            return(sqf.Ask());
        }
Exemplo n.º 2
0
        public string ArchiveItem(Outlook.MailItem item, string dir, string newname)
        {
            string archived      = "erreur";
            string shortFilename = String.Format("{0:yyyy-MM-dd_HHmmss}", item.ReceivedTime) + "-";

            if (Config.GetInstance().GetOption("ADD_CATEGORIES_IN_FILENAME") == "TRUE")
            {
                if (item.Categories != null)
                {
                    shortFilename += item.Categories.Replace(';', '-') + "-";
                }
            }
            if (newname != null)
            {
                shortFilename += CleanFileName(newname);
            }
            else
            {
                shortFilename += CleanFileName(item.Subject);
            }
            string filename = Path.Combine(dir, shortFilename + ".msg");

            // si extraction dans dossier séparé, on redéfini le filename
            if (extractAttachments)
            {
                dir      = Path.Combine(dir, shortFilename);
                filename = Path.Combine(dir, shortFilename + ".msg");
            }

            // si on fleurte avec les limites, on ne sauve pas
            if (dir.Length > 230)
            {
                return(Localisation.getInstance().getString(
                           parent.culture.TwoLetterISOLanguageName,
                           "PATH_TOO_LONG"
                           ));
            }

            // si on fleurte avec les limites, on ne sauve pas
            if (filename.Length > 250)
            {
                if (truncatePathTooLong)
                {
                    filename = filename.Substring(0, 250) + ".msg";
                }
                else if (askPathTooLong)
                {
                    do
                    {
                        string error = Localisation.getInstance().getString(
                            parent.culture.TwoLetterISOLanguageName,
                            "FULL_PATH_TOO_LONG"
                            );

                        shortFilename = SingleQuestionForm.Ask(
                            Localisation.getInstance().getString(
                                parent.culture.TwoLetterISOLanguageName,
                                "QUESTION_FULL_PATH_TOO_LONG"
                                ),
                            shortFilename,
                            null,
                            null,
                            error);

                        filename = Path.Combine(dir, shortFilename + ".msg");
                    } while (filename.Length > 254 || File.Exists(filename));
                }
                else
                {
                    return(Localisation.getInstance().getString(
                               parent.culture.TwoLetterISOLanguageName,
                               "FULL_PATH_TOO_LONG"
                               ));
                }
            }

            // si fichier déjà existant, on ne sauve pas
            if (File.Exists(filename))
            {
                return(Localisation.getInstance().getString(
                           parent.culture.TwoLetterISOLanguageName,
                           "FILE_ALREADY_EXISTS"
                           ));
            }

            // si extraction des attachements, on est OK sur longueur et not exists, on tente de créer le répertoire
            if (extractAttachments)
            {
                Directory.CreateDirectory(dir);
            }

            // on tente de sauver
            try
            {
                item.SaveAs(filename, Outlook.OlSaveAsType.olMSGUnicode);

                // si extration des attachements, on extract
                if (extractAttachments)
                {
                    foreach (Outlook.Attachment att in item.Attachments)
                    {
                        att.SaveAsFile(Path.Combine(dir, att.FileName));
                    }
                }
                archived = "Ok";
            }
            catch (Exception e)
            {
                archived = e.Message;
            }

            return(archived);
        }