Skip to content
Snippets Groups Projects
Commit 2af086ed authored by deuce's avatar deuce
Browse files

Handle non-existant boundary.

parent ca82770c
Branches
Tags
No related merge requests found
...@@ -21,6 +21,8 @@ function count_attachments(hdr, body) ...@@ -21,6 +21,8 @@ function count_attachments(hdr, body)
if(CT.search(/multipart\/[^\s;]*/i)!=-1) { if(CT.search(/multipart\/[^\s;]*/i)!=-1) {
var bound=CT.match(/;[\s\r\n]*boundary="{0,1}([^";\r\n]*)"{0,1}/i); var bound=CT.match(/;[\s\r\n]*boundary="{0,1}([^";\r\n]*)"{0,1}/i);
if(bound==undefined)
return(attach);
bound[1]=regex_escape(bound[1]); bound[1]=regex_escape(bound[1]);
re=new RegExp ("--"+bound[1]+"-{0,2}",""); re=new RegExp ("--"+bound[1]+"-{0,2}","");
msgbits=body.split(re); msgbits=body.split(re);
...@@ -64,61 +66,63 @@ function mime_decode(hdr, body) ...@@ -64,61 +66,63 @@ function mime_decode(hdr, body)
} }
if(CT.search(/multipart\/[^\s;]*/i)!=-1) { if(CT.search(/multipart\/[^\s;]*/i)!=-1) {
var bound=CT.match(/;[\s\r\n]*boundary="{0,1}([^";\r\n]*)"{0,1}/i); var bound=CT.match(/;[\s\r\n]*boundary="{0,1}([^";\r\n]*)"{0,1}/i);
bound[1]=regex_escape(bound[1]); if(bound!=undefined) {
re=new RegExp ("--"+bound[1]+"-{0,2}"); bound[1]=regex_escape(bound[1]);
msgbits=body.split(re); re=new RegExp ("--"+bound[1]+"-{0,2}");
/* Search for attachments/inlined */ msgbits=body.split(re);
for(bit in msgbits) { /* Search for attachments/inlined */
var pieces=msgbits[bit].split(/\r?\n\r?\n/); for(bit in msgbits) {
var disp=pieces[0].match(/content-disposition:\s+(?:attachment|inline)[;\s]*filename="?([^";\r\n]*)"?/i); var pieces=msgbits[bit].split(/\r?\n\r?\n/);
if(disp!=undefined) { var disp=pieces[0].match(/content-disposition:\s+(?:attachment|inline)[;\s]*filename="?([^";\r\n]*)"?/i);
/* Attachment */ if(disp!=undefined) {
if(Message.attachments==undefined) /* Attachment */
Message.attachments=new Array; if(Message.attachments==undefined)
Message.attachments.push(disp[1]); Message.attachments=new Array;
} Message.attachments.push(disp[1]);
disp=pieces[0].match(/content-id:\s+\<?([^\<\>;\r\n]*)\>?/i); }
if(disp!=undefined) { disp=pieces[0].match(/content-id:\s+\<?([^\<\>;\r\n]*)\>?/i);
/* Inline Attachment */ if(disp!=undefined) {
if(Message.inlines==undefined) /* Inline Attachment */
Message.inlines=new Array; if(Message.inlines==undefined)
Message.inlines.push(disp[1]); Message.inlines=new Array;
Message.inlines.push(disp[1]);
}
} }
} /* Search for HTML encoded bit */
/* Search for HTML encoded bit */ for(bit in msgbits) {
for(bit in msgbits) { var pieces=msgbits[bit].split(/(\r?\n\r?\n)/);
var pieces=msgbits[bit].split(/(\r?\n\r?\n)/); var pheads=pieces[0];
var pheads=pieces[0]; if(pheads==undefined)
if(pheads==undefined) continue;
continue; var content=pieces.slice(2).join('');
var content=pieces.slice(2).join(''); if(content==undefined)
if(content==undefined) continue;
continue; if(pheads.search(/content-type: text\/html/i)!=-1) {
if(pheads.search(/content-type: text\/html/i)!=-1) { Message.body=decode_body(TE,pheads,content);
Message.body=decode_body(TE,pheads,content); if(Message.inlines!=undefined) {
if(Message.inlines!=undefined) { for(il in Message.inlines) {
for(il in Message.inlines) { var path=http_request.virtual_path;
var path=http_request.virtual_path; var basepath=path.match(/^(.*\/)[^\/]*$/);
var basepath=path.match(/^(.*\/)[^\/]*$/); re=new RegExp("cid:("+regex_escape(Message.inlines[il])+")","ig");
re=new RegExp("cid:("+regex_escape(Message.inlines[il])+")","ig"); Message.body=Message.body.replace(re,basepath[1]+"inline.ssjs/"+template.group.number+"/"+template.sub.code+"/"+hdr.number+"/$1");
Message.body=Message.body.replace(re,basepath[1]+"inline.ssjs/"+template.group.number+"/"+template.sub.code+"/"+hdr.number+"/$1"); }
} }
Message.type="html";
return(Message);
} }
Message.type="html";
return(Message);
} }
} /* Search for plaintext bit */
/* Search for plaintext bit */ for(bit in msgbits) {
for(bit in msgbits) { var pieces=msgbits[bit].split(/(\r?\n\r?\n)/);
var pieces=msgbits[bit].split(/(\r?\n\r?\n)/); var pheads=pieces[0];
var pheads=pieces[0]; var content=pieces.slice(2).join('');
var content=pieces.slice(2).join(''); if(content==undefined)
if(content==undefined) continue;
continue; if(pheads.search(/content-type: text\/plain/i)!=-1) {
if(pheads.search(/content-type: text\/plain/i)!=-1) { Message.body=decode_body(TE,pheads,content);
Message.body=decode_body(TE,pheads,content); Message.type="plain";
Message.type="plain"; return(Message);
return(Message); }
} }
} }
} }
...@@ -202,6 +206,8 @@ function mime_get_attach(hdr, body, filename) ...@@ -202,6 +206,8 @@ function mime_get_attach(hdr, body, filename)
} }
if(CT.search(/multipart\/[^\s;]*/i)!=-1) { if(CT.search(/multipart\/[^\s;]*/i)!=-1) {
var bound=CT.match(/;[\s\r\n]*boundary="{0,1}([^";\r\n]*)"{0,1}/i); var bound=CT.match(/;[\s\r\n]*boundary="{0,1}([^";\r\n]*)"{0,1}/i);
if(bound==undefined)
return(undefined);
bound[1]=regex_escape(bound[1]); bound[1]=regex_escape(bound[1]);
re=new RegExp ("--"+bound[1]+"-{0,2}"); re=new RegExp ("--"+bound[1]+"-{0,2}");
msgbits=body.split(re); msgbits=body.split(re);
...@@ -244,6 +250,8 @@ function mime_get_cid_attach(hdr, body, cid) ...@@ -244,6 +250,8 @@ function mime_get_cid_attach(hdr, body, cid)
} }
if(CT.search(/multipart\/[^\s;]*/i)!=-1) { if(CT.search(/multipart\/[^\s;]*/i)!=-1) {
var bound=CT.match(/;[\s\r\n]*boundary="{0,1}([^";\r\n]*)"{0,1}/i); var bound=CT.match(/;[\s\r\n]*boundary="{0,1}([^";\r\n]*)"{0,1}/i);
if(bound==undefined)
return(undefined);
bound[1]=regex_escape(bound[1]); bound[1]=regex_escape(bound[1]);
re=new RegExp ("--"+bound[1]+"-{0,2}"); re=new RegExp ("--"+bound[1]+"-{0,2}");
msgbits=body.split(re); msgbits=body.split(re);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment