JavaMail client reads new messages but not existing messages - email

JavaMail newbie here. I'm trying to figure out what's wrong with a Javamail client that's embeded in a very large system. Sorry I do not have a short, self-contained example, but I'm hoping that someone might be able to give me some tips on how to go about debugging this issue.
It's JavaMail 1.4.3 in Java 7, running on Windows 7. The email server is on a Linux box. The intent of the code is to read all emails in an inbox, delete and expunge them, do some work on the emails, pause for a while, then repeat, looping forever. The problem is that if there are already emails in the inbox when this program starts and the JavaMail client code executes, it does not retrieve them. However, if I send emails to the inbox once the code is running, it retrieves them just fine.
The code gets the inbox with Store.getFolder("INBOX"), opens it with Folder.open(Folder.READ_WRITE) and does a Folder.getMessages(). The getMessages() call always returns no messages when first starting up, but does return the messages sent after the program's been started.
I'm using Pine to verify that the inbox does or does not contains messages, but am not opening the messages in Pine, so they should still be new. And if I use Pine to look at the inbox after running this code, it still contains old messages that were sent before the program was launched, but not any that were sent to it while the program was running (they've been successfully read, deleted and expunged).
The code should also be reading messages that are already in the inbox when it starts. I set mail.debug=true and that output follows. Again, any tips for how to dig into this would be greatly appreciated. Thanks.
// first attempt to read mail when program starts
DEBUG: JavaMail version 1.4.3
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smt
ps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSP
ORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STOR
E,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,
pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,
com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.m
ail.pop3.POP3Store,Sun Microsystems, Inc]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,S
un Microsystems, Inc], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=jav
ax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], pop3=javax.mail.Provider[STO
RE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3
SSLStore,Sun Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystem
s, Inc]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: getProvider() returning javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems,
Inc]
DEBUG: mail.imap.fetchsize: 16384
DEBUG: mail.imap.statuscachetimeout: 1000
DEBUG: mail.imap.appendbuffersize: -1
DEBUG: mail.imap.minidletime: 10
DEBUG: trying to connect to host "10.128.200.85", port 143, isSSL false
* OK [CAPABILITY IMAP4REV1 LOGIN-REFERRALS STARTTLS AUTH=LOGIN] pristine.ame.xx.com IMAP4rev1 2001.315rh at Mon, 30 Dec 2013 11:15:26 -0500 (EST)
IMAP DEBUG: AUTH: LOGIN
DEBUG: protocolConnect login, host=10.128.200.85, user=venuswmpublic, password=<non-null>
A0 AUTHENTICATE LOGIN
+ VXNlciBOYW1lAA==
dmVudXN3bXB1YmxpYw==
+ UGFzc3dvcmQA
d2VibTEyMzQ=
A0 OK [CAPABILITY IMAP4REV1 IDLE NAMESPACE MAILBOX-REFERRALS SCAN SORT THREAD=REFERENCES THREAD=ORDEREDSUBJECT MULTIAPPEND] User venuswmpublic authenticated
A1 LIST "" INBOX
* LIST (\NoInferiors) NIL INBOX
A1 OK LIST completed
DEBUG: connection available -- size: 1
A2 SELECT INBOX
* 0 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1] UID validity status
* OK [UIDNEXT 1] Predicted next UID
* FLAGS (\Answered \Flagged \Deleted \Draft \Seen)
* OK [PERMANENTFLAGS ()] Permanent flags
A2 OK [READ-WRITE] SELECT completed
A3 EXPUNGE
A3 OK EXPUNGE completed
Monitoring incoming email...
* OK [CAPABILITY IMAP4REV1 LOGIN-REFERRALS STARTTLS AUTH=LOGIN] pristine.ame.xx.com IMAP4rev1 2001.315rh at
Mon, 30 Dec 2013 11:15:38 -0500 (EST)
IMAP DEBUG: AUTH: LOGIN
A0 AUTHENTICATE LOGIN
+ VXNlciBOYW1lAA==
dmVudXN3bXB1YmxpYw==
+ UGFzc3dvcmQA
d2VibTEyMzQ=
A0 OK [CAPABILITY IMAP4REV1 IDLE NAMESPACE MAILBOX-REFERRALS SCAN SORT THREAD=REFERENCES THREAD=ORDEREDSUBJECT MULTIAPPEND] User venuswmpublic authenticated
IMAP DEBUG: IMAPProtocol noop
A1 NOOP
A1 OK NOOP completed
IMAP DEBUG: IMAPProtocol noop
A4 NOOP
A4 OK NOOP completed
A5 EXPUNGE
A5 OK EXPUNGE completed
A6 EXPUNGE
A6 OK EXPUNGE completed
DEBUG: pool is full, not adding an Authenticated connection
A7 CLOSE
A7 OK CLOSE completed
A8 LOGOUT
* BYE pristine.ame.xx.com IMAP4rev1 server terminating connection
A8 OK LOGOUT completed
A2 LOGOUT
* BYE pristine.ame.xx.com IMAP4rev1 server terminating connection
A2 OK LOGOUT completed
DEBUG: IMAPStore connection dead
DEBUG: IMAPStore cleanup, force false
DEBUG: IMAPStore cleanup done
// and a bunch of these...
Monitoring incoming email...
IMAP DEBUG: IMAPProtocol noop
A33 NOOP
A33 OK NOOP completed
IMAP DEBUG: IMAPProtocol noop
A77 NOOP
A77 OK NOOP completed
A78 EXPUNGE
A78 OK No messages deleted, so no update needed
Monitoring incoming email...
IMAP DEBUG: IMAPProtocol noop
A34 NOOP
A34 OK NOOP completed
IMAP DEBUG: IMAPProtocol noop
A79 NOOP
A79 OK NOOP completed
A80 EXPUNGE
A80 OK No messages deleted, so no update needed
etc...
------------------------------------
// If I send in an email while the program is running, it picks it up, but still leaves the previous ones unread in the inbox.
Monitoring incoming email...
IMAP DEBUG: IMAPProtocol noop
A4 NOOP
A4 OK NOOP completed
IMAP DEBUG: IMAPProtocol noop
A10 NOOP
* 1 EXISTS
* 1 RECENT
* OK [UIDVALIDITY 1388420519] UID validity status
* OK [UIDNEXT 2] Predicted next UID
* FLAGS (\Answered \Flagged \Deleted \Draft \Seen)
* OK [PERMANENTFLAGS (\* \Answered \Flagged \Deleted \Draft \Seen)] Permanent flags
* OK [READ-WRITE] Mailbox status
* OK [UNSEEN 1] first unseen message in /var/spool/mail/venuswmpublic
A10 OK NOOP completed
A11 EXPUNGE
A11 OK Mailbox checkpointed, but no messages expunged
A12 STORE 1 +FLAGS (\Flagged)
* 1 FETCH (FLAGS (\Recent \Flagged))
A12 OK STORE completed
A13 FETCH 1 (ENVELOPE INTERNALDATE RFC822.SIZE)
* 1 FETCH (ENVELOPE ("Mon, 30 Dec 2013 19:43:42 +0000" "test.testService"
* (("LName, FName" NIL "FName.LName" "Company.com")) (("LName, FName" NIL "FName.LName"
"Company.com")) (("LName, FName" NIL "FName.LName"
"Company.com")) (("venuswmpublic#pristine.ame.xx.com" NIL "venuswmpublic" "pristine.ame.xx.com")) NIL NI
L NIL "<DAF6C79D86A80C49A9F66B898B2821A327FD50E6#hqmbx6.eur.ad.sag>") INTERNALDATE "30-Dec-2013 11:21:51 -0500" RFC822.S
IZE 3774)
A13 OK FETCH completed
A14 FETCH 1 (BODYSTRUCTURE)
* 1 FETCH (BODYSTRUCTURE (("TEXT" "PLAIN" ("CHARSET" "us-ascii") NIL NIL "QUOTED-PRINTABLE" 15 1 NIL NIL NIL
)("TEXT" "HTML" ("CHARSET" "us-ascii") NIL NIL "QUOTED-PRINTABLE" 1899 60 NIL NIL NIL) "ALTERNATIVE" ("BOUNDARY" "_000_D
AF6C79D86A80C49A9F66B898B2821A327FD50E6hqmbx6euradsag_") NIL "EN-US"))
A14 OK FETCH completed
A15 FETCH 1 (BODY[1]<0.15>)
* 1 FETCH (BODY[1]<0> {15}
a=3D111111111
)
* 1 FETCH (FLAGS (\Recent \Seen \Flagged))
A15 OK FETCH completed
A16 FETCH 1 (BODY[1]<0.15>)
* 1 FETCH (BODY[1]<0> {15}
a=3D111111111
)
A16 OK FETCH completed
A17 FETCH 1 (BODY[2]<0.1899>)
* 1 FETCH (BODY[2]<0> {1899}
<html xmlns:v=3D"urn:schemas-microsoft-com:vml" xmlns:o=3D"urn:schemas-micr=
osoft-com:office:office" xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" xmlns=3D"http:=
//www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dus-ascii"=
>
<meta name=3D"Generator" content=3D"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;}
#font-face
{font-family:"Trebuchet MS";
panose-1:2 11 6 3 2 2 2 2 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:"Trebuchet MS","sans-serif";
color:windowtext;
font-weight:normal;
font-style:normal;
text-decoration:none none;}
.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=3D"edit" spidmax=3D"1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext=3D"edit">
<o:idmap v:ext=3D"edit" data=3D"1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=3D"EN-US" link=3D"blue" vlink=3D"purple">
<div class=3D"WordSection1">
<p class=3D"MsoNormal"><span style=3D"font-size:10.0pt;font-family:"Tr=
ebuchet MS","sans-serif"">a=3D111111111<o:p></o:p></span></p=
>
</div>
</body>
</html>
)
A17 OK FETCH completed
A18 FETCH 1 (BODY[1]<0.15>)
* 1 FETCH (BODY[1]<0> {15}
a=3D111111111
)
A18 OK FETCH completed
DEBUG: JavaMail version 1.4.3
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smt
ps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSP
ORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STOR
E,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,
pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,
com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.m
ail.pop3.POP3Store,Sun Microsystems, Inc]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,S
un Microsystems, Inc], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=jav
ax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], pop3=javax.mail.Provider[STO
RE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3
SSLStore,Sun Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystem
s, Inc]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
2013-12-30 14:43:53 EST [ISS.0015.0005D] Invoking service test.testService.
2013-12-30 14:43:53 EST [ISP.0090.0001C] ---
2013-12-30 14:43:53 EST [ISP.0090.0001C] --- test.testService EXECUTED !!!
2013-12-30 14:43:53 EST [ISP.0090.0001C] ---
A19 STORE 1 +FLAGS (\Deleted)
* 1 FETCH (FLAGS (\Recent \Seen \Deleted \Flagged))
A19 OK STORE completed
A20 EXPUNGE
* 1 EXPUNGE
* 0 EXISTS
* 0 RECENT
A20 OK Expunged 1 messages

