2016-06-29 127 views
0

我正在嘗試使用Java郵件API來開發電子郵件偵聽器。我收到兩封同樣的電子郵件,情況不會每次都發生;隨機發生。IMAP文件夾接收郵件兩次

下面的代碼是用來做IMAP連接

try { 
      isConnecting.set(true); 
      createSession(); 
      LOGGER.warn("session created "+getIdentifier() +"on Imap"+imapLoginId+" pw "+imapPasswrd); 
      store = session.getStore("imap"); 
      if(store==null){ 
       LOGGER.warn("store is null return from here"+getIdentifier() +"on Imap"+imapLoginId+" pw "+imapPasswrd); 
       return; 
      } 
      store.connect(imapServerAddress, imapLoginId, imapPasswrd); 
      LOGGER.warn("Connecting successful "+getIdentifier() +"on Imap"+imapLoginId+" pw "+imapPasswrd); 
      folder = store.getFolder(folderName); 
      LOGGER.warn("Folder creating "+getIdentifier() +"on Imap"+imapLoginId+" pw "+imapPasswrd); 
      if (timer == null) { 
       timer = new HashedWheelTimer(1, TimeUnit.SECONDS); 
      } 
      if (idleManager == null) { 
       idleManager = new IdleManager(session, es); 
      } 
      if (folder == null || !folder.exists()) { 
       LOGGER.warn("invalid folder exit from here "+getIdentifier() +"on Imap"+imapLoginId+" pw "+imapPasswrd); 
       System.out.println("Invalid folder"); 
       return; 
      } 
      synchronized (folder) { 
       LOGGER.warn("Folder sync "+getIdentifier() +"on Imap"+imapLoginId+" pw "+imapPasswrd); 
       folder.addConnectionListener(this); 
       folder.open(Folder.READ_WRITE); 
       folder.addMessageCountListener(this); 

       System.out.println("message count listener added"); 
       LOGGER.warn("message count listner added "+getIdentifier() +"on Imap"+imapLoginId+" pw "+imapPasswrd); 
       if (folder instanceof IMAPFolder) { 
        IMAPFolder f = (IMAPFolder) folder; 
        System.out.println("enter idle"); 
        LOGGER.warn("Idle condition "+getIdentifier() +"on Imap"+imapLoginId+" pw "+imapPasswrd); 
        idleManager.watch(f); 
        setIsConnected(true); 
        LOGGER.warn("Folder.watch "+getIdentifier() +"on Imap"+imapLoginId+" pw "+imapPasswrd); 
        DbUtil.updateMediaStream(getIdentifier(), true); 
        isConnecting.set(false); 
        connectionAttempt.set(0); 
        LOGGER.warn("Db updated "+getIdentifier() +"on Imap"+imapLoginId+" pw "+imapPasswrd); 
        System.out.println("idle done"); 
        scheduleTask(); 
        LOGGER.warn("Scheduler starts "+getIdentifier() +"on Imap"+imapLoginId+" pw "+imapPasswrd); 
       } 

      } 

      System.out.println(new Date() 
        + "================================== connect() end"); 
      LOGGER.warn("____________________END connecting "+getIdentifier() +"on Imap"+imapLoginId+" pw "+imapPasswrd); 
     } catch (Exception fex) { 

       if (connectionAttempt.get() >= 3) { 
        LOGGER.error("Reconnection Failed", fex); 
        connectionAttempt.set(0); 
        throw new IllegalStateException(
          "Error while connecting mediaStream", fex); 
       } 
       LOGGER.error("Reconnecting mediastream attempt " 
         + connectionAttempt.get(), fex); 
       connectionAttempt.incrementAndGet(); 
       closeFolderAndStore(); 
       connect(); 

     } 

電子郵件這裏收到的「公共無效messagesAdded(MessageCountEvent EV)」 方法調用兩次

