Syntax error in BODYSTRUCTURE. Unexpected token: [qstring: "Multipart message"] - imap

Almost 2 years ago I made this post.
Mailkit Fetch "Unexpected token in IMAP response: [qstring: "Multipart message"]"
During this time I choose GetMessage instead of Fetch.
Now, I´m testing SignalR, just to show a ProgressBar during Check Mailbox and revisiting some threads, I decided to change my code to use Fetch instead o GetMessage, the time difference to have all info I need is HUGE.
But, even upgrading Mailkit to latest version, I´m back on same issue, but this time error message changed to Syntax error in BODYSTRUCTURE. Unexpected token: [qstring: "Multipart message"]
In thread I mention, the conclusion was a problem in Mail Server, not on specific message. What I agree.
Now I sure it is a problem with outlook.office365.com
Here is the log part where Fetch fire exception
S: * 56961 FETCH (ENVELOPE ("Fri, 22 Sep 2017 14:05:47 +0000" "=?iso-8859-1?Q?Not_Fara_0000276_s=E9rie_1___-_Ped_int_0032?= =?iso-8859-1?Q?3__Ped_cli_313?=" ((NIL NIL "workflow" "kermoklast.com")) NIL NIL ((NIL NIL "fiscal" "genera.com") (NIL NIL "nfe" "kermoklast.com") (NIL NIL "kjkilber" "gmail.com") (NIL NIL "ven" "kermoklast.com") (NIL NIL "prod" "kermoklast.com") (NIL NIL "vennac" "kermoklast.com")) NIL NIL NIL "<20170922140643.FF5ED40100B#proxy.email-ssl.com>") BODYSTRUCTURE (("text" "html" ("charset" "iso-8859-1") NIL NIL "Quoted-Printable" 7170 95 NIL NIL NIL NI
By the way, yes string above ends with "NI"

Related

ExactOnline: Token is not allowed, because of invalid or empty chainId

We have a java application that connects to ExactOnline for performing the operations.
The connection works fine for almost 9days and then it will start complaining about the below exception:
"Request from start.exactonline.nl returned an error (response code: 400, response: { "error":"invalid_grant","error_description":"Token is not allowed, because of invalid or empty chainId"
After encountering this error we have to force re-authorize the application by the user to get the new accessToken.
Now I am getting the below error as well:
"Request to token endpoint https://start.exactonline.nl/api/oauth2/token"
Any help would be appreciated.
The error message it's background and the solutions are explained at https://forums.invantive.com/t/exact-online-error-token-is-not-allowed-because-of-invalid-or-empty-chainid-on-exact-online/2226

URLSession dataTask returns with no error and no data, causing SwiftyStoreKit.ReceiptError error 1

Why would the following code cause URLSession to return nil for both data and error?
let task = URLSession.shared.dataTask(with: storeRequest as URLRequest) { data, _, error -> Void in
// there is an error
if let networkError = error {
print("There was a network error")
return
}
// there is no data
guard let safeData = data else {
print("No network error, but no data either")
return
}
...
On running this code, one user hits the No network error, but no data either line.
According to Apple's docs on URLSession.dataTask:
If the request completes successfully, the data parameter of the
completion handler block contains the resource data, and the error
parameter is nil. If the request fails, the data parameter is nil and
the error parameter contain information about the failure.
I read that as: either data or error should always be non-nil. But that doesn't seem to be happening here. In what situation would both be nil?
(It if helps - the URL in question is the iTunes receipt validation API at https://buy.itunes.apple.com/verifyReceipt and the affected users are the reviewers at Apple, who are generally unwilling to assist in debug. This code is actually part of SwiftyStoreKit and it causes the error SwiftyStoreKit.ReceiptError error 1 for the reviewer - but never for anyone else.)
This could possibly depend on the HTTPURLResponse that you are ignoring in the completion handler of the dataTask (documentation for URLSession.dataTask indicates that the response, while of type URLResponse, is actually of type HTTPURLResponse - so it would have a statusCode property that would be helpful to understand the result of your request..
The request may very well have been successful, but with no data returned (ie a 204 No Content response or a 300 Redirect response). These would not have a data response, but would also not have an error response, as the request did not fail.

JODD Message parsing failed; <--- java.lang.NullPointerException

I'm using Jodd version 3.9 and I would like to read an outlook account (Microsoft Exchange).
]
int port = 993;
ImapSslServer imapServer = new ImapSslServer("mail.myhost.it", port, "authuser", "authpass");
imapServer.setProperty("mail.imap.connectiontimeout", "15000");
ReceiveMailSession session = imapServer.createSession();
session.open();
_log.info("total number of inbox emails : " + session.getMessageCount());
ReceivedEmail[] emails = session.receiveEmailAndMarkSeen(EmailFilter.filter().flag(Flags.Flag.SEEN, false));
but i get this error at the line : session.receiveEmailAndMarkSeen(...)
jodd.mail.MailException: Message parsing failed; <---
java.lang.NullPointerException
this is a debug:
A8 FETCH 4 (BODYSTRUCTURE)
* 4 FETCH (BODYSTRUCTURE (("text" "plain" ("charset" "us-ascii") NIL NIL "7bit" 1401 35 NIL NIL NIL NIL) "mixed" ("boundary" "----=_Part_1029639_1159929762.1507643405808") NIL NIL))
[ERROR] 11 ott 04:57:31.467 PM [com.afterbit.jobs.EmailJob] (mGxTfT0) EXCEPTION session.receiveEmailAndMarkSeen : jodd.mail.MailException: Message parsing failed; <--- java.lang.NullPointerException
A9 CLOSE
A8 OK FETCH completed.
A9 OK CLOSE completed.
I cannot understand why...
[SOLVED] I hope this help... and save time (i have spend many days..)
there is a conflict between javamail and apache CXF.
apache cxf has a inner file geronimo-javamail_1.4_spec-1.7.1.jar .. so if you add into your project also mail.jar (javamail) and use IMAP protocol, it can generate error like above!

AWS S3 HEAD request not returning 404 when file doesn't not exist

I'm using the following code to check if a file exists on S3. Unfortunately, I'm never getting an error. It seems to be that the AWS SDK should return an error but that it doesn't because the body is empty and cannot be deserialized in a S3 error.
How can I work around this issue? A solution would be to check myself for the 404 in the response but I don't find a way to do that with the task.
s3.headObject(headRequest).continue({ task in
task.
if let taskError = task.error {
if let error = task.error as NSError? {
if error.domain == AWSS3ErrorDomain && AWSS3ErrorType(rawValue: error.code) == AWSS3ErrorType.noSuchKey {
return successBlock(false)
}
}
errorBlock(taskError)
return nil
}
return successBlock(true)
});
(The same issue arises if the error is a 403)
The issue here is that you will never receive a Body because a HEAD request is designed not to return one.
RFC7230 - Section 3.3
Responses to the HEAD request method (Section 4.3.2
of [RFC7231]) never include a message body because the associated
response header fields (e.g., Transfer-Encoding, Content-Length,
etc.), if present, indicate only what their values would have been if
the request method had been GET (Section 4.3.1 of [RFC7231]).
However, you can still get an HTTP status code, which should indicate the state of any error which occurred.

IMAP attachment retrieving command

I am working on a mail client using IMAP and I am looking for the command for receiving the attachments of a message.
All message info is retrieved using the FETCH command. You have two options on how to use it, however.
First, you can retrieve the entire email message, verbatim. In that case, you're going to need to include a MIME parser in your client to figure out the structure of the message. (Each platform has at least one or two popular MIME parsers; since you haven't told us what you're coding in, I can't recommend one for you.) Once you get the message structure from your MIME parser, you'll need some client logic to determine which parts are attachments. It's worth looking at RFC 2183 to get you started. In general, parts with a Content-Disposition starting with "attachment" are going to be attachments, but all mail client authors go through a phase of trial and error getting it right. In order to download the entire email message, you'd issue the IMAP command
$ UID FETCH <uid> BODY.PEEK[]
Second, you can have the IMAP server parse the message structure for you by issuing a FETCH BODYSTRUCTURE (note: no square brackets). You'll have to parse the returned BODYSTRUCTURE data yourself; the IMAP RFC explains the format and gives a few examples.
# message, no attachments:
("TEXT" "PLAIN" ("CHARSET" "ISO-8859-1" "FORMAT" "flowed") NIL NIL "7BIT" 1469 50 NIL NIL NIL NIL)
# message, one attachment
(("TEXT" "PLAIN" ("CHARSET" "US-ASCII") NIL NIL "QUOTED-PRINTABLE" 56 1 NIL NIL NIL NIL)("AUDIO" "X-WAV" ("NAME" "voicemail.wav") NIL NIL "BASE64" 152364 NIL ("attachment" ("FILENAME" "voicemail.wav")) NIL NIL) "MIXED" ("BOUNDARY" "----_=_NextPart_001_01C4ACB3.5AA7B8E2") NIL NIL NIL)
Once you've determined which parts you're interested in, you can issue a FETCH for the displayable message body. Your client can then just list the message attachments (parsed out of the BODY response) and can then go back and FETCH them if the user clicks on them. So the IMAP commands you'd be issuing would be along the lines of:
$ UID FETCH <uid> (BODY ENVELOPE) # get structure and header info
$ UID FETCH <uid> (BODY[1]) # retrieving displayable body
$ UID FETCH <uid> (BODY[2]) # retrieving attachment on demand
I believe what you are looking for is the IMAP v4 FETCH command.
You could use Context.IO's files resource to quickly and easily fetch attachments.
http://context.io/docs/2.0/accounts/files#get

Resources