EldoS | Feel safer!

Software components for data protection, secure storage and transfer

AddPart does not make copy of added message part

Also by EldoS: Callback File System
Create virtual file systems and disks, expose and manage remote data as if they were files on the local disk.
#22085
Posted: 10/19/2012 03:03:01
by Niklas Kjellander (Standard support level)
Joined: 09/30/2008
Posts: 49

I get a strange NullReferenceException when i try to save an instance of TElMessage to file. The exception is thrown when I invoke AssembleMessage method. In short, this is what i do, m_message is an instance of TElMessage and its main part is a multi part list.

Code
using (TElPlainTextPart textPart = new TElPlainTextPart(m_message, m_message.MainPart))
{
   textPart.SetText("some text");
   m_message.MainPart.AddPart(textPart, true, -1);
}

using (SBMIMEStream.TAnsiStringStream sm = new SBMIMEStream.TAnsiStringStream())
{
   int res = m_message.AssembleMessage(sm, false);
}


This is the stack trace from the exception:

  • at SBMIME.TElMessagePart.internalAssemble(Stream Destination, Byte[] Charset, TElHeaderEncoding HeaderEncoding, Byte[] BodyEncoding, Byte[] AttachEncoding, String AText, Boolean bDataIsText, Boolean bAssembleSource)
  • at SBMIME.TElPlainTextPart.Assemble(Stream Destination, Byte[] Charset, TElHeaderEncoding HeaderEncoding, Byte[] BodyEncoding, Byte[] AttachEncoding, Boolean bAssembleSource)
  • at SBMIME.TElMultiPartList.Assemble(Stream Destination, Byte[] Charset, TElHeaderEncoding HeaderEncoding, Byte[] BodyEncoding, Byte[] AttachEncoding, Boolean bAssembleSource)
  • at SBMIME.TElMessage.AssembleMessage(Stream Destination, Byte[] Charset, TElHeaderEncoding HeaderEncoding, Byte[] BodyEncoding, Byte[] AttachEncoding, Boolean bAssembleSource)
  • at SBMIME.TElMessage.AssembleMessage(Stream Destination, String Charset, TElHeaderEncoding HeaderEncoding, String BodyEncoding, String AttachEncoding, Boolean bAssembleSource)
  • at SBMIME.TElMessage.AssembleMessage(Stream Destination, Boolean bAssembleSource)



If I remove the first using statement and just create a new text part AssembleMessage works fine. Seems like AddPart does not really make a copy of the part beeing sent to it.

Best regards,

Niklas Kjellander
#22086
Posted: 10/19/2012 03:15:26
by Vsevolod Ievgiienko (EldoS Corp.)

Thank you for contacting us.

Quote
Seems like AddPart does not really make a copy of the part beeing sent to it.

Indeed it doesn't make a copy, so your should not use 'using' statement.
#22087
Posted: 10/19/2012 04:04:37
by Niklas Kjellander (Standard support level)
Joined: 09/30/2008
Posts: 49

Well, souldn't it make a copy? Isn't that what the documentation implies?

I took a quick peek at the method in the .Net reflector and it seems like there is a bug in this method. There is a declaration of a message part inside that is assigned to the part sent as argument (Part) or assigned to a clone of the argument if bMakeCopy is set to true. However, the internally declared part is then just ignored for the rest of the method, instead the part passed as argument is used when setting parent and adding it to the internal list of parts.
#22089
Posted: 10/19/2012 04:13:22
by Eugene Mayevski (EldoS Corp.)

Quote
Niklas Kjellander wrote:
Well, souldn't it make a copy? Isn't that what the documentation implies?


If bMakeCopy == true, then sure, a copy must be made. Thank you for pointing at the bug, we've fixed it for the next update.


Sincerely yours
Eugene Mayevski

Reply

Statistics

Topic viewed 516 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!