Last active
December 22, 2015 03:48
-
-
Save andris9/6412439 to your computer and use it in GitHub Desktop.
Gmail IMAP bug example testcase. If run, the output should include an invalid BODYSTRUCTURE string for message/rfc822 attachments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// GMAIL BUG: | |
// If a message has an message/rfc822 attachment then In-Reply-To value in the embedded envelope | |
// is forced to string even if the value was missing (the value is "NIL" instead of NIL) | |
// Usage: this is a node.js script, so you should have node installed (www.nodejs.org) | |
// replace USERNAME and PASSWORD values and run `node gmail-test.js` | |
// the output of this script is an IMAP log, see below for an example | |
// this script appends and removes a message with message/rfc822 attachments | |
var tls = require("tls"); | |
var USERNAME = "[email protected]", | |
PASSWORD = "password"; | |
var message = | |
"MIME-Version: 1.0\r\n"+ | |
"From: [email protected]\r\n"+ | |
"To: [email protected]\r\n"+ | |
"Content-Type: multipart/mixed;\r\n"+ | |
" boundary=\"----mailcomposer-?=_1-1328088797399\"\r\n"+ | |
"Message-Id: <testmessage-for-bug>;\r\n"+ | |
"\r\n"+ | |
"------mailcomposer-?=_1-1328088797399\r\n"+ | |
"Content-Type: message/rfc822\r\n"+ | |
"Content-Transfer-Encoding: 7bit\r\n"+ | |
"\r\n"+ | |
"MIME-Version: 1.0\r\n"+ | |
"From: [email protected]\r\n"+ | |
"To: [email protected]\r\n"+ | |
"In-Reply-To: <test1>\r\n"+ | |
"\r\n"+ | |
"Hello world!\r\n"+ | |
"------mailcomposer-?=_1-1328088797399\r\n"+ | |
"Content-Type: message/rfc822\r\n"+ | |
"Content-Transfer-Encoding: 7bit\r\n"+ | |
"\r\n"+ | |
"MIME-Version: 1.0\r\n"+ | |
"From: [email protected]\r\n"+ | |
"To: [email protected]\r\n"+ | |
"\r\n"+ | |
"Hello world!\r\n"+ | |
"------mailcomposer-?=_1-1328088797399\r\n"+ | |
"Content-Type: text/html; charset=utf-8\r\n"+ | |
"Content-Transfer-Encoding: quoted-printable\r\n"+ | |
"\r\n"+ | |
"<b>Hello world!</b>\r\n"+ | |
"------mailcomposer-?=_1-1328088797399--"; | |
var commands = [ | |
"a1 LOGIN "+USERNAME+" "+PASSWORD, | |
"a2 CAPABILITY", | |
"a3 LIST \"\" \"*\"", | |
"a4 LSUB \"\" \"*\"", | |
"a5 SELECT INBOX", | |
"a6 APPEND INBOX {" + (message.length) + "}", | |
message, | |
"a7 LOGOUT" | |
]; | |
var socket = tls.connect(993, "imap.gmail.com", function(){ | |
socket.pipe(process.stdout); | |
socket.on("data", function(data){ | |
var command, appendUID; | |
if((appendUID = data.toString().match(/APPENDUID \d+ (\d+)/))){ | |
appendUID = appendUID[1]; | |
command = "af UID FETCH " + appendUID + " (ENVELOPE BODYSTRUCTURE)"; | |
commands.unshift("ad UID STORE " + appendUID + " +FLAGS (\\Deleted)"); | |
commands.unshift("ae EXPUNGE"); | |
}else{ | |
command = commands.shift() | |
} | |
if(command){ | |
socket.write(command + "\r\n"); | |
} | |
}); | |
}); | |
/* | |
RESPONSE | |
ENVELOPE: | |
( | |
"Mon, 2 Sep 2013 05:30:13 -0700 (PDT)" | |
NIL | |
((NIL NIL "andris" "kreata.ee")) | |
((NIL NIL "andris" "kreata.ee")) | |
((NIL NIL "andris" "kreata.ee")) | |
((NIL NIL "andris" "tr.ee")) | |
NIL | |
NIL | |
NIL <-- NB! in-Reply-To not set, so this value is NIL | |
"<-4730417346358914070@unknownmsgid>" | |
) | |
BODYSTRUCTURE: | |
( | |
("MESSAGE" "RFC822" NIL NIL NIL "7BIT" 105 | |
( | |
NIL NIL | |
((NIL NIL "andris" "kreata.ee")) | |
((NIL NIL "andris" "kreata.ee")) | |
((NIL NIL "andris" "kreata.ee")) | |
((NIL NIL "andris" "pangalink.net")) | |
NIL | |
NIL | |
"<test1>" <--- NB! In-Reply-To value was <test1>, so this is OK | |
NIL | |
) | |
("TEXT" "PLAIN" NIL NIL NIL "7BIT" 12 0 NIL NIL NIL) | |
5 NIL NIL NIL) | |
("MESSAGE" "RFC822" NIL NIL NIL "7BIT" 83 | |
( | |
NIL NIL | |
((NIL NIL "andris" "kreata.ee")) | |
((NIL NIL "andris" "kreata.ee")) | |
((NIL NIL "andris" "kreata.ee")) | |
((NIL NIL "andris" "pangalink.net")) | |
NIL | |
NIL | |
"NIL" <-- NB! Here is a bug! Should be NIL (null value) instead of "NIL" (string value) | |
NIL | |
) | |
("TEXT" "PLAIN" NIL NIL NIL "7BIT" 12 0 NIL NIL NIL) | |
4 NIL NIL NIL | |
) | |
("TEXT" "HTML" ("CHARSET" "utf-8") NIL NIL "QUOTED-PRINTABLE" 19 0 NIL NIL NIL) | |
"MIXED" | |
("BOUNDARY" "----mailcomposer-?=_1-1328088797399") | |
NIL | |
NIL | |
) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment