[QtMoko] qtmail send fails if username too long

Eric Ehlers eric.ehlers at nazcatech.be
Thu Jan 12 22:42:35 CET 2012

hi all,

in qtmail, email send fails if username + password exceeds a certain
length.  in my particular case the problem can be resolved by increasing
the buffer size.  is this a fix that could be applied to the repository?

i am using IMAP, patched for SSL support as documented here:

i am running the code from git tag v37_gta02.

my email address is in the format firstname.lastname at domain.tld.  my
server is configured such that the user name is firstname.lastname
+domain.tld.  in other words, to get the user name, you take the email
address and replace the @ with a +.

in file qtmoko/src/tools/messageserver/smtpclient.cpp, lines 382-383, it

    QString temp = _config.smtpUsername() + '\0' +
        _config.smtpUsername() + '\0' + _config.smtpPassword();
    temp = _toBase64(temp);

my user name firstname.lastname+domain.tld is 24 characters long and my
password is 8 characters long so after the first line above the value of
temp is 24 + 1 + 24 + 1 + 8 = 58 characters long.

the call to _toBase64 goes into src/libraries/qtopiamail/qmailcodec.cpp
and the relevant code there is:

    lines 31-32:

      // Must be an even multiple of 4:
      int QTOPIAMAIL_EXPORT Base64MaxLineLength = 76;

    lines 434-436:

      // Each encoded line will contain 76 output chars - 57 input chars
      if (_maximumLineLength <= 0)
          _maximumLineLength = Base64MaxLineLength;

_toBase64 takes the input string and encodes it.  if the input string is
<= 57 characters then the output string is <= 76 characters.  in my case
the input string is 58 characters so the code inserts a ^M and the
encoded value that gets returned is 76 characters + ^M + 4 characters.

comments in the code suggest that the ^M is part of the SMTP RFC.  in my
case this linebreak causes the send to fail.  i don't know anything
about SMTP but my humble guess is that my mail server is OK and that
qtmail's implementation of the RFC is wrong.

in my case the fix is simple:

        // Must be an even multiple of 4:
        //int QTOPIAMAIL_EXPORT Base64MaxLineLength = 76;
        int QTOPIAMAIL_EXPORT Base64MaxLineLength = 80;

i patched this on to my phone and now i am sending mail successfully.
but if the RFC really does say that the encoded string requires a
linebreak after 76 characters, then either qtmail is inserting that ^M
incorrectly, or else my mail server does not conform to the RFC...

does anybody know what the correct solution is?

many thanks,

More information about the community mailing list