New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IMAP custom FETCH breaks when a message contains a line beginning with '+ ' #486

Closed
ehlertjd opened this Issue Oct 13, 2015 · 0 comments

Comments

Projects
None yet
3 participants
@ehlertjd
Contributor

ehlertjd commented Oct 13, 2015

When retrieving message contents via CURLOPT_CUSTOM_REQUEST, a message with a line beginning with '+ ' can cause the request to fail with the error "FTP: weird server reply".
Running in verbose, curl prints out "Unexpected continuation response", which is can be found in imap_endofresp.

This appears to be due to custom commands being treated as LIST instead of FETCH in this instance, so curl continues to do extra processing on the body.

Message to reproduce:

To: <test@example.org>
From: <test@example.org>(Example User)
Subject: IMAP Bogus message

+ This line breaks IMAP custom command processing.

Code to reproduce:

#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>

#define USERNAME "username"
#define PASSWORD "password"
#define SERVER_URL "imap://mail.example.org/"

// This is the UID of the message that contains a line beginning with "+ "
#define BAD_MESSAGE_UID "2358"
#define FETCH_COMMAND "UID FETCH " BAD_MESSAGE_UID " (UID BODY.PEEK[1])"

int main(void) {
    CURL *curl;
    CURLcode res;

    curl = curl_easy_init();
    if( curl ) {
        curl_easy_setopt(curl, CURLOPT_USERNAME, USERNAME);
        curl_easy_setopt(curl, CURLOPT_PASSWORD, PASSWORD);

        curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
        curl_easy_setopt(curl, CURLOPT_URL, SERVER_URL "INBOX");

        // Do the request
        curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, FETCH_COMMAND);
        res = curl_easy_perform(curl);
        if( res != CURLE_OK ) {
            fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
        }

        curl_easy_cleanup(curl);
    }

    return res;
}

Relevant output:

> A003 SELECT INBOX
< * FLAGS (\Answered \Flagged \Deleted \Seen \Draft $NotJunk $Junk JunkRecorded $Forwarded NotJunk)
< * OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft $NotJunk $Junk JunkRecorded $Forwarded NotJunk \*)] Flags permitted.
< * 407 EXISTS
< * 0 RECENT
< * OK [UIDVALIDITY 1418849919] UIDs valid
< * OK [UIDNEXT 2359] Predicted next UID
< * OK [HIGHESTMODSEQ 7503] Highest
< A003 OK [READ-WRITE] Select completed (0.000 secs).
> A004 UID FETCH 2358 (UID BODY.PEEK[1])
< * 407 FETCH (UID 2358 BODY[1] {52}
* 407 FETCH (UID 2358 BODY[1] {52}
< + This line breaks IMAP custom command processing.
* Unexpected continuation response
> A005 LOGOUT
< )
< A004 OK Fetch completed.
< * BYE Logging out
< A005 OK Logout completed.
* Closing connection 0
curl_easy_perform() failed: FTP: weird server reply

ehlertjd pushed a commit to ehlertjd/curl that referenced this issue Oct 13, 2015

ehlertjd pushed a commit to ehlertjd/curl that referenced this issue Oct 13, 2015

ehlertjd added a commit to ehlertjd/curl that referenced this issue Oct 13, 2015

@bagder bagder added the IMAP label Nov 5, 2015

captain-caveman2k added a commit that referenced this issue Nov 8, 2015

@lock lock bot locked as resolved and limited conversation to collaborators May 7, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.