Skip to content

Instantly share code, notes, and snippets.

@alextwl
Created April 3, 2010 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alextwl/354264 to your computer and use it in GitHub Desktop.
Save alextwl/354264 to your computer and use it in GitHub Desktop.
/*
* ANSI Strip for BBS Mail
* 2010/04/03 Wei-li Tang <s3321037@ncnu.edu.tw>
*
* Thunderbird Preview mode only. Does not apply for Newsgroup message.
* Do not use Jetpack XPI from AMO, it won't work.
* Please install opc-jetpack from:
* http://hg.mozilla.org/users/bugmail_asutherland.org/opc-jetpack/
*
* The script is based on opt-jetpack example:
* http://hg.mozilla.org/users/bugmail_asutherland.org/jetpack-tb-examples/file/a117452f167b/message-display/sender-specific/amazon-big-total.js
*
*/
// Import menu from future
jetpack.future.import("menu");
// opt-jetpack 0.7 trunk
jetpack.future.import("thunderbird.messageDisplay");
jetpack.thunderbird.messageDisplay.overrideMessageDisplay({
match: {
// Only apply for mail from "xxx.bbs@xxx"
fromAddress: /.*\.bbs@.*/
},
onDisplay: function(aGlodaMsg, aMimeMsg, aMsgHdr) {
// Strips ANSI color
var ANSIregexp = /\x1B\[([0-9]{1,2}(;[0-9]{1,2})*)?[m|K]/g;
var ansiText = aMimeMsg.coerceBodyToPlaintext(aMsgHdr.folder);
var plainText = ansiText.replace(ANSIregexp, "");
// BBS-like template
// Isolates header part.
var headExp = /\r\n\r\n([\s\S]*)/;
var headText = plainText.replace(headExp, "");
// Isolates body part. It's dirty since author was not familiar with js... :(
var bodyText1 = plainText.replace(/[\r]?\n/g, "%NEWLINE%");
var bodyText2 = bodyText1.replace(/\%NEWLINE\%\%NEWLINE\%/, "%HEADERSPLIT%");
var bodyText3 = bodyText2.replace(/^.*\%HEADERSPLIT\%/, "");
var bodyText = bodyText3.replace(/\%NEWLINE\%/g, "\n");
return {
html:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<head>
<meta content="text/html; charset=utf-8" http-equiv="content-type" />
</head>
<style><![CDATA[
body { background-color: #000000; color: #ffffff;}
#bbshdr { background-color: #337; color: #CCC;}
]]></style>
<body>
<pre id="bbshdr">{headText}</pre>
<pre>{bodyText}</pre>
</body>
</html>
};
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment