2014-03-06 1 views
1

MailSystem.NET을 사용하여 모든 메일 (Drafts의 내용은 제외)을 읽고 UUID, 날짜, 보낸 사람, 모든받는 사람 전자 메일을 추출하려고합니다.효율적인 FETCH 쿼리 및 구문 분석 결과

가장 최근에 시작하여 뒤로 검색하여 한 번에 100 개의 헤더 배치를로드하고 싶습니다.

이 작업 중에 새 전자 메일이 수신되면 메시지 인덱스 변경 내용이 진행 상황에 영향을 미치지 않도록 할 수 있습니다.

나는 이것에 대한 조언을하고 싶습니다. 필자는 Fetch() 래퍼가 개별 메시지에서 작동하고받은 편지함 검색 기능이 UID가 아닌 메시지 인덱스 서수를 제공한다고 생각합니다. 나는 UID가 동시 활동에보다 견고 할 것이라고 믿는다.

imap.Command ("fetch 1 : 100 (uid rfc822.header)"를 호출 할 수 있습니다.) 그러나 MailSystem.NET을 사용하여 결과를 구문 분석하는 방법을 알지 못합니다.

또한 "마지막으로 본 UID보다 작은 UID를 사용하여 다음 100 개의 메시지를 가져 오는 중"이라고 말할 수있는 방법이 있습니까? UID가 나중 메시지와 함께 항상 증가한다고 가정하는 것이 안전 할 경우. 나는 이것을 메시지 색인 서수에 근거하는 대신에 사용할 수 있음을 의미합니다.

감사합니다.

답변

0

MailSystem.NET을 사용하여 질문에 답변 할 수 없지만 훨씬 나은 C# IMAP 라이브러리 인 MailKit을 사용하여이 질문에 대답 할 수 있습니다.

using System; 

using MailKit.Net.Imap; 
using MailKit; 
using MimeKit; 

namespace TestClient { 
    class Program 
    { 
     public static void Main (string[] args) 
     { 
      using (var client = new ImapClient()) { 
       client.Connect ("imap.friends.com", 993, true); 

       // Note: since we don't have an OAuth2 token, disable 
       // the XOAUTH2 authentication mechanism. 
       client.AuthenticationMechanisms.Remove ("XOAUTH"); 

       client.Authenticate ("joey", "password"); 

       // The Inbox folder is always available on all IMAP servers... 
       client.Inbox.Open (FolderAccess.ReadOnly); 

       // Note: The envelope contains the date and all of the email addresses 
       var items = MessageSummaryItems.UniqueId | MessageSummaryItems.Envelope; 
       int upper = client.Inbox.Count - 1; 
       int lower = Math.Max (upper - 100, 0); 

       while (lower <= upper) { 
        foreach (var message in client.Inbox.Fetch (lower, upper, items)) { 
         Console.WriteLine ("Sender: {0}", message.Envelope.Sender); 
         Console.WriteLine ("From: {0}", message.Envelope.From); 
         Console.WriteLine ("To: {0}", message.Envelope.To); 
         Console.WriteLine ("Cc: {0}", message.Envelope.Cc); 
         if (message.Envelope.Date.HasValue) 
          Console.WriteLine ("Date: {0}", message.Envelope.Date.Value); 
        } 

        upper = lower - 1; 
        lower = Math.Max (upper - 100, 0); 
       } 

       client.Disconnect (true); 
      } 
     } 
    } 
} 
+0

995는 imap ...에 대한 홀수 포트 번호입니다. – arnt

+0

죄송합니다. 예, 993을 입력하려고했습니다. – jstedfast