We still got a problem with conversion of mail messages. With the code below we try to convert a msg formatted mail to RFC 822 format and back to msg format. Now the code which works with Aspose.Network 4.6.0.1 doesn't work any more with version 4.7.0.8. The code fails at the underlined line with the following error description. The error occurs with any msg formatted mail on 32 bit and 64 bit windows platforms.
Best Regards
Volker Roeser
bei System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy)
bei System.String.Substring(Int32 startIndex, Int32 length)
bei Aspose.Network.Outlook.MapiMessage.xbe8fa87f38748b7c(MapiAttachmentCollection xb8b986a36a564367, MapiPropertyStream xebd3f90832eab048, Attachment xdd361a2e023253e5, OutlookMessageFormat x5786461d089b10a0)
bei Aspose.Network.Outlook.MapiMessage.xaa71394a9a765151(MailMessage x1f25abf5fb75e795, MapiMessage xa773d6b986f6bdbb)
bei Aspose.Network.Outlook.MapiMessage.FromMailMessage(MailMessage message)
bei Aspose.Network.Mail.MailMessage.Save(Stream stream, MessageFormat format)
bei WindowsApplication2.Form1.ConvertEmailFormat(Stream pStream, MessageFormat pInputFormat, MessageFormat pOutputFormat)
private void button1_Click(object sender, EventArgs eventArgs)
{
OpenFileDialog dlg = null;
try
{
dlg = new OpenFileDialog();
dlg.Multiselect = false;
dlg.Filter = "Outlook-Nachrichtenformat (*.msg)|*.msg|RFC 822 Format (*.eml)|*.eml|"
+ "Alle Dateien (*.*)|*.*";
if (dlg.ShowDialog() != DialogResult.OK)
return;
textBoxFilename.Text = dlg.FileName;
MailMessage mailMessage = null;
if (Path.GetExtension(dlg.FileName).ToLower().Equals(".msg"))
mailMessage = MailMessage.Load(dlg.OpenFile(), MessageFormat.Msg);
else
mailMessage = MailMessage.Load(dlg.OpenFile());
Stream stream = new MemoryStream();
mailMessage.Save(stream);
stream.Position = 0;
//... Save the RFC 822 formatted mail to a stream wich will be saved into database
//... load the stream from database and change the mail format back to msg format
stream = ConvertEmailFormat(stream, MessageFormat.Eml, MessageFormat.Msg);
}
catch (Exception e)
{
MessageBox.Show(e.Message, "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
private Stream ConvertEmailFormat(Stream pStream, MessageFormat pInputFormat, MessageFormat pOutputFormat)
{
Stream stream = null;
try
{
pStream.Position = 0;
MailMessage mailMessage = MailMessage.Load(pStream, pInputFormat);
stream = new MemoryStream();
mailMessage.Save(stream, pOutputFormat);
stream.Position = 0;
}
catch (Exception e)
{
throw new MailArchiveException(string.Format("Fehler beim Umwandeln der E-Mail in das"
+ "{0}-Dateiformat", pOutputFormat.ToString()), e);
}
return stream;
}