@Override 
    public void messagesAdded(MessageCountEvent ev) { 
     Message[] msgs = ev.getMessages(); 
     System.out.println("Got " + msgs.length + " new messages"); 
     LOGGER.info("New message received {}" ,msgs.length); 
     // Just dump out the new messages 

     for (int i = 0; i < msgs.length; i++) { 

      try { 

       // msgs[i].writeTo(System.out); 

        System.out.println("-----"); 
        System.out.println("Message >>" + msgs[i].getMessageNumber() 
          + ":"); 
        LOGGER.info("Email Received >>> {}" , msgs[i].getMessageNumber()); 
        processEmail(msgs[i]); 


      } catch (Exception ioex) { 
       LOGGER.error("messagesAdded:getmessagenumber", ioex); 
       ioex.printStackTrace(); 
      } 
     } 
     try { 
      synchronized (folder) { 
       if (folder != null && idleManager != null) { 
        idleManager.watch(folder); 
       } 
      } 
     } catch (Exception e) { 
      LOGGER.error("messagesAdded:watch", e); 
      e.printStackTrace(); 
     } 
    } 

的IMAP調試日誌如下

DEBUG: getProvider() returning javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle] 
DEBUG IMAP: mail.imap.fetchsize: 16384 
DEBUG IMAP: mail.imap.ignorebodystructuresize: false 
DEBUG IMAP: mail.imap.statuscachetimeout: 1000 
DEBUG IMAP: mail.imap.appendbuffersize: -1 
DEBUG IMAP: mail.imap.minidletime: 10 
DEBUG IMAP: enable STARTTLS 
DEBUG IMAP: closeFoldersOnStoreFailure 
DEBUG IMAP: trying to connect to host "outlook.office365.com", port 993, isSSL true 
* OK The Microsoft Exchange IMAP4 service is ready. [QQBNADMAUABSADAANQBDAEEAMAAyADgALgBlAHUAcgBwAHIAZAAwADUALgBwAHIAbwBkAC4AbwB1AHQAbABvAG8AawAuAGMAbwBtAA==] 
A0 CAPABILITY 
* CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=XOAUTH2 SASL-IR UIDPLUS MOVE ID UNSELECT CHILDREN IDLE NAMESPACE LITERAL+ 
A0 OK CAPABILITY completed. 
DEBUG IMAP: AUTH: PLAIN 
DEBUG IMAP: AUTH: XOAUTH2 
DEBUG IMAP: protocolConnect login, host=outlook.office365.com, [email protected], password=<non-null> 
DEBUG IMAP: AUTHENTICATE PLAIN command trace suppressed 
DEBUG IMAP: AUTHENTICATE PLAIN command result: A1 OK AUTHENTICATE completed. 
A2 CAPABILITY 
* CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=XOAUTH2 SASL-IR UIDPLUS MOVE ID UNSELECT CLIENTACCESSRULES CLIENTNETWORKPRESENCELOCATION BACKENDAUTHENTICATE CHILDREN IDLE NAMESPACE LITERAL+ 
A2 OK CAPABILITY completed. 
DEBUG IMAP: AUTH: PLAIN 
DEBUG IMAP: AUTH: XOAUTH2 
A3 LIST "" inbox 
DEBUG IMAP: IdleManager select starting 
DEBUG IMAP: IdleManager waiting... 
* LIST (\Marked \HasNoChildren) "/" INBOX 
A3 OK LIST completed. 
DEBUG IMAP: connection available -- size: 1 
A4 SELECT INBOX 
* 463 EXISTS 
* 0 RECENT 
* FLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent) 
* OK [PERMANENTFLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)] Permanent flags 
* OK [UNSEEN 36] Is the first unseen message 
* OK [UIDVALIDITY 14] UIDVALIDITY value 
* OK [UIDNEXT 7207] The next unique identifier value 
A4 OK [READ-WRITE] SELECT completed. 
DEBUG IMAP: IdleManager watching imap://amith.bharathan%[email protected]/INBOX 
A5 IDLE 
+ IDLE accepted, awaiting DONE command. 
DEBUG IMAP: startIdle: set to IDLE 
DEBUG IMAP: startIdle: return true 
DEBUG IMAP: IdleManager.watch startIdle succeeded for imap://amith.bharathan%[email protected]/INBOX 
DEBUG IMAP: IdleManager selected 0 channels 
DEBUG IMAP: IdleManager adding imap://amith.bharathan%[email protected]/INBOX to selector 
DEBUG IMAP: IdleManager waiting... 
DEBUG IMAP: IdleManager selected 1 channels 
DEBUG IMAP: IdleManager selected folder: imap://amith.bharathan%[email protected]/INBOX 
* 1 RECENT 
* 464 EXISTS 
DEBUG IMAP: waitIfIdle: request IdleManager to abort 
DEBUG IMAP: waitIfIdle: wait to be not idle: Thread[pool-21-thread-2,5,main] 
DEBUG IMAP: IdleManager continue watching folder imap://amith.bharathan%[email protected]/INBOX 
DEBUG IMAP: IdleManager aborting IDLE for folder: imap://amith.bharathan%[email protected]/INBOX 
DONE 
DEBUG IMAP: IdleManager adding imap://amith.bharathan%[email protected]/INBOX to selector 
DEBUG IMAP: IdleManager adding imap://amith.bharathan%[email protected]/INBOX to selector 
DEBUG IMAP: IdleManager waiting... 
DEBUG IMAP: IdleManager selected 1 channels 
DEBUG IMAP: IdleManager selected folder: imap://amith.bharathan%[email protected]/INBOX 
A5 OK IDLE completed. 
DEBUG IMAP: handleIdle: set to RUNNING 
DEBUG IMAP: waitIfIdle: wait done, idleState 0: Thread[pool-21-thread-2,5,main] 
A6 FETCH 464 (ENVELOPE INTERNALDATE RFC822.SIZE) 
DEBUG IMAP: IdleManager done watching folder imap://amith.bharathan%[email protected]/INBOX 
DEBUG IMAP: IdleManager waiting... 
* 464 FETCH (ENVELOPE ("Wed, 29 Jun 2016 08:31:06 +0000" "4444" (("Amith K Bharathan" NIL "amith.bharathan" "drd.co.in")) NIL NIL (("Amith K Bharathan" NIL "amith.bharathan" "drd.co.in")) NIL NIL NIL "<[email protected]od.outlook.com>") INTERNALDATE "29-Jun-2016 14:01:07 +0530" RFC822.SIZE 19822) 
A6 OK FETCH completed. 
A7 FETCH 464 (BODYSTRUCTURE) 
* 464 FETCH (BODYSTRUCTURE ("text" "html" ("charset" "us-ascii") NIL NIL "7BIT" 1586 48 NIL NIL "en-US" NIL)) 
A7 OK FETCH completed. 
A8 FETCH 464 (BODY[TEXT]<0.1586>) 
* 464 FETCH (BODY[TEXT]<0> {1586} 
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii"> 
<meta name="Generator" content="Microsoft Word 14 (filtered medium)"> 
<style><!-- 
/* Font Definitions */ 
@font-face 
    {font-family:Calibri; 
    panose-1:2 15 5 2 2 2 4 3 2 4;} 
/* Style Definitions */ 
p.MsoNormal, li.MsoNormal, div.MsoNormal 
    {margin:0in; 
    margin-bottom:.0001pt; 
    font-size:11.0pt; 
    font-family:"Calibri","sans-serif";} 
a:link, span.MsoHyperlink 
    {mso-style-priority:99; 
    color:blue; 
    text-decoration:underline;} 
a:visited, span.MsoHyperlinkFollowed 
    {mso-style-priority:99; 
    color:purple; 
    text-decoration:underline;} 
span.EmailStyle17 
    {mso-style-type:personal-compose; 
    font-family:"Calibri","sans-serif"; 
    color:windowtext;} 
.MsoChpDefault 
    {mso-style-type:export-only; 
    font-family:"Calibri","sans-serif";} 
@page WordSection1 
    {size:8.5in 11.0in; 
    margin:1.0in 1.0in 1.0in 1.0in;} 
div.WordSection1 
    {page:WordSection1;} 
--></style><!--[if gte mso 9]><xml> 
<o:shapedefaults v:ext="edit" spidmax="1026" /> 
</xml><![endif]--><!--[if gte mso 9]><xml> 
<o:shapelayout v:ext="edit"> 
<o:idmap v:ext="edit" data="1" /> 
</o:shapelayout></xml><![endif]--> 
</head> 
<body lang="EN-US" link="blue" vlink="purple"> 
<div class="WordSection1"> 
<p class="MsoNormal">555555555555<o:p></o:p></p> 
</div> 
</body> 
</html> 
FLAGS (\Seen \Recent)) 
A8 OK FETCH completed. 
A9 FETCH 464 (BODY[TEXT]<0.1586>) 
* 464 FETCH (BODY[TEXT]<0> {1586} 
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii"> 
<meta name="Generator" content="Microsoft Word 14 (filtered medium)"> 
<style><!-- 
/* Font Definitions */ 
@font-face 
    {font-family:Calibri; 
    panose-1:2 15 5 2 2 2 4 3 2 4;} 
/* Style Definitions */ 
p.MsoNormal, li.MsoNormal, div.MsoNormal 
    {margin:0in; 
    margin-bottom:.0001pt; 
    font-size:11.0pt; 
    font-family:"Calibri","sans-serif";} 
a:link, span.MsoHyperlink 
    {mso-style-priority:99; 
    color:blue; 
    text-decoration:underline;} 
a:visited, span.MsoHyperlinkFollowed 
    {mso-style-priority:99; 
    color:purple; 
    text-decoration:underline;} 
span.EmailStyle17 
    {mso-style-type:personal-compose; 
    font-family:"Calibri","sans-serif"; 
    color:windowtext;} 
.MsoChpDefault 
    {mso-style-type:export-only; 
    font-family:"Calibri","sans-serif";} 
@page WordSection1 
    {size:8.5in 11.0in; 
    margin:1.0in 1.0in 1.0in 1.0in;} 
div.WordSection1 
    {page:WordSection1;} 
--></style><!--[if gte mso 9]><xml> 
<o:shapedefaults v:ext="edit" spidmax="1026" /> 
</xml><![endif]--><!--[if gte mso 9]><xml> 
<o:shapelayout v:ext="edit"> 
<o:idmap v:ext="edit" data="1" /> 
</o:shapelayout></xml><![endif]--> 
</head> 
<body lang="EN-US" link="blue" vlink="purple"> 
<div class="WordSection1"> 
<p class="MsoNormal">555555555555<o:p></o:p></p> 
</div> 
</body> 
</html> 
FLAGS (\Seen \Recent)) 
A9 OK FETCH completed. 
DEBUG IMAP: IdleManager watching imap://amith.bharathan%[email protected]/INBOX 
A10 IDLE 
+ IDLE accepted, awaiting DONE command. 
DEBUG IMAP: startIdle: set to IDLE 
DEBUG IMAP: startIdle: return true 
DEBUG IMAP: IdleManager.watch startIdle succeeded for imap://amith.bharathan%[email protected]/INBOX 
DEBUG IMAP: IdleManager selected 0 channels 
DEBUG IMAP: IdleManager adding imap://amith.bharathan%[email protected]/INBOX to selector 
DEBUG IMAP: IdleManager waiting... 
DEBUG IMAP: IdleManager selected 1 channels 
DEBUG IMAP: IdleManager selected folder: imap://amith.bharathan%[email protected]/INBOX 
* 2 RECENT 
* 465 EXISTS 
DEBUG IMAP: waitIfIdle: request IdleManager to abort 
DEBUG IMAP: waitIfIdle: wait to be not idle: Thread[pool-21-thread-2,5,main] 
DEBUG IMAP: IdleManager continue watching folder imap://amith.bharathan%[email protected]/INBOX 
DEBUG IMAP: IdleManager aborting IDLE for folder: imap://amith.bharathan%[email protected]/INBOX 
DONE 
DEBUG IMAP: IdleManager adding imap://amith.bharathan%[email protected]/INBOX to selector 
DEBUG IMAP: IdleManager adding imap://amith.bharathan%[email protected]/INBOX to selector 
DEBUG IMAP: IdleManager waiting... 
DEBUG IMAP: IdleManager selected 1 channels 
DEBUG IMAP: IdleManager selected folder: imap://amith.bharathan%[email protected]/INBOX 
A10 OK IDLE completed. 
DEBUG IMAP: handleIdle: set to RUNNING 
DEBUG IMAP: waitIfIdle: wait done, idleState 0: Thread[pool-21-thread-2,5,main] 
A11 FETCH 465 (ENVELOPE INTERNALDATE RFC822.SIZE) 
DEBUG IMAP: IdleManager done watching folder imap://amith.bharathan%[email protected]/INBOX 
DEBUG IMAP: IdleManager waiting... 
* 465 FETCH (ENVELOPE ("Wed, 29 Jun 2016 08:32:01 +0000" "test" (("Gopikrishnan V" NIL "gopikrishnan.v" "drd.co.in")) NIL NIL (("Amith K Bharathan" NIL "amith.bharathan" "drd.co.in")) NIL NIL NIL "<[email protected].outlook.com>") INTERNALDATE "29-Jun-2016 14:02:05 +0530" RFC822.SIZE 18300) 
A11 OK FETCH completed. 
A12 FETCH 465 (BODYSTRUCTURE) 
* 465 FETCH (BODYSTRUCTURE ("text" "html" ("charset" "iso-8859-1") NIL NIL "quoted-printable" 427 15 NIL NIL "en-GB" NIL)) 
A12 OK FETCH completed. 
A13 FETCH 465 (BODY[TEXT]<0.427>) 
* 465 FETCH (BODY[TEXT]<0> {427} 
<html> 
<head> 
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Diso-8859-= 
1"> 
<style type=3D"text/css" style=3D"display:none;"><!-- P {margin-top:0;margi= 
n-bottom:0;} --></style> 
</head> 
<body dir=3D"ltr"> 
<div id=3D"divtagdefaultwrapper" style=3D"font-size:12pt;color:#000000;back= 
ground-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;"> 
<p>test<br> 
</p> 
</div> 
</body> 
</html> 
FLAGS (\Seen \Recent)) 
A13 OK FETCH completed. 
A14 FETCH 465 (BODY[TEXT]<0.427>) 
* 465 FETCH (BODY[TEXT]<0> {427} 
<html> 
<head> 
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Diso-8859-= 
1"> 
<style type=3D"text/css" style=3D"display:none;"><!-- P {margin-top:0;margi= 
n-bottom:0;} --></style> 
</head> 
<body dir=3D"ltr"> 
<div id=3D"divtagdefaultwrapper" style=3D"font-size:12pt;color:#000000;back= 
ground-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;"> 
<p>test<br> 
</p> 
</div> 
</body> 
</html> 
FLAGS (\Seen \Recent)) 
A14 OK FETCH completed. 
DEBUG IMAP: IdleManager watching imap://amith.bharathan%[email protected]/INBOX 
A15 IDLE 
+ IDLE accepted, awaiting DONE command. 
DEBUG IMAP: startIdle: set to IDLE 
DEBUG IMAP: startIdle: return true 
DEBUG IMAP: IdleManager.watch startIdle succeeded for imap://amith.bharathan%[email protected]/INBOX 
DEBUG IMAP: IdleManager selected 0 channels 
DEBUG IMAP: IdleManager adding imap://amith.bharathan%[email protected]/INBOX to selector 
DEBUG IMAP: IdleManager waiting... 
DEBUG IMAP: IdleManager selected 1 channels 
DEBUG IMAP: IdleManager selected folder: imap://amith.bharathan%[email protected]/INBOX 
* 3 RECENT 
* 466 EXISTS 
DEBUG IMAP: waitIfIdle: request IdleManager to abort 
DEBUG IMAP: waitIfIdle: wait to be not idle: Thread[pool-21-thread-2,5,main] 
DEBUG IMAP: IdleManager continue watching folder imap://amith.bharathan%[email protected]/INBOX 
DEBUG IMAP: IdleManager aborting IDLE for folder: imap://amith.bharathan%[email protected]/INBOX 
DONE 
DEBUG IMAP: IdleManager adding imap://amith.bharathan%[email protected]/INBOX to selector 
DEBUG IMAP: IdleManager adding imap://amith.bharathan%[email protected]/INBOX to selector 
DEBUG IMAP: IdleManager waiting... 
DEBUG IMAP: IdleManager selected 1 channels 
DEBUG IMAP: IdleManager selected folder: imap://amith.bharathan%[email protected]/INBOX 
A15 OK IDLE completed. 
DEBUG IMAP: handleIdle: set to RUNNING 
DEBUG IMAP: waitIfIdle: wait done, idleState 0: Thread[pool-21-thread-2,5,main] 
A16 FETCH 466 (ENVELOPE INTERNALDATE RFC822.SIZE) 
DEBUG IMAP: IdleManager done watching folder imap://amith.bharathan%[email protected]/INBOX 
DEBUG IMAP: IdleManager waiting... 
* 466 FETCH (ENVELOPE ("Wed, 29 Jun 2016 08:35:56 +0000" NIL (("Gopikrishnan V" NIL "gopikrishnan.v" "drd.co.in")) NIL NIL (("Amith K Bharathan" NIL "amith.bharathan" "drd.co.in")) NIL NIL NIL "<DB4P[email protected]look.com>") INTERNALDATE "29-Jun-2016 14:05:57 +0530" RFC822.SIZE 11747) 
A16 OK FETCH completed. 
A17 FETCH 466 (BODYSTRUCTURE) 
* 466 FETCH (BODYSTRUCTURE ("text" "html" ("charset" "iso-8859-1") NIL NIL "quoted-printable" 427 15 NIL NIL "en-GB" NIL)) 
A17 OK FETCH completed. 
A18 FETCH 466 (BODY[TEXT]<0.427>) 
* 466 FETCH (BODY[TEXT]<0> {427} 
<html> 
<head> 
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Diso-8859-= 
1"> 
<style type=3D"text/css" style=3D"display:none;"><!-- P {margin-top:0;margi= 
n-bottom:0;} --></style> 
</head> 
<body dir=3D"ltr"> 
<div id=3D"divtagdefaultwrapper" style=3D"font-size:12pt;color:#000000;back= 
ground-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;"> 
<p>test<br> 
</p> 
</div> 
</body> 
</html> 
FLAGS (\Seen \Recent)) 
A18 OK FETCH completed. 
A19 FETCH 466 (BODY[TEXT]<0.427>) 
* 466 FETCH (BODY[TEXT]<0> {427} 
<html> 
<head> 
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Diso-8859-= 
1"> 
<style type=3D"text/css" style=3D"display:none;"><!-- P {margin-top:0;margi= 
n-bottom:0;} --></style> 
</head> 
<body dir=3D"ltr"> 
<div id=3D"divtagdefaultwrapper" style=3D"font-size:12pt;color:#000000;back= 
ground-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;"> 
<p>test<br> 
</p> 
</div> 
</body> 
</html> 
FLAGS (\Seen \Recent)) 
A19 OK FETCH completed. 
DEBUG IMAP: IdleManager watching imap://amith.bharathan%[email protected]/INBOX 
A20 IDLE 
+ IDLE accepted, awaiting DONE command. 
DEBUG IMAP: startIdle: set to IDLE 
DEBUG IMAP: startIdle: return true 
DEBUG IMAP: IdleManager.watch startIdle succeeded for imap://amith.bharathan%[email protected]/INBOX 
DEBUG IMAP: IdleManager selected 0 channels 
DEBUG IMAP: IdleManager adding imap://amith.bharathan%[email protected]/INBOX to selector 
DEBUG IMAP: IdleManager waiting... 
DEBUG IMAP: IdleManager selected 1 channels 
DEBUG IMAP: IdleManager selected folder: imap://amith.bharathan%[email protected]/INBOX 
* 466 EXPUNGE 
* 466 EXISTS 
DEBUG IMAP: waitIfIdle: request IdleManager to abort 
DEBUG IMAP: waitIfIdle: wait to be not idle: Thread[pool-21-thread-2,5,main] 
DEBUG IMAP: IdleManager continue watching folder imap://amith.bharathan%[email protected]/INBOX 
DEBUG IMAP: IdleManager aborting IDLE for folder: imap://amith.bharathan%[email protected]/INBOX 
DONE 
DEBUG IMAP: IdleManager adding imap://amith.bharathan%[email protected]/INBOX to selector 
DEBUG IMAP: IdleManager adding imap://amith.bharathan%[email protected]/INBOX to selector 
DEBUG IMAP: IdleManager waiting... 
DEBUG IMAP: IdleManager selected 1 channels 
DEBUG IMAP: IdleManager selected folder: imap://amith.bharathan%[email protected]/INBOX 
A20 OK IDLE completed. 
DEBUG IMAP: handleIdle: set to RUNNING 
DEBUG IMAP: waitIfIdle: wait done, idleState 0: Thread[pool-21-thread-2,5,main] 
A21 FETCH 466 (ENVELOPE INTERNALDATE RFC822.SIZE) 
DEBUG IMAP: IdleManager done watching folder imap://amith.bharathan%[email protected]/INBOX 
DEBUG IMAP: IdleManager waiting... 
* 466 FETCH (ENVELOPE ("Wed, 29 Jun 2016 08:35:56 +0000" NIL (("Gopikrishnan V" NIL "gopikrishnan.v" "drd.co.in")) NIL NIL (("Amith K Bharathan" NIL "amith.bharathan" "drd.co.in")) NIL NIL NIL "<[email protected].outlook.com>") INTERNALDATE "29-Jun-2016 14:05:57 +0530" RFC822.SIZE 13152) 
A21 OK FETCH completed. 
A22 FETCH 466 (BODYSTRUCTURE) 
* 466 FETCH (BODYSTRUCTURE ("text" "html" ("charset" "iso-8859-1") NIL NIL "quoted-printable" 427 15 NIL NIL "en-GB" NIL)) 
A22 OK FETCH completed. 
A23 FETCH 466 (BODY[TEXT]<0.427>) 
* 466 FETCH (BODY[TEXT]<0> {427} 
<html> 
<head> 
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Diso-8859-= 
1"> 
<style type=3D"text/css" style=3D"display:none;"><!-- P {margin-top:0;margi= 
n-bottom:0;} --></style> 
</head> 
<body dir=3D"ltr"> 
<div id=3D"divtagdefaultwrapper" style=3D"font-size:12pt;color:#000000;back= 
ground-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;"> 
<p>test<br> 
</p> 
</div> 
</body> 
</html> 
FLAGS (\Seen \Recent)) 
A23 OK FETCH completed. 
A24 FETCH 466 (BODY[TEXT]<0.427>) 
* 466 FETCH (BODY[TEXT]<0> {427} 
<html> 
<head> 
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Diso-8859-= 
1"> 
<style type=3D"text/css" style=3D"display:none;"><!-- P {margin-top:0;margi= 
n-bottom:0;} --></style> 
</head> 
<body dir=3D"ltr"> 
<div id=3D"divtagdefaultwrapper" style=3D"font-size:12pt;color:#000000;back= 
ground-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;"> 
<p>test<br> 
</p> 
</div> 
</body> 
</html> 
FLAGS (\Seen \Recent)) 
A24 OK FETCH completed. 
DEBUG IMAP: IdleManager watching imap://amith.bharathan%[email protected]/INBOX 
A25 IDLE 
+ IDLE accepted, awaiting DONE command. 
DEBUG IMAP: startIdle: set to IDLE 
DEBUG IMAP: startIdle: return true 
DEBUG IMAP: IdleManager.watch startIdle succeeded for imap://amith.bharathan%[email protected]/INBOX 
DEBUG IMAP: IdleManager selected 0 channels 
DEBUG IMAP: IdleManager adding imap://amith.bharathan%[email protected]/INBOX to selector 
DEBUG IMAP: IdleManager waiting... 

