/// <summary> /// This function will read all the properties of an <see cref="Storage.Message"/> file and maps /// all the properties that are filled to the extended file attributes. /// </summary> /// <param name="inputFile">The msg file</param> public void SetExtendedFileAttributesWithMsgProperties(string inputFile) { MemoryStream memoryStream = null; try { // We need to read the msg file into memory because we otherwise can't set the extended filesystem // properties because the files is locked memoryStream = new MemoryStream(); using (var fileStream = File.OpenRead(inputFile)) fileStream.CopyTo(memoryStream); memoryStream.Position = 0; using (var shellFile = ShellFile.FromFilePath(inputFile)) { using (var propertyWriter = shellFile.Properties.GetPropertyWriter()) { using (var message = new Storage.Message(memoryStream)) { switch (message.Type) { case Storage.Message.MessageType.Email: MapEmailPropertiesToExtendedFileAttributes(message, propertyWriter); break; case Storage.Message.MessageType.AppointmentRequest: case Storage.Message.MessageType.Appointment: case Storage.Message.MessageType.AppointmentResponse: MapAppointmentPropertiesToExtendedFileAttributes(message, propertyWriter); break; case Storage.Message.MessageType.Task: case Storage.Message.MessageType.TaskRequestAccept: MapTaskPropertiesToExtendedFileAttributes(message, propertyWriter); break; case Storage.Message.MessageType.Contact: MapContactPropertiesToExtendedFileAttributes(message, propertyWriter); break; case Storage.Message.MessageType.Unknown: throw new NotSupportedException("Unsupported message type"); } } } } } finally { if (memoryStream != null) memoryStream.Dispose(); } }
public string[] ExtractToFolder(string inputFile, string outputFolder, bool hyperlinks = false) { outputFolder = FileManager.CheckForBackSlash(outputFolder); _errorMessage = string.Empty; try { using (var stream = File.Open(inputFile, FileMode.Open, FileAccess.Read)) using (var message = new Storage.Message(stream)) { switch (message.Type) { case Storage.Message.MessageType.Email: return WriteEmail(message, outputFolder, hyperlinks).ToArray(); case Storage.Message.MessageType.AppointmentRequest: case Storage.Message.MessageType.Appointment: case Storage.Message.MessageType.AppointmentResponse: return WriteAppointment(message, outputFolder, hyperlinks).ToArray(); case Storage.Message.MessageType.Task: throw new Exception("An task file is not supported"); case Storage.Message.MessageType.StickyNote: return WriteStickyNote(message, outputFolder, hyperlinks).ToArray(); case Storage.Message.MessageType.Unknown: throw new NotSupportedException("Unknown message type"); } } } catch (Exception e) { _errorMessage = GetInnerException(e); return new string[0]; } // If we return here then the file was not supported return new string[0]; }