title: Lotus Notes MIME Conversion - Content returns null
body: <p>I am trying to access Lotus Notes NSF Files to convert them to EML, so far it is working fine but it fails randomly for some files.</p>
  
  <p>I am creating a Notes Session without MIME conversion:</p>
  
  <pre><code>NotesSession session = new NotesSession();
  session.Initialize(GLNAdminPassword);
  session.ConvertMime = false;
  NotesDatabase db = session.GetDatabase(GLNServer, GLNFilePath, true);
  </code></pre>
  
  <p>==========</p>
  
  <pre><code>if (doc.GetFirstItem("Body") != null)
  bool result = WriteMIMEOutput(doc.NoteID + ".eml", doc.NoteID, db, session);
  </code></pre>
  
  <p>The Write MIME output creates MIME as following:</p>
  
  <pre><code>private static bool WriteMIMEOutput(string outfile, string noteid, NotesDatabase nsf,
  
                         NotesSession session)
  {
      try
      {
          Domino.NotesMIMEEntity mE = null;
          Domino.NotesMIMEEntity mChild = null;
          bool result = false;
          string contentType = null;
          string headers = null;
          string content = null;
          string preamble = null;
          MIME_ENCODING encoding;
          StreamWriter writer = new StreamWriter(outfile);
          NotesDocument doc = nsf.GetDocumentByID(noteid);
  
          if (doc == null)
          {
              MessageBox.Show("doc = null");
  
              goto XEnd;
          }
  
  
          mE = doc.GetMIMEEntity("body");
  
          if (mE == null)
          {
              SQLMIMEErrorlogger(ex, noteid);
  
              goto XEnd;
          }
  
          contentType = mE.ContentType;
          headers = mE.Headers;
          encoding = mE.Encoding;
  
          // message envelope. If no MIME-Version header, add one
          if (!headers.Contains("MIME-Version:"))
              writer.WriteLine("MIME-Version: 1.0");
          writer.WriteLine(headers);
  
          // for multipart, usually no main-msg content...
          if (content != null &amp;&amp; content.Trim().Length &gt; 0)
              writer.WriteLine(content);
          writer.Flush();
  
          if (contentType.StartsWith("multipart"))
          {
              preamble = mE.Preamble;
              mChild = mE.GetFirstChildEntity();
              while (mChild != null)
              {
                  headers = mChild.Headers;
                  encoding = mChild.Encoding;
  
                  // if it's a binary part, force it to b64
                  if (encoding == MIME_ENCODING.ENC_IDENTITY_BINARY)
                  {
                      mChild.EncodeContent(MIME_ENCODING.ENC_BASE64);
                      headers = mChild.Headers;
                  }
  
                  preamble = mChild.Preamble;
  
                  content = mChild.BoundaryStart;
                  writer.Write(content);
                  if (!content.EndsWith("\n"))
                      writer.WriteLine("");
  
                  writer.WriteLine(headers);
                  writer.WriteLine();
  
                  content = mChild.ContentAsText;
                  writer.Write(content);
                  writer.Write(mChild.BoundaryEnd);
                  writer.Flush();
                  mChild = mChild.GetNextSibling();
              } // end while
          } // end multipart
          if (contentType.StartsWith("text/plain"))
          {
              preamble = mE.Preamble;
              mChild = mE.GetFirstChildEntity();
              while (mChild != null)
              {
                  headers = mChild.Headers;
                  encoding = mChild.Encoding;
  
                  // if it's a binary part, force it to b64
                  if (encoding == MIME_ENCODING.ENC_IDENTITY_BINARY)
                  {
                      mChild.EncodeContent(MIME_ENCODING.ENC_BASE64);
                      headers = mChild.Headers;
                  }
  
                  preamble = mChild.Preamble;
  
                  content = mChild.BoundaryStart;
                  writer.Write(content);
                  if (!content.EndsWith("\n"))
                      writer.WriteLine("");
  
                  writer.WriteLine(headers);
                  writer.WriteLine();
  
                  content = mChild.ContentAsText;
                  writer.Write(content);
                  writer.Write(mChild.BoundaryEnd);
                  writer.Flush();
                  mChild = mChild.GetNextSibling();
              } // end while
          } //
          if (contentType.StartsWith("text/html"))
          {
              preamble = mE.Preamble;
              mChild = mE.GetFirstChildEntity();
              while (mChild != null)
              {
                  headers = mChild.Headers;
                  encoding = mChild.Encoding;
  
                  // if it's a binary part, force it to b64
                  if (encoding == MIME_ENCODING.ENC_IDENTITY_BINARY)
                  {
                      mChild.EncodeContent(MIME_ENCODING.ENC_BASE64);
                      headers = mChild.Headers;
                  }
  
                  preamble = mChild.Preamble;
  
                  content = mChild.BoundaryStart;
                  writer.Write(content);
                  if (!content.EndsWith("\n"))
                      writer.WriteLine("");
  
                  writer.WriteLine(headers);
                  writer.WriteLine();
  
                  content = mChild.ContentAsText;
                  writer.Write(content);
                  writer.Write(mChild.BoundaryEnd);
                  writer.Flush();
                  mChild = mChild.GetNextSibling();
              } // end while
          } //
          // end of main envelope
          writer.WriteLine(mE.BoundaryEnd);
          result = true;
  
      XEnd:
  
          if (writer != null)
              writer.Close();
          return result;
      }
      catch (Exception ex)
      {
          SQLMIMEErrorlogger(ex, noteid);
  
          return false;
      }
  }
  </code></pre>
  
  <p>But
  <code>content = mChild.ContentAsText;</code> 
  randomly returns empty text which creates emails with no body, what could be the reason of this.</p>
  
  <p>Thanks.</p>