Your server is telling JavaMail that there are no messages in the Inbox ("0 EXISTS") when it first opens it, then a message appears ("1 EXISTS"), which your program processes, deletes, and expunges. That all looks perfectly normal.
If you think there are other messages in the Inbox, the server disagrees. Perhaps you have some messages cached in your Pine client? Perhaps you've set Pine up to work similarly to how most POP3 clients work - download messages from the server, cache them locally, and delete them from the server?

Related

MailKit search query problems

I use MailKit and IMAP Client. There are no problems with GMail mails, but when I make the same request to another server, problems appear.
Even a simple Search with the criterion MailKit.Search.SearchQuery.NotSeen does not work. I have access to the mailbox and mails are read, but filters do not work.
The only working filter is MailKit.Search.SearchQuery.All. Also I cannot change flag from NotSeen to Seen using Inbox.AddFlags, it works only with GMail.
When I use Fetch method with MessageSummaryItems.BodyStructure it returns TextBody = null.
Does it work correctly only with GMail or I must fix some server settings?
IMAP.log:
Connected to imaps://mail.totalware.gr:993/
S: * OK [CAPABILITY IMAP4rev1 SASL-IR LOGIN-REFERRALS ID ENABLE IDLE NAMESPACE LITERAL+ AUTH=PLAIN AUTH=LOGIN] Dovecot ready.
C: A00000000 AUTHENTICATE PLAIN AGZvc3Rpcm9wb3Vsb3NAdG90YWx3YXJlLmdyAEAhZm9zdGlyb3BvdWxvc0Ah
S: A00000000 OK [CAPABILITY IMAP4rev1 SASL-IR LOGIN-REFERRALS ID ENABLE IDLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS THREAD=ORDEREDSUBJECT MULTIAPPEND URL-PARTIAL CATENATE UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS BINARY MOVE SNIPPET=FUZZY PREVIEW=FUZZY STATUS=SIZE NAMESPACE LITERAL+ NOTIFY SPECIAL-USE COMPRESS=DEFLATE QUOTA] Logged in
C: A00000001 NAMESPACE
S: * NAMESPACE (("INBOX." ".")) NIL NIL
S: A00000001 OK Namespace completed (0.001 + 0.000 secs).
C: A00000002 LIST "" "INBOX" RETURN (SUBSCRIBED CHILDREN)
S: * LIST (\HasChildren) "." INBOX
S: A00000002 OK List completed (0.017 + 0.000 + 0.016 secs).
C: A00000003 LIST (SPECIAL-USE) "" "*" RETURN (SUBSCRIBED CHILDREN)
S: * LIST (\HasNoChildren \Archive) "." INBOX.Archive
S: * LIST (\Subscribed \HasNoChildren \Junk) "." INBOX.spam
S: * LIST (\Subscribed \HasNoChildren \UnMarked \Trash) "." INBOX.Trash
S: * LIST (\Subscribed \HasNoChildren \UnMarked \Sent) "." INBOX.Sent
S: * LIST (\Subscribed \HasNoChildren \Drafts) "." INBOX.Drafts
S: A00000003 OK List completed (0.001 + 0.000 secs).
C: A00000004 SELECT INBOX (CONDSTORE)
S: * FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
S: * OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft \*)] Flags permitted.
S: * 21 EXISTS
S: * 0 RECENT
S: * OK [UIDVALIDITY 1513154986] UIDs valid
S: * OK [UIDNEXT 1634] Predicted next UID
S: * OK [HIGHESTMODSEQ 3293] Highest
S: A00000004 OK [READ-WRITE] Select completed (0.002 + 0.000 + 0.001 secs).
C: A00000005 UID SEARCH RETURN () UNSEEN
S: * ESEARCH (TAG "A00000005") UID
S: A00000005 OK Search completed (0.001 + 0.000 secs).
C: A00000006 LOGOUT
S: * BYE Logging out
S: A00000006 OK Logout completed (0.001 + 0.000 secs).
According to the log, the reason that MailKit's Search(SearchQuery.Unseed) returns no results is because your IMAP server is returning 0 matches.
It turns out that some IMAP servers did not implement rfc4731 correctly. Namely, they do not treat RETURN () as equivalent to RETURN (ALL). MailKit 2.11.1 will be more explicit and use RETURN (ALL) to work around this issue.

Telegraf inputs.tail with zimbra.log

I have some questions, how I can set telegraf.conf file for collect logs from the "zimbra.conf" file?
Now I tried to use this config text, but it does not work :(((
I want to send this logs to grafana
One of the lines "zimbra.conf" for example:
Oct 1 10:20:46 webmail postfix/smtp[7677]: BD5BAE9999: to=user#mail.com, relay=mo94.cloud.mail.com[92.97.907.14]:25, delay=0.73, delays=0.09/0.01/0.58/0.19, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 4C25fk2pjFz32N5)
And I do not understand exactly how works the "grok_patterns ="
[[inputs.tail]]
files = ["/var/log/zimbra.log"]
from_beginning = false
grok_patterns = ['%{SYSLOGTIMESTAMP:timestamp} %{SYSLOGHOST} %{DATA:program}(?:\[%{POSINT}\])?: %{GREEDYDATA:message}']
name_override = "zimbra_access_log"
grok_custom_pattern_files = []
grok_custom_patterns = '''
TS_UNIX %{MONTH}%{SPACE}%{MONTHDAY}%{SPACE}%{HOUR}:%{MINUTE}:%{SECOND}
TS_CUSTOM %{MONTH}%{SPACE}%{MONTHDAY} %{HOUR}:%{MINUTE}:%{SECOND}
'''
grok_timezone = "Local"
data_format = "grok"
I have copied your example line into a log file called Prueba.txt wich contains the following lines:
Oct 3 00:52:32 webmail postfix/smtp[7677]: BD5BAE9999: to=user#mail.com, relay=mo94.cloud.mail.com[92.97.907.14]:25, delay=0.73, delays=0.09/0.01/0.58/0.19, dsn=2.0.0, status=sent (250 2.0$
Oct 13 06:25:01 webmail systemd-logind[949]: New session 229478 of user zimbra.
Oct 13 06:25:02 webmail zmconfigd[27437]: Shutting down. Received signal 15
Oct 13 06:25:02 webmail systemd-logind[949]: Removed session c296.
Oct 13 06:25:03 webmail sshd[28005]: Failed password for invalid user julianne from 120.131.2.210 port 10570 ssh2
I have been able to parse the data with this configuration of the tail.input plugin:
[[inputs.tail]]
files = ["Prueba.txt"]
from_beginning = true
data_format = "grok"
grok_patterns = ['%{TIMESTAMP_ZIMBRA} %{GREEDYDATA:source} %{DATA:program}(?:\[%{POSINT}\])?: %{GREEDYDATA:message}']
grok_custom_patterns = '''
TIMESTAMP_ZIMBRA (\w{3} \d{1,2} \d{2}:\d{2}:\d{2})
'''
name_override = "log_frames"
You need to match the input string with regular expressions. For that there are some predefined patters such as GREEDYDATA = .* that you can use to match your input (another example will be NUMBER = (?:%{BASE10NUM}) BASE16NUM (?<![0-9A-Fa-f])(?:[+-]?(?:0x)?(?:[0-9A-Fa-f]+))) . You can also define your own patterns in grok_custom_patterns. Take a look at this website with some patters: https://streamsets.com/documentation/datacollector/latest/help/datacollector/UserGuide/Apx-GrokPatterns/GrokPatterns_title.html
In this case I defined a TIMESTAMP_ZIMBRA pattern for matching Oct 3 00:52:32 and Oct 03 00:52:33 alike inputs.
Here is the collected metric by Prometheus:
# HELP log_frames_delay Telegraf collected metric
# TYPE log_frames_delay untyped
log_frames_delay{delays="0.09/0.01/0.58/0.19",dsn="2.0.0",host="localhost.localdomain",message="BD5BAE9999:",path="Prueba.txt",program="postfix/smtp",relay="mo94.cloud.mail.com[92.97.907.14]:25",source="webmail",status="sent (250 2.0.0 Ok: queued as 4C25fk2pjFz32N5)",to="user#mail.com"} 0.73
P.D.: Ensure that telegraf has access to the log files.

Mailkit Fetch returns unexpected result

I am running in the following issue with MailKit. My Email Client application is in Idle(Inbox). I am adding a new email from Outlook in the Inbox and I receive CountChanged event in my client(MailKit). Inside CountChanged Event I execute
remoteFolder.Fetch(messagesCount, -1, MessageSummaryItems.All | MessageSummaryItems.UniqueId);
//where messagesCount == 467
I have a breakpoint on this line and while I am on the breakpoint, I am switching to Outlook and I delete random email from the Inbox.
After that I am running the line above. I expect Fetch to return 1 email and MessageExpunge event immediatelly after, but what happens is that Fetch returns 2 emails - with UID 468 and 464. The one with UID 464 doesn't have Envelope property set. I would like to know if this is how MailKit Fetch function is supposed to work? Should I filter the result set of Fetch command with
.Where(mailMessage.Index > messagesCount) to get only the new messages?
This below is the server log
C: A00000045 IDLE
S: + idling
S: * 468 EXISTS
C: DONE
S: A00000045 OK Idle completed (24.713 + 24.713 + 24.712 secs).
C: A00000046 FETCH 468:* (UID FLAGS INTERNALDATE RFC822.SIZE ENVELOPE)
S: * 468 FETCH (UID 20873 FLAGS (\Flagged \Seen) INTERNALDATE "25-Aug-2017 16:58:02 +0300" RFC822.SIZE 9648 ENVELOPE ("Fri, 25 Aug 2017 16:57:08 +0300" "Reset Your Zeplin Password" (("Zeplin" NIL "no-reply" "zeplin.io")) (("Zeplin" NIL "no-reply" "zeplin.io")) (("Zeplin" NIL "no-reply" "zeplin.io")) ((NIL NIL "emil.kalchev" "mobisystems.com")) NIL NIL NIL "<30339184.20170825135708.59a02cb4bee526.36618240#mail179-24.suw41.mandrillapp.com>"))
S: * 464 FETCH (MODSEQ (19343) FLAGS (\Flagged \Deleted \Seen))
S: A00000046 OK Fetch completed (0.001 + 0.000 secs).
C: A00000047 IDLE
S: + idling
S: * 464 EXPUNGE
I did a research on https://www.rfc-editor.org/rfc/rfc3501#page-73 and indeed by specification imap server can return "unilateral server decision (e.g.,
flag updates)" in FETCH response.
However I wonder why Mailkit doesn't raise MessageFlagChanged event for UID 464

How to view the IMAP flags in an email client?

We are are setting a the IMAP flags using the Java Mail API. Is there is a way to look at these flags in Thunderbird or other client for debugging purposes?
You can learn enough of IMAP to use socat to try yourself. Here's a sample exchange, I've marked my input with >, and responses with <:
$ socat READLINE ssl:imap.gmail.com:993,verify=0,crlf
< * OK Gimap ready for requests from [ip]
> a LOGIN user#gmail.com password
< * CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 UIDPLUS COMPRESS=DEFLATE ENABLE MOVE CONDSTORE ESEARCH
< a OK user#gmail.com User authenticated (Success)
> a SELECT INBOX
< * FLAGS (\Answered \Flagged \Draft \Deleted \Seen $Forwarded)
< * OK [PERMANENTFLAGS (\Answered \Flagged \Draft \Deleted \Seen $Forwarded \*)] Flags permitted.
< * OK [UIDVALIDITY 7] UIDs valid.
< * 836 EXISTS
< * 0 RECENT
< * OK [UIDNEXT 36515] Predicted next UID.
< * OK [HIGHESTMODSEQ 3346208]
< a OK [READ-WRITE] INBOX selected. (Success)
> a FETCH 810:820 (FLAGS)
< * 810 FETCH (FLAGS (\Flagged))
< * 811 FETCH (FLAGS ())
< * 812 FETCH (FLAGS (\Seen))
< * 813 FETCH (FLAGS (\Seen))
< * 814 FETCH (FLAGS (\Seen))
< * 815 FETCH (FLAGS (\Seen))
< * 816 FETCH (FLAGS (\Seen))
< * 817 FETCH (FLAGS ())
< * 818 FETCH (FLAGS ())
< * 819 FETCH (FLAGS ())
< * 820 FETCH (FLAGS ())
< a OK Success
> a LOGOUT
< * BYE LOGOUT Requested
< a OK 73 good day (Success)
You will want to at least skim RFC 3501, so that you understand UIDs and message sequence numbers, and section 6.4.5 will tell you the various things you can ask for in a FETCH command, such as flags, envelope, etc.
Each command is preceded by an arbitrary tag. I've used just a in the examples. It's intended to allow pipelining of commands and responses, so that they can be matched up.
The LOGIN command is just the username and password, and SELECT INBOX chooses the mailbox for the following commands to use. FETCH takes a sequence list (in the example, I said messages with sequence numbers between 810 and 820, and a list of items to fetch, in this case, just the flags.
Get Trojitá, it shows e-mail flags by default. I have no idea how to configure other MUAs to do the same, but I suspect many of them can do this for you as well.

Error in Basic-Authentication Login (406 Not Acceptable)

After implementing Basic-Authentication for my Jersey REST services, I'm implementing Authentication for my Client API using HTTPBasicAuthFilter.
I'm using Glassfish 3.1.2 and NetBeans.
I've followed the code written in http://javaevangelist.blogspot.pt/2012/07/jax-rs-tip-of-day-basic-client_27.html, and just changed the following parameters:
erc.setUsernamePassword("blive2", "microio") - this is the correct login
private static final String BASE_URI = "http://localhost:8080/LULServices/webresources"
webResource = client.resource(BASE_URI).path("entities.user")
So, when I run this file, the following message appears:
Mar 11, 2013 5:30:38 PM com.sun.jersey.api.client.filter.LoggingFilter log
INFO: 1 * Client out-bound request
1 > GET http://localhost:8080/LULServices/webresources/entities.user
1 > Accept: text/plain
1 > Authorization: Basic YmxpdmUyOm1pY3JvaW8=
Mar 11, 2013 5:30:38 PM com.sun.jersey.api.client.filter.LoggingFilter log
INFO: 1 * Client in-bound response
1 < 406
1 < Date: Mon, 11 Mar 2013 17:30:38 GMT
1 < Content-Length: 1231
1 < Expires: Thu, 01 Jan 1970 01:00:00 GMT
1 < Content-Type: text/html
1 < Server: GlassFish Server Open Source Edition 3.1.2.2
1 < X-Powered-By: Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1.2.2 Java/Oracle Corporation/1.7)
1 < Cache-Control: no-cache
1 < Pragma: No-cache
1 <
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>GlassFish Server Open Source Edition 3.1.2.2 - Error report</title><style type="text/css"><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 406 - Not Acceptable</h1><hr/><p><b>type</b> Status report</p><p><b>message</b>Not Acceptable</p><p><b>description</b>The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers (Not Acceptable).</p><hr/><h3>GlassFish Server Open Source Edition 3.1.2.2</h3></body></html>
Exception in thread "main" com.sun.jersey.api.client.UniformInterfaceException: GET http://localhost:8080/LULServices/webresources/entities.user returned a response status of 406 Not Acceptable
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:686)
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
at com.sun.jersey.api.client.WebResource$Builder.get(WebResource.java:507)
at lulClient.BasicAuthenticationClient$ExampleResourceClient.getMessage(BasicAuthenticationClient.java:38)
at lulClient.BasicAuthenticationClient.main(BasicAuthenticationClient.java:19)
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)
So it is the 406 Not Acceptable that appears.
Can you help me to solve it?
Thanks!
The problem is solved. The information I was asking to the service was just returned in two types: APPLICATION_JSON, or APPLICATION_XML. So I had to alter the part of the code where I inserted the type to:
javax.ws.rs.core.MediaType.APPLICATION_JSON or javax.ws.rs.core.MediaType.APPLICATION_XML.