2016-08-11 33 views
1

私は、Lotus Domino interopでLotus NotesからMIMEメールを解析しようとしています。電子メールがMIME形式でない場合、私は単純なNotesDocument.GetFirstItem("Body").Text;節を通してBodyコンテンツを取得することに成功しました。しかし、私はボディコンテンツを解析しようとしているときにMIMEでnullまたは空の文字列を取得しています。Lotus NotesからのMIMEメールを解析します。

var session = new NotesSession(); 
session.Initialize("RadioLotus028"); 
session.ConvertMime = false; 
var db = session.GetDatabase("PRGLNApps01/CZ/RFERL", "mail-in\\SEEurope\\MIA.nsf", false); 
if (db == null) throw new ArgumentNullException("cannot load database"); 

var legnth = db.AllDocuments.Count; 
for (int i = 1; i < legnth; i++) 
{ 
    NotesDocument doc = db.AllDocuments.GetNthDocument(i); 
    NotesMIMEEntity bodyMIME = doc.GetMIMEEntity(); 

    NotesStream stream = session.CreateStream(); 
    //bodyMIME.GetContentAsBytes(stream); 
    //bodyMIME.GetEntityAsText(stream); 
    bodyMIME.GetContentAsText(stream); 

    string bodyString = stream.ReadText(); 
    var bodyString2 = stream.Read(); 
    string bodyString3 = bodyMIME.ContentAsText; 

    var from = doc.GetFirstItem("From").Text; 
    var subject = doc.GetFirstItem("Subject").Text;     
} 

誰もがこの問題での経験を持っていますか?または本文コンテンツをHTMLまたはRichfullTextまたはその他の方法で取得する方法は?

+0

本文にMIMEまたはリッチテキストが含まれているかどうかはテストしていません。このメールボックスで処理しているメッセージがすべてMIMEであることを確認してください。おそらく、doc.hasItem( "$ NoteHasNativeMIME")を使用してチェックしてください。 –

+0

あなたはそうです!これは単なるコード例です。最終バージョンには、コンテンツタイプ間の切り替えが含まれています。だから、異なるブランチは、RichTextを世話し、別の人がMIMEのボディを世話します。コメントのおかげで、誰かに時間を節約できます。 – Mastenka

答えて

3

ほとんどの場合、子MIMEエンティティを見つける必要があります。

MIMEEntity mime = sourceDoc.getMIMEEntity(bodyField); 
if (mime != null) { 
    // If multipart MIME entity 
    if (mime.getContentType().equals("multipart")) { 
     // Find text/html content of each child entity 
     MIMEEntity child1 = mime.getFirstChildEntity(); 
     while (child1 != null) { 
      if (child1.getContentType().contains("text")) { 
       html = child1.getContentAsText(); 
      } 
      MIMEEntity child2 = child1.getFirstChildEntity(); 
      if (child2 == null) { 
       child2 = child1.getNextSibling(); 
       if (child2 == null) { 
        child2 = child1.getParentEntity(); 
        if (child2 != null) { 
         child2 = child2.getNextSibling(); 
        } 
       } 
      } 
      child1 = child2; 
     } 
    } else { 
     // Not multipart 
     html = mime.getContentAsText(); 
    } 
} 
+1

あなたの解決策は正しいです...私はずっとそれを欠いていました! :( – Mastenka

関連する問題