private static void ExtractPropertiesInFolder(XstFile xstFile, XstReader.Folder folder, string exportDirectory) { var fileName = Path.Combine(exportDirectory, RemoveInvalidChars(folder.Name)) + ".csv"; Console.WriteLine("Exporting " + fileName); xstFile.ReadMessages(folder); xstFile.ExportMessageProperties(folder.Messages, fileName); }
private static void ExtractAttachmentsInFolder(XstFile xstFile, XstReader.Folder folder, string exportDirectory) { int good = 0, bad = 0; xstFile.ReadMessages(folder); foreach (var message in folder.Messages) { try { xstFile.ReadMessageDetails(message); foreach (var att in message.Attachments) { if (att.IsFile) { var attachmentExpectedName = Path.Combine(exportDirectory, att.FileName); var fi = new FileInfo(attachmentExpectedName); var actionName = string.Empty; if (!fi.Exists) { actionName = "Create"; } else { if (fi.CreationTime < message.Received) { actionName = "CreateNewer"; } else { actionName = "Skip"; } } Console.WriteLine($"{actionName} : {attachmentExpectedName}"); switch (actionName) { case "Create": case "CreateNewer": xstFile.SaveAttachment(attachmentExpectedName, message.Received, att); break; default: break; } } } good++; } catch (System.Exception ex) { Console.WriteLine(String.Format("Error '{0}' exporting email '{1}'", ex.Message, message.Subject)); bad++; } } Console.WriteLine($"Folder '{folder.Name}' completed with {good} successes and {bad} failures"); }
private static void ExtractEmailsInFolder(XstFile xstFile, XstReader.Folder folder, string exportDirectory) { Message current = null; int good = 0, bad = 0; // If files already exist, we overwrite them. // But if emails within this batch generate the same filename, // use a numeric suffix to distinguish them HashSet <string> usedNames = new HashSet <string>(); xstFile.ReadMessages(folder); foreach (Message m in folder.Messages) { try { current = m; string fileName = m.ExportFileName; for (int i = 1; ; i++) { if (!usedNames.Contains(fileName)) { usedNames.Add(fileName); break; } else { fileName = String.Format("{0} ({1})", m.ExportFileName, i); } } Console.WriteLine("Exporting " + m.ExportFileName); // Ensure that we have the message contents xstFile.ReadMessageDetails(m); var fullFileName = String.Format(@"{0}\{1}.{2}", exportDirectory, fileName, m.ExportFileExtension); m.ExportToFile(fullFileName, xstFile); xstFile.SaveVisibleAttachmentsToAssociatedFolder(fullFileName, m); good++; } catch (System.Exception ex) { Console.WriteLine(String.Format("Error '{0}' exporting email '{1}'", ex.Message, current.Subject)); bad++; } } Console.WriteLine($"Folder '{folder.Name}' completed with {good} successes and {bad} failures"); }