身體「測試」的電子郵件正在重複

請指教。

由於

Amith

+0

日誌顯示你讀了兩遍 – Outtruder

+0

(帶標籤A8和A9命令)@Outtruder我僅添加了一個監聽器,但我收到兩封電子郵件,這就是我的問題 – Amith

回答

1

這是在郵箱消息號466。服務器宣佈新的消息:

* 3 RECENT 
    * 466 EXISTS 

您處理消息:

A16 FETCH 466 (ENVELOPE INTERNALDATE RFC822.SIZE) 
    ... 

你等待新的消息,並且服務器會告訴你:

* 466 EXPUNGE 
    * 466 EXISTS 

這意味着消息編號466已從郵箱中完全刪除,郵箱中有一個新的郵件號碼466。 JavaMail的通知您新的訊息號466很顯然,這是完全一樣的刪除消息號466

我不知道爲什麼服務器這樣做。它看起來像服務器中的一個bug。 請將其報告給Microsoft。

您可能想要檢查正在處理的消息的IMAP UID。新消息466絕對必須具有不同的UID。如果沒有,那是服務器中更嚴重的錯誤。

您還可以檢查郵件的Message-ID,以確保你以前沒有見過該消息。如果所有的錯誤情況都是這樣的,你可能只需要保留一條消息的歷史記錄。但需要注意的是,雖然郵件ID的目的是唯一的,通常是獨特的,不同於IMAP的UID沒有保證,他們獨特的,甚至它們的存在的。

相關問題