mime-js

Create MIME message from browser, fork of https://github.com/ikr0m/mime-js
git clone git://git.defalsify.org/mime-js.git
Log | Files | Refs | LICENSE

commit 9096dd7b1226df4749bc636b76f5e76d2cc67c8f
parent eb1eeb53e91e9ce7910555bc6d600fbc6e7c65c2
Author: Xavier Guimard <x.guimard@free.fr>
Date:   Sun,  4 Oct 2015 08:41:43 +0200

Add "text only" feature

Diffstat:
Mdist/mime-js.js | 14+++++++++-----
Mdist/mime-js.min.js | 4++--
Msrc/mime-js.coffee | 14+++++++++-----
3 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/dist/mime-js.js b/dist/mime-js.js @@ -10,7 +10,7 @@ (function() { window.Mime = (function() { var MailParser, _util, buildMimeObj, toMimeObj, toMimeTxt; - toMimeTxt = function(mail) { + toMimeTxt = function(mail, txtOnly) { var alternative, attaches, cids, createAlternative, createAttaches, createCids, createHtml, createMixed, createPlain, createRelated, getBoundary, htm, linkify, plain, related, result; linkify = function(inputText) { var replacePattern1, replacePattern2, replacePattern3, replacedText; @@ -110,10 +110,14 @@ return (mimeStr + '\n--' + boundary + '--').replace(/\n/g, '\r\n'); }; plain = createPlain(mail.body); - htm = createHtml(mail); - alternative = createAlternative(plain, htm); - cids = createCids(mail.cids); - related = createRelated(alternative, cids); + if (txtOnly) { + related = plain; + } else { + htm = createHtml(mail); + alternative = createAlternative(plain, htm); + cids = createCids(mail.cids); + related = createRelated(alternative, cids); + } attaches = createAttaches(mail.attaches); result = createMixed(related, attaches); return result; diff --git a/dist/mime-js.min.js b/dist/mime-js.min.js @@ -1 +1 @@ -(function(){window.Mime=function(){var e,n,t,r,u;return u=function(e){var n,t,r,u,a,o,i,c,s,l,d,p,f,m,g,h;return f=function(e){var n,t,r,u;return n=/(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim,u=e.replace(n,'<a href="$1" target="_blank">$1</a>'),t=/(^|[^\/])(www\.[\S]+(\b|$))/gim,u=u.replace(t,'$1<a href="http://$2" target="_blank">$2</a>'),r=/(([a-zA-Z0-9\-\_\.])+@[a-zA-Z\_]+?(\.[a-zA-Z]{2,6})+)/gim,u=u.replace(r,'<a href="mailto:$1">$1</a>')},d=function(){var e;return e=function(){return Math.random().toString(36).slice(2)},e()+e()},s=function(e){return null==e&&(e=""),"\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: base64\n\n"+Base64.encode(e,!0).replace(/.{76}/g,"$&\n")},i=function(e){var n;return n=e.body||"",n=n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/,"&gt;").replace(/\n/g,"\n<br/>"),n=f(n),n="<div>"+n+"</div>","\nContent-Type: text/html; charset=UTF-8\nContent-Transfer-Encoding: base64\n\n"+Base64.encode(n,!0).replace(/.{76}/g,"$&\n")},u=function(e,n){var t;return t=d(),"\nContent-Type: multipart/alternative; boundary="+t+"\n\n--"+t+e+"\n\n--"+t+n+"\n\n--"+t+"--"},o=function(e){var n,t,r,u,a,o,i,c;if(e){for(r=[],a=0,o=e.length;o>a;a++)t=e[a],c=t.type,i=t.name,n=t.base64,u=d(),r.push("\nContent-Type: "+c+'; name="'+i+'"\nContent-Transfer-Encoding: base64\nContent-ID: <'+u+">\nX-Attachment-Id: "+u+"\n\n"+n);return r}},l=function(e,n){var t,r,u,a,o;for(null==n&&(n=[]),t=d(),o="\nContent-Type: multipart/related; boundary="+t+"\n\n--"+t+e,u=0,a=n.length;a>u;u++)r=n[u],o+="\n--"+t+r;return o+"\n--"+t+"--"},a=function(e){var n,t,r,u,a,o,i,c;if(e){for(i=[],u=0,a=e.length;a>u;u++)n=e[u],c=n.type,o=n.name,t=n.base64,r=d(),i.push("\nContent-Type: "+c+'; name="'+o+'"\nContent-Disposition: attachment; filename="'+o+'"\nContent-Transfer-Encoding: base64\nX-Attachment-Id: '+r+"\n\n"+t);return i}},c=function(n,t){var r,u,a,o,i,c,s,l;for(u=d(),l="",e.subject&&(l="=?UTF-8?B?"+Base64.encode(e.subject,!0)+"?="),c="=?UTF-8?B?"+Base64.encode(e.fromName||"",!0)+"?=",a=(new Date).toGMTString().replace(/GMT|UTC/gi,"+0000"),s="MIME-Version: 1.0\nDate: "+a+"\nMessage-ID: <"+d()+"@mail.your-domain.com>\nSubject: "+l+"\nFrom: "+c+" <"+e.from+">\nTo: "+e.to+"\nCc: "+e.cc+"\nContent-Type: multipart/mixed; boundary="+u+"\n\n--"+u+n,o=0,i=t.length;i>o;o++)r=t[o],s+="\n--"+u+r;return(s+"\n--"+u+"--").replace(/\n/g,"\r\n")},m=s(e.body),p=i(e),n=u(m,p),r=o(e.cids),g=l(n,r),t=a(e.attaches),h=c(g,t)},e=function(e){var t,r,u,a,o,i,c,s;r=function(e){var t,u,a,o,i,c,s,l,d,p,f,m,g,h,b,C;if(l=e.indexOf("\r\n\r\n"),-1===l&&(e=e.replace(/\n/g,"\r\n"),l=e.indexOf("\r\n\r\n"),-1===l&&(l=e.length)),p=e.slice(0,l).replace(/\r\n\s+/g," ")+"\r\n",d=e.slice(l).replace(/(\r\n)+$/,"").replace(/^(\r\n)+/,""),c="",h=p.match(/Content-Type: (.*)/i),h&&h.length>0?c=h[1]:console.log("Warning: MailParser: Content-type doesn't exist!"),s=c.split(";"),m=s[0].replace(/\s/g,""),g=m.split("/"),"multipart"===g[0].toLowerCase())for(o=[],f=s[1].match(/boundary="?([^"]*)"?/i),!f&&s[2]&&(f=s[2].match(/boundary="?([^"]*)"?/i)),i=n.trim(f[1]).replace(/"/g,""),t=i.replace(/\+/g,"\\+"),b=new RegExp("--"+t,"g"),o=d.replace(b,i).replace(b,i).split(i),o.shift(),o.pop(),u=0;u<o.length;)o[u]=o[u].replace(/(\r\n)+$/,"").replace(/^(\r\n)+/,""),o[u]=r(o[u]),u++;else if(a=d,"text"===g[0]&&(a=a.replace(RegExp("=\\r\\n","g"),""),C=a.match(RegExp("=[A-F0-9][A-F0-9]","g"))))for(u=0;u<C.length;)a=a.replace(C[u],String.fromCharCode(parseInt(C[u].replace(RegExp("="),""),16))),u++;return{rawHeaders:p,rawBody:d,body:a,contentType:c,contentTypeParts:s,boundary:i,bodyParts:o,mimeType:m,mimeTypeParts:g}},o="";try{o=r(e)}catch(l){}return i=o.rawHeaders,a=function(e){return null==e&&(e=[]),e[1]||""},c=a(/\r\nSubject: (.*)\r\n/g.exec(i)),s=a(/\r\nTo: (.*)\r\n/g.exec(i)),t=a(/\r\nCc: (.*)\r\n/g.exec(i)),u=a(/\r\nFrom: (.*)\r\n/g.exec(i)),{messageParts:o,subject:c,to:s,cc:t,from:u}},n=function(){var e,t,r,u,a,o,i,c;return i=function(e){return null==e&&(e=""),("function"==typeof e.trim?e.trim():void 0)||e.replace(/^\s+|\s+$/g,"")},u=function(n,t){var r;return null==n&&(n=""),null==t&&(t=""),t=t.toLowerCase(),r=function(){switch(!1){case-1===t.indexOf("koi8-r"):return e(n);case-1===t.indexOf("utf-8"):return Base64._utf8_decode(n);case-1===t.indexOf("windows-1251"):return c(n);default:return n}}()},t=function(e){return e.replace(/\=[\r\n]+/g,"").replace(/\=[0-9A-F]{2}/gi,function(e){return String.fromCharCode(parseInt(e.substr(1),16))})},e=function(e){var n,t,r,u,a,o,i;for(n=unescape("%u2500%u2502%u250C%u2510%u2514%u2518%u251C%u2524%u252C%u2534%u253C%u2580%u2584%u2588%u258C%u2590%u2591%u2592%u2593%u2320%u25A0%u2219%u221A%u2248%u2264%u2265%u00A0%u2321%u00B0%u00B2%u00B7%u00F7%u2550%u2551%u2552%u0451%u2553%u2554%u2555%u2556%u2557%u2558%u2559%u255A%u255B%u255C%u255D%u255E%u255F%u2560%u2561%u0401%u2562%u2563%u2564%u2565%u2566%u2567%u2568%u2569%u256A%u256B%u256C%u00A9%u044E%u0430%u0431%u0446%u0434%u0435%u0444%u0433%u0445%u0438%u0439%u043A%u043B%u043C%u043D%u043E%u043F%u044F%u0440%u0441%u0442%u0443%u0436%u0432%u044C%u044B%u0437%u0448%u044D%u0449%u0447%u044A%u042E%u0410%u0411%u0426%u0414%u0415%u0424%u0413%u0425%u0418%u0419%u041A%u041B%u041C%u041D%u041E%u041F%u042F%u0420%u0421%u0422%u0423%u0416%u0412%u042C%u042B%u0417%u0428%u042D%u0429%u0427%u042A"),t=function(e){return e>=128&&255>=e?n.charAt(e-128):String.fromCharCode(e)},o="",r=u=0,a=e.length;a>u;r=++u)i=e[r],o+=t(e.charCodeAt(r));return o},c=function(e){var n,t,r,u,a,o,i;for(null==e&&(e=""),o="",n=r=0,u=e.length;u>r;n=++r)i=e[n],t=e.charCodeAt(n),a=function(){switch(!1){case 168!==t:return 1025;case 184!==t:return 1105;case!(t>191&&256>t):return t+848;default:return t}}(),o+=String.fromCharCode(a);return o},r=function(e,r){var a,o,i;return e=n.trim(e),o=void 0,a=void 0,i=void 0,(i=e.match(/^\=\?([\w_\-]+)\?([QqBb])\?([^\?]*)\?\=$/i))?(o=i[1],a=(i[2]||"Q").toString().toUpperCase(),e=(i[3]||"").replace(/_/g," "),"B"===a?Base64.decode(e,r):"Q"===a?t(e):e):u(e,r)},a=function(e,n){return e=(e||"").toString().replace(/(=\?[^?]+\?[QqBb]\?[^?]+\?=)\s+(?==\?[^?]+\?[QqBb]\?[^?]*\?=)/g,"$1").replace(/\=\?([\w_\-]+)\?([QqBb])\?[^\?]*\?\=/g,function(e,n,t){return r(e)}.bind(this)),u(e,n)},o=function(e){return null==e&&(e=""),(e+"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")},{decode:u,KOIRDec:e,win1251Dec:c,decodeMimeWords:a,toHtmlEntity:o,trim:i}}(),t=function(t){var u,a,o,i,c,s,l,d,p,f,m,g;f={html:"",text:"",attaches:[],innerMsgs:[],to:n.decodeMimeWords(t.to),cc:n.decodeMimeWords(t.cc),from:n.decodeMimeWords(t.from),subject:n.decodeMimeWords(t.subject)},a=function(e,t){var r,u,a;return a=/Content-Transfer-Encoding: quoted-printable/i.test(t),u=/Content-Transfer-Encoding: base64/i.test(t),u?(e=e.replace(/\s/g,""),r="function"==typeof atob?atob(e):void 0,null==r&&(r=Base64.decode(e)),e=r):a&&(e=n.QPDec(e)),e},d=function(t){var u,o,i,c,s,l,p,m,g,h,b,C,y,x,T,v,w,B,A,E,M,D,F,$,O;if(t){for(h=0,C=t.length;C>h;h++)if(w=t[h],x=(null!=(A=w.mimeType)?A:"").toLowerCase(),-1===x.indexOf("multipart"))if(-1===x.indexOf("message/rfc822"))if(B=w.rawHeaders,c=-1!==B.indexOf("Content-Disposition: attachment"),o=w.rawBody,l=/text\/html/.test(x),m=/text\/plain/.test(x),p=/image/.test(x),s=/audio/.test(x),c||p||s){for(g=/Content-Transfer-Encoding: quoted-printable/i.test(B),g&&(o=n.QPDec(o),o=btoa?btoa(o):Base64.encode(o)),E=w.contentTypeParts,b=0,y=E.length;y>b;b++)if(O=E[b],/name=/i.test(O)){T=O.replace(/(.*)=/,"").replace(/"|'/g,"");break}T||(T=p?"image":s?"audio":"attachment",T+="_"+Math.floor(100*Math.random()),F=x.indexOf("/"),$=x.substring(F+1),$.length<4&&(T+="."+$)),D=/(.*)content-id:(.*)<(.*)>/i,u={type:x,base64:o,name:T,cid:null!=(M=D.exec(B))?M[3]:void 0,visible:/png|jpeg|jpg|gif/.test(x)},f.attaches.push(u)}else l||m?(o=a(o,B),o=n.decode(o,w.contentType),l&&(f.html+=o),m&&(f.text+=o)):console.log("Unknown mime type: "+x);else v=e(w.rawBody),i=r(v),f.innerMsgs.push(i);else d(w.bodyParts);return null}};try{if(p=t.messageParts,!p)return f;l=(p.mimeType||"").toLowerCase(),c=/text\/plain/.test(l),i=/text\/html/.test(l),-1!==l.indexOf("multipart")?d(p.bodyParts):c||i?(u=a(p.body,p.rawHeaders),u=n.decode(u,p.contentType),i&&(f.html=u),c&&(f.text=u)):console.log("Warning: mime type isn't supported! mime="+l)}catch(h){throw o=h,new Error(o)}return g=function(e){return"<pre>"+n.toHtmlEntity(e)+"</pre>"},s=function(e){var t,r,u,a,o,i,c,l;if(u=e.innerMsgs,null!=u?u.length:void 0)for(!n.trim(e.html)&&e.text&&(e.html+=g(e.text)),a=0,o=u.length;o>a;a++)r=u[a],i=s(r),l=i.text,t=i.html,t?e.html+=t:l&&(e.html+=wrapPerTag(l),e.text+=l),(null!=(c=i.attaches)?c.length:void 0)>0&&(e.attaches=e.attaches.concat(i.attaches));return e},m=s(f)},r=function(n){var r,u;return u=e(n),r=t(u)},{toMimeTxt:u,toMimeObj:r}}()}).call(this); -\ No newline at end of file +(function(){window.Mime=function(){var e,n,t,r,u;return u=function(e,n){var t,r,u,a,o,i,c,s,l,d,p,f,m,g,h,b;return m=function(e){var n,t,r,u;return n=/(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim,u=e.replace(n,'<a href="$1" target="_blank">$1</a>'),t=/(^|[^\/])(www\.[\S]+(\b|$))/gim,u=u.replace(t,'$1<a href="http://$2" target="_blank">$2</a>'),r=/(([a-zA-Z0-9\-\_\.])+@[a-zA-Z\_]+?(\.[a-zA-Z]{2,6})+)/gim,u=u.replace(r,'<a href="mailto:$1">$1</a>')},p=function(){var e;return e=function(){return Math.random().toString(36).slice(2)},e()+e()},l=function(e){return null==e&&(e=""),"\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: base64\n\n"+Base64.encode(e,!0).replace(/.{76}/g,"$&\n")},c=function(e){var n;return n=e.body||"",n=n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/,"&gt;").replace(/\n/g,"\n<br/>"),n=m(n),n="<div>"+n+"</div>","\nContent-Type: text/html; charset=UTF-8\nContent-Transfer-Encoding: base64\n\n"+Base64.encode(n,!0).replace(/.{76}/g,"$&\n")},a=function(e,n){var t;return t=p(),"\nContent-Type: multipart/alternative; boundary="+t+"\n\n--"+t+e+"\n\n--"+t+n+"\n\n--"+t+"--"},i=function(e){var n,t,r,u,a,o,i,c;if(e){for(r=[],a=0,o=e.length;o>a;a++)t=e[a],c=t.type,i=t.name,n=t.base64,u=p(),r.push("\nContent-Type: "+c+'; name="'+i+'"\nContent-Transfer-Encoding: base64\nContent-ID: <'+u+">\nX-Attachment-Id: "+u+"\n\n"+n);return r}},d=function(e,n){var t,r,u,a,o;for(null==n&&(n=[]),t=p(),o="\nContent-Type: multipart/related; boundary="+t+"\n\n--"+t+e,u=0,a=n.length;a>u;u++)r=n[u],o+="\n--"+t+r;return o+"\n--"+t+"--"},o=function(e){var n,t,r,u,a,o,i,c;if(e){for(i=[],u=0,a=e.length;a>u;u++)n=e[u],c=n.type,o=n.name,t=n.base64,r=p(),i.push("\nContent-Type: "+c+'; name="'+o+'"\nContent-Disposition: attachment; filename="'+o+'"\nContent-Transfer-Encoding: base64\nX-Attachment-Id: '+r+"\n\n"+t);return i}},s=function(n,t){var r,u,a,o,i,c,s,l;for(u=p(),l="",e.subject&&(l="=?UTF-8?B?"+Base64.encode(e.subject,!0)+"?="),c="=?UTF-8?B?"+Base64.encode(e.fromName||"",!0)+"?=",a=(new Date).toGMTString().replace(/GMT|UTC/gi,"+0000"),s="MIME-Version: 1.0\nDate: "+a+"\nMessage-ID: <"+p()+"@mail.your-domain.com>\nSubject: "+l+"\nFrom: "+c+" <"+e.from+">\nTo: "+e.to+"\nCc: "+e.cc+"\nContent-Type: multipart/mixed; boundary="+u+"\n\n--"+u+n,o=0,i=t.length;i>o;o++)r=t[o],s+="\n--"+u+r;return(s+"\n--"+u+"--").replace(/\n/g,"\r\n")},g=l(e.body),n?h=g:(f=c(e),t=a(g,f),u=i(e.cids),h=d(t,u)),r=o(e.attaches),b=s(h,r)},e=function(e){var t,r,u,a,o,i,c,s;r=function(e){var t,u,a,o,i,c,s,l,d,p,f,m,g,h,b,C;if(l=e.indexOf("\r\n\r\n"),-1===l&&(e=e.replace(/\n/g,"\r\n"),l=e.indexOf("\r\n\r\n"),-1===l&&(l=e.length)),p=e.slice(0,l).replace(/\r\n\s+/g," ")+"\r\n",d=e.slice(l).replace(/(\r\n)+$/,"").replace(/^(\r\n)+/,""),c="",h=p.match(/Content-Type: (.*)/i),h&&h.length>0?c=h[1]:console.log("Warning: MailParser: Content-type doesn't exist!"),s=c.split(";"),m=s[0].replace(/\s/g,""),g=m.split("/"),"multipart"===g[0].toLowerCase())for(o=[],f=s[1].match(/boundary="?([^"]*)"?/i),!f&&s[2]&&(f=s[2].match(/boundary="?([^"]*)"?/i)),i=n.trim(f[1]).replace(/"/g,""),t=i.replace(/\+/g,"\\+"),b=new RegExp("--"+t,"g"),o=d.replace(b,i).replace(b,i).split(i),o.shift(),o.pop(),u=0;u<o.length;)o[u]=o[u].replace(/(\r\n)+$/,"").replace(/^(\r\n)+/,""),o[u]=r(o[u]),u++;else if(a=d,"text"===g[0]&&(a=a.replace(RegExp("=\\r\\n","g"),""),C=a.match(RegExp("=[A-F0-9][A-F0-9]","g"))))for(u=0;u<C.length;)a=a.replace(C[u],String.fromCharCode(parseInt(C[u].replace(RegExp("="),""),16))),u++;return{rawHeaders:p,rawBody:d,body:a,contentType:c,contentTypeParts:s,boundary:i,bodyParts:o,mimeType:m,mimeTypeParts:g}},o="";try{o=r(e)}catch(l){}return i=o.rawHeaders,a=function(e){return null==e&&(e=[]),e[1]||""},c=a(/\r\nSubject: (.*)\r\n/g.exec(i)),s=a(/\r\nTo: (.*)\r\n/g.exec(i)),t=a(/\r\nCc: (.*)\r\n/g.exec(i)),u=a(/\r\nFrom: (.*)\r\n/g.exec(i)),{messageParts:o,subject:c,to:s,cc:t,from:u}},n=function(){var e,t,r,u,a,o,i,c;return i=function(e){return null==e&&(e=""),("function"==typeof e.trim?e.trim():void 0)||e.replace(/^\s+|\s+$/g,"")},u=function(n,t){var r;return null==n&&(n=""),null==t&&(t=""),t=t.toLowerCase(),r=function(){switch(!1){case-1===t.indexOf("koi8-r"):return e(n);case-1===t.indexOf("utf-8"):return Base64._utf8_decode(n);case-1===t.indexOf("windows-1251"):return c(n);default:return n}}()},t=function(e){return e.replace(/\=[\r\n]+/g,"").replace(/\=[0-9A-F]{2}/gi,function(e){return String.fromCharCode(parseInt(e.substr(1),16))})},e=function(e){var n,t,r,u,a,o,i;for(n=unescape("%u2500%u2502%u250C%u2510%u2514%u2518%u251C%u2524%u252C%u2534%u253C%u2580%u2584%u2588%u258C%u2590%u2591%u2592%u2593%u2320%u25A0%u2219%u221A%u2248%u2264%u2265%u00A0%u2321%u00B0%u00B2%u00B7%u00F7%u2550%u2551%u2552%u0451%u2553%u2554%u2555%u2556%u2557%u2558%u2559%u255A%u255B%u255C%u255D%u255E%u255F%u2560%u2561%u0401%u2562%u2563%u2564%u2565%u2566%u2567%u2568%u2569%u256A%u256B%u256C%u00A9%u044E%u0430%u0431%u0446%u0434%u0435%u0444%u0433%u0445%u0438%u0439%u043A%u043B%u043C%u043D%u043E%u043F%u044F%u0440%u0441%u0442%u0443%u0436%u0432%u044C%u044B%u0437%u0448%u044D%u0449%u0447%u044A%u042E%u0410%u0411%u0426%u0414%u0415%u0424%u0413%u0425%u0418%u0419%u041A%u041B%u041C%u041D%u041E%u041F%u042F%u0420%u0421%u0422%u0423%u0416%u0412%u042C%u042B%u0417%u0428%u042D%u0429%u0427%u042A"),t=function(e){return e>=128&&255>=e?n.charAt(e-128):String.fromCharCode(e)},o="",r=u=0,a=e.length;a>u;r=++u)i=e[r],o+=t(e.charCodeAt(r));return o},c=function(e){var n,t,r,u,a,o,i;for(null==e&&(e=""),o="",n=r=0,u=e.length;u>r;n=++r)i=e[n],t=e.charCodeAt(n),a=function(){switch(!1){case 168!==t:return 1025;case 184!==t:return 1105;case!(t>191&&256>t):return t+848;default:return t}}(),o+=String.fromCharCode(a);return o},r=function(e,r){var a,o,i;return e=n.trim(e),o=void 0,a=void 0,i=void 0,(i=e.match(/^\=\?([\w_\-]+)\?([QqBb])\?([^\?]*)\?\=$/i))?(o=i[1],a=(i[2]||"Q").toString().toUpperCase(),e=(i[3]||"").replace(/_/g," "),"B"===a?Base64.decode(e,r):"Q"===a?t(e):e):u(e,r)},a=function(e,n){return e=(e||"").toString().replace(/(=\?[^?]+\?[QqBb]\?[^?]+\?=)\s+(?==\?[^?]+\?[QqBb]\?[^?]*\?=)/g,"$1").replace(/\=\?([\w_\-]+)\?([QqBb])\?[^\?]*\?\=/g,function(e,n,t){return r(e)}.bind(this)),u(e,n)},o=function(e){return null==e&&(e=""),(e+"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")},{decode:u,KOIRDec:e,win1251Dec:c,decodeMimeWords:a,toHtmlEntity:o,trim:i}}(),t=function(t){var u,a,o,i,c,s,l,d,p,f,m,g;f={html:"",text:"",attaches:[],innerMsgs:[],to:n.decodeMimeWords(t.to),cc:n.decodeMimeWords(t.cc),from:n.decodeMimeWords(t.from),subject:n.decodeMimeWords(t.subject)},a=function(e,t){var r,u,a;return a=/Content-Transfer-Encoding: quoted-printable/i.test(t),u=/Content-Transfer-Encoding: base64/i.test(t),u?(e=e.replace(/\s/g,""),r="function"==typeof atob?atob(e):void 0,null==r&&(r=Base64.decode(e)),e=r):a&&(e=n.QPDec(e)),e},d=function(t){var u,o,i,c,s,l,p,m,g,h,b,C,y,x,T,v,w,B,A,E,M,D,F,$,O;if(t){for(h=0,C=t.length;C>h;h++)if(w=t[h],x=(null!=(A=w.mimeType)?A:"").toLowerCase(),-1===x.indexOf("multipart"))if(-1===x.indexOf("message/rfc822"))if(B=w.rawHeaders,c=-1!==B.indexOf("Content-Disposition: attachment"),o=w.rawBody,l=/text\/html/.test(x),m=/text\/plain/.test(x),p=/image/.test(x),s=/audio/.test(x),c||p||s){for(g=/Content-Transfer-Encoding: quoted-printable/i.test(B),g&&(o=n.QPDec(o),o=btoa?btoa(o):Base64.encode(o)),E=w.contentTypeParts,b=0,y=E.length;y>b;b++)if(O=E[b],/name=/i.test(O)){T=O.replace(/(.*)=/,"").replace(/"|'/g,"");break}T||(T=p?"image":s?"audio":"attachment",T+="_"+Math.floor(100*Math.random()),F=x.indexOf("/"),$=x.substring(F+1),$.length<4&&(T+="."+$)),D=/(.*)content-id:(.*)<(.*)>/i,u={type:x,base64:o,name:T,cid:null!=(M=D.exec(B))?M[3]:void 0,visible:/png|jpeg|jpg|gif/.test(x)},f.attaches.push(u)}else l||m?(o=a(o,B),o=n.decode(o,w.contentType),l&&(f.html+=o),m&&(f.text+=o)):console.log("Unknown mime type: "+x);else v=e(w.rawBody),i=r(v),f.innerMsgs.push(i);else d(w.bodyParts);return null}};try{if(p=t.messageParts,!p)return f;l=(p.mimeType||"").toLowerCase(),c=/text\/plain/.test(l),i=/text\/html/.test(l),-1!==l.indexOf("multipart")?d(p.bodyParts):c||i?(u=a(p.body,p.rawHeaders),u=n.decode(u,p.contentType),i&&(f.html=u),c&&(f.text=u)):console.log("Warning: mime type isn't supported! mime="+l)}catch(h){throw o=h,new Error(o)}return g=function(e){return"<pre>"+n.toHtmlEntity(e)+"</pre>"},s=function(e){var t,r,u,a,o,i,c,l;if(u=e.innerMsgs,null!=u?u.length:void 0)for(!n.trim(e.html)&&e.text&&(e.html+=g(e.text)),a=0,o=u.length;o>a;a++)r=u[a],i=s(r),l=i.text,t=i.html,t?e.html+=t:l&&(e.html+=wrapPerTag(l),e.text+=l),(null!=(c=i.attaches)?c.length:void 0)>0&&(e.attaches=e.attaches.concat(i.attaches));return e},m=s(f)},r=function(n){var r,u;return u=e(n),r=t(u)},{toMimeTxt:u,toMimeObj:r}}()}).call(this); +\ No newline at end of file diff --git a/src/mime-js.coffee b/src/mime-js.coffee @@ -21,7 +21,7 @@ window.Mime = do -> # "cids": [], # "attaches" : [] # } - toMimeTxt = (mail) -> + toMimeTxt = (mail, txtOnly) -> linkify = (inputText) -> #URLs starting with http://, https://, or ftp:// replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim @@ -136,10 +136,14 @@ window.Mime = do -> plain = createPlain mail.body - htm = createHtml mail - alternative = createAlternative plain, htm - cids = createCids mail.cids - related = createRelated alternative, cids + if txtOnly + related = plain + else + htm = createHtml mail + alternative = createAlternative plain, htm + cids = createCids mail.cids + related = createRelated alternative, cids + attaches = createAttaches mail.attaches result = createMixed(related, attaches)