Mailkit Fetch returns unexpected result - mailkit

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

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.

ServerSelectionTimeoutError: Time out error when connecting to Atlas via pymongo

I'm trying to connect to my Atlas mongodb database through pymongo. I make the connection and do a basic query just to count the documents and it times out.
I am able to run the same string on my personal linux (and managed to get it working from a clean Docker), but did not manage to get it working from my Mac that I use for work (and neither did my colleagues and I wasn't able to make it work in a clean Docker image either). If it matters I'm running pymongo 3.8, that I installed with pip install pymongo[tls]. I tried downgrading as well and tried also pip install pymongo[tls,srv].
Personal guesses: something to do with proxy/firewall blocking the connection maybe? I checked whether the port was open On the server I whitelisted the 0.0.0.0/0 so that shouldn't be the issue.
import pymongo
client = pymongo.MongoClient("mongodb+srv://whatever:yep#cluster0-xxxxx.mongodb.net/test?retryWrites=true")
client.test.matches.count_documents({}) # this blocks and then errors
I get the following error
/usr/local/lib/python3.7/site-packages/pymongo/collection.py in count_documents(self, filter, session, **kwargs)
1693 collation = validate_collation_or_none(kwargs.pop('collation', None))
1694 cmd.update(kwargs)
-> 1695 with self._socket_for_reads(session) as (sock_info, slave_ok):
1696 result = self._aggregate_one_result(
1697 sock_info, slave_ok, cmd, collation, session)
/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py in __enter__(self)
110 del self.args, self.kwds, self.func
111 try:
--> 112 return next(self.gen)
113 except StopIteration:
114 raise RuntimeError("generator didn't yield") from None
/usr/local/lib/python3.7/site-packages/pymongo/mongo_client.py in _socket_for_reads(self, read_preference)
1133 topology = self._get_topology()
1134 single = topology.description.topology_type == TOPOLOGY_TYPE.Single
-> 1135 server = topology.select_server(read_preference)
1136
1137 with self._get_socket(server) as sock_info:
/usr/local/lib/python3.7/site-packages/pymongo/topology.py in select_server(self, selector, server_selection_timeout, address)
224 return random.choice(self.select_servers(selector,
225 server_selection_timeout,
--> 226 address))
227
228 def select_server_by_address(self, address,
/usr/local/lib/python3.7/site-packages/pymongo/topology.py in select_servers(self, selector, server_selection_timeout, address)
182 with self._lock:
183 server_descriptions = self._select_servers_loop(
--> 184 selector, server_timeout, address)
185
186 return [self.get_server_by_address(sd.address)
/usr/local/lib/python3.7/site-packages/pymongo/topology.py in _select_servers_loop(self, selector, timeout, address)
198 if timeout == 0 or now > end_time:
199 raise ServerSelectionTimeoutError(
--> 200 self._error_message(selector))
201
202 self._ensure_opened()
ServerSelectionTimeoutError: cluster0-shard-00-01-eflth.mongodb.net:27017: timed out,cluster0-shard-00-00-eflth.mongodb.net:27017: timed out,cluster0-shard-00-02-eflth.mongodb.net:27017: timed out

TCP connection crashes after reading only a few strings

I'm working with the ESP8266 wifi module programming it in LUA using NodeMCU. I was able to connect from an iPhone app to the TCP server created by the wifi module to send 3 floats. I parse the huge string into 3 strings and send them using uart to and Arduino. It works just fine but after about 10 inputs it crashes/freezes. I need the constant flow of data to keep coming but consistently and I'm unable to do it reliably.
I've printed after each line to keep track of what is actually happening and even after that i'm still not sure what is going on.
Code
`
print("11\n")
wifi.setmode(wifi.STATION)
print("22\n")
wifi.sta.config("WDTS03","Walker14!")
print("33\n")
elWiFi =(wifi.sta.getip())
if elWiFi ~= nil then
print(wifi.sta.getip())
end
print("44\n")
if srv~=nil then
print("444\n")
srv:close()
print("555 \n")
end
print("Create server \n")
srv=net.createServer(net.TCP)
print("1\n")
if srv ~= nil then
print("srv !=nil \n")
srv:listen(6969,function(conn)
print("listening \n")
if conn ~= nil then
print("incoming\n")
conn:on("receive",function(conn,numbers)
print("2\n")
print(#numbers)
print("chekcing for nil \n")
if numbers ~= nil then
print("3\n")
p = string.find(numbers, "x=")
print("4\n")
q = string.find(numbers, "&y")
print("5\n")
if p ~= nill then
print("6\n")
if q ~= nil then
print("7\n")
x = (string.sub(numbers,p+2, q-1))
print("x=" .. x)
end
end --p ~= nill
print("8\n")
p = string.find(numbers, "y=")
print("9\n")
q = string.find(numbers, "&z")
print("10\n")
if p ~= nill then
print("11\n")
if q ~= nil then
print("12\n")
y = (string.sub(numbers,p+2, q-1))
print("y=" .. y)
end
end --p ~= nill
print("13\n")
p = string.find(numbers, "z=")
print("14\n")
q = string.find(numbers, " H")
print("15\n")
if p ~= nill then
print("16\n")
if q ~= nil then
print("17\n")
z = (string.sub(numbers,p+2, q-1))
print("z=" .. z)
end
end-- p ~= nill
print("18\n")
end --numbers ~= nil
print("54\n")
--conn:send("test\n")
end)
print("55 \n")
end
print("66 \n")
end)
print("77\n")
end
print("666\n")`
and I get the following output
11
22
33
44
Create server
1
srv !=nil
77
666
> listening
incoming
55
66
listening
incoming
55
66
listening
incoming
55
66
listening
incoming
55
66
2
338
chekcing for nil
3
4
5
6
7
x=0.1722259521484375
8
9
10
11
12
y=-0.7733306884765625
13
14
15
16
17
z=-0.5716094970703125
18
54
2
337
chekcing for nil
3
4
5
6
7
.
.--repeats a few times
.
y=-0.005340576171875
13
14
15
16
17
z=-0.9838409423828125
18
54
PANIC: unprotected error in call to Lua API (attempt to call a nil value)
�l� �=+���T2n���
NodeMCU 0.9.6 build 20150704 powered by Lua 5.1.4
11
22`
It fails on the "conn:on" argument for "srv:listen" after a few times
Thanks for the help and sorry if formatting is messed up. First time
Too long for a comment, sorry.
PANIC: unprotected error in call to Lua API (attempt to call a nil value)
Hard to tell which value was nil/null. Create a Minimal, Complete, and Verifiable Example (MCVE) to reduce the amount of code one needs to analyze.
The following snippet will eventually lead to out-of-memory due to closed upvalues. Each of your callback functions should use its own copy of the passed socket instance rather referencing the one of a wrapping callback function. The third line should NOT re-use the conn variable but define one with a new name.
See https://stackoverflow.com/a/37379426/131929 for details.
srv:listen(6969,function(conn)
if conn ~= nil then
conn:on("receive",function(conn,numbers)
NodeMCU 0.9.6 build 20150704
Don't use those old 0.9.x binaries, they're outdated and contain lots of bugs. http://nodemcu.readthedocs.io/en/latest/en/#getting-started helps you get started with a new firmware.

JavaMail client reads new messages but not existing messages

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?

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.