examples/imap-append: Set size of data to be uploaded #1011

Closed
wants to merge 1 commit into
from

Projects

None yet

4 participants

@jay
Member
jay commented Sep 14, 2016

Prior to this commit this example failed with error
'Cannot APPEND with unknown input file size'.

Bug: #1008
Reported-by: lukaszgn@users.noreply.github.com

Closes #XXXX

@jay jay examples/imap-append: Set size of data to be uploaded
Prior to this commit this example failed with error
'Cannot APPEND with unknown input file size'.

Bug: curl#1008
Reported-by: lukaszgn@users.noreply.github.com

Closes #XXXX
f6c3117
@jay jay added the IMAP label Sep 14, 2016
@mention-bot

@jay, thanks for your PR! By analyzing the annotation information on this pull request, we identified @captain-caveman2k and @bagder to be potential reviewers

@bagder
Member
bagder commented Sep 14, 2016

It seems like a fine fix to me, the question is however why it is needed. An upload should stop when a zero is returned from the read callback as that example already does, so while this fix makes the example run fine again it might also just mask a bug...

@jay
Member
jay commented Sep 14, 2016

The problem is I don't think you can do that with IMAP. I assume the example must have worked at some point and I reviewed its history but I don't see the size was ever set. IMAP send extra data seems to be knowing the continuation size and communicating it to the server beforehand, like COMMAND OPTIONS {data-byte-count}. For example right now an APPEND starts like this:
A003 APPEND "[Gmail]/Sent Mail" (\Seen) {381}<CRLF>
Then the server replies
+ any message here<CRLF>
Then upload 381 bytes

More detail from IMAP RFC for APPEND:

APPEND Command

   Arguments:  mailbox name
               OPTIONAL flag parenthesized list
               OPTIONAL date/time string
               message literal

It doesn't define 'message literal' explicitly but earlier says:

   There are two cases in which a line from the client does not
   represent a complete command.  In one case, a command argument is
   quoted with an octet count (see the description of literal in String
   under Data Formats); in the other case, the command arguments require
   server feedback (see the AUTHENTICATE command).  In either case, the
   server sends a command continuation request response if it is ready
   for the octets (if appropriate) and the remainder of the command.
   This response is prefixed with the token "+".

And literal is defined in String as:

   A literal is a sequence of zero or more octets (including CR and
   LF), prefix-quoted with an octet count in the form of an open
   brace ("{"), the number of octets, close brace ("}"), and CRLF.

So I think we have to calculate the size beforehand.

@bagder
Member
bagder commented Sep 15, 2016 edited

The problem is I don't think you can do that with IMAP

Ah, it has clearly been too long since I was hands-on with IMAP since I have totally forgotten about that detail. Then I'm in agreement with you. That's a necessary change of the example and we should even figure out somewhere where this is best documented...

@bagder
bagder approved these changes Sep 15, 2016 View changes

👍

@jay jay added a commit that closed this pull request Sep 18, 2016
@jay jay examples/imap-append: Set size of data to be uploaded
Prior to this commit this example failed with error
'Cannot APPEND with unknown input file size'.

Bug: #1008
Reported-by: lukaszgn@users.noreply.github.com

Closes #1011
45c1c54
@jay jay closed this in 45c1c54 Sep 18, 2016
@jay jay deleted the jay:fix_example_imap-append branch Sep 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment