Skip to content

Instantly share code, notes, and snippets.

@arronzhang
Created October 21, 2011 06:55
Show Gist options
  • Save arronzhang/1303261 to your computer and use it in GitHub Desktop.
Save arronzhang/1303261 to your computer and use it in GitHub Desktop.
Test mail parser for haraka
Received: by yxo30 with SMTP id 30so753526yxo.1
for <test@push.notihub.com>; Thu, 20 Oct 2011 06:29:41 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=gamma;
h=from:content-type:subject:date:message-id:to:mime-version:x-mailer;
bh=Obpvt8P9afAHZoVJKKcis2kWu/ANdFRO5wMOJKfFu8Q=;
b=I1E+REKQIibT3BjN25s0C7uz/tRlx4RJExa+ZINa3fRf13WmROkf4SJmLAP65LZzX8
5o3emJ4fdnv1YZQSOp0+YlRcAt5vvd84eYZwaSCL2uFjHOJLpR/k/HsObJ6VMvmQqEFZ
gzhd1lLvxvKm6W7ypMOybfzjCHGosN3mqPzuU=
Received: by 10.68.199.170 with SMTP id jl10mr20555259pbc.28.1319117381189;
Thu, 20 Oct 2011 06:29:41 -0700 (PDT)
Return-Path: <zzdhidden@gmail.com>
Received: from [192.168.1.101] ([125.120.70.137])
by mx.google.com with ESMTPS id ki1sm19076325pbb.3.2011.10.20.06.29.38
(version=TLSv1/SSLv3 cipher=OTHER);
Thu, 20 Oct 2011 06:29:40 -0700 (PDT)
From: =?GB2312?B?1cXV8rar?= <zzdhidden@gmail.com>
Content-Type: multipart/alternative; boundary=Apple-Mail-86--639724651
Subject: =?GB2312?Q?Test_for_=D6=D0=CE=C4?=
Date: Thu, 20 Oct 2011 21:29:35 +0800
Message-Id: <24047BC7-6315-48E2-B8F4-7CF897135AEB@gmail.com>
To: test@push.notihub.com
Mime-Version: 1.0 (Apple Message framework v1084)
X-Mailer: Apple Mail (2.1084)
--Apple-Mail-86--639724651
Content-Transfer-Encoding: base64
Content-Type: text/plain;
charset=GB2312
yMvD8c34MTDUwjIwyNW15yCjqLCyufrVwqOpIL7dwLTX1MD7scjRx7XEz/vPoqOsDQrA+7HI0cfW
tNX+tbG+1rK/ttO98czs0tG+rc3qyKu/2NbGwcu/qNT6t8a1xMDPvNLL1bb7zNijrL+o1Pq3xsG9
zcjK3MnLuvOxu7T+srajrNLRsbvLzc350r3UuqGjIL7dwPuxyNHHtefK08yosai1wKOswPuxyNHH
1rTV/rWxvta1xLK/ttO98czsx+Wzv7bUv6ggLi4u
--Apple-Mail-86--639724651
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
charset=GB2312
<html><head></head><body style=3D"word-wrap: break-word; =
-webkit-nbsp-mode: space; -webkit-line-break: after-white-space; =
"><!--?xml version=3D"1.0" encoding=3D"UTF-8"?-->
<div style=3D"font-family: Arial; ">=C8=CB=C3=F1=CD=F810=D4=C220=C8=D5=B5=E7=
=A3=A8=B0=B2=B9=FA=D5=C2=A3=A9 =BE=DD=C0=B4=D7=D4=C0=FB=B1=C8=D1=C7=B5=C4=
=CF=FB=CF=A2=A3=AC</div><div style=3D"font-family: Arial; =
">=C0=FB=B1=C8=D1=C7=D6=B4=D5=FE=B5=B1=BE=D6=B2=BF=B6=D3=BD=F1=CC=EC=D2=D1=
=BE=AD=CD=EA=C8=AB=BF=D8=D6=C6=C1=CB=BF=A8=D4=FA=B7=C6=B5=C4=C0=CF=BC=D2=CB=
=D5=B6=FB=CC=D8=A3=AC=BF=A8=D4=FA=B7=C6=C1=BD=CD=C8=CA=DC=C9=CB=BA=F3=B1=BB=
=B4=FE=B2=B6=A3=AC=D2=D1=B1=BB=CB=CD=CD=F9=D2=BD=D4=BA=A1=A3 =
=BE=DD=C0=FB=B1=C8=D1=C7=B5=E7=CA=D3=CC=A8=B1=A8=B5=C0=A3=AC=C0=FB=B1=C8=D1=
=C7=D6=B4=D5=FE=B5=B1=BE=D6=B5=C4=B2=BF=B6=D3=BD=F1=CC=EC=C7=E5=B3=BF=B6=D4=
=BF=A8 ...</div></body></html>=
--Apple-Mail-86--639724651--
Received: by ywb26 with SMTP id 26so57554ywb.1
for <test@push.notihub.com>; Thu, 20 Oct 2011 06:33:54 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=gamma;
h=mime-version:date:message-id:subject:from:to:content-type;
bh=wsg9qxezfSvf+2YWxgE5i9csW5QhCcABSFpI4B/r15Y=;
b=rXeTpx01t/4J6qZe7whQ2lM0UM1MX7D73nyOdd3zO33JMz8G6pXlvpRObXQLFcKJ0H
gEdk+QVEsXjAn/ZTBZSh+it+9capUnE+Z0yTXreZiDkJaKsQgysi335gsduXmcFT2YbU
bKhlo8QBXdnPveLcI0CQgYlYrZ0Xhbmx2vCr8=
MIME-Version: 1.0
Received: by 10.223.81.205 with SMTP id y13mr18203205fak.34.1319117634355;
Thu, 20 Oct 2011 06:33:54 -0700 (PDT)
Received: by 10.223.87.8 with HTTP; Thu, 20 Oct 2011 06:33:54 -0700 (PDT)
Date: Thu, 20 Oct 2011 21:33:54 +0800
Message-ID: <CAOOd1DF4Dm=sNnkAYQTYAn6bkqtTfk4X=mOJXUj-yMs=O3ZH-A@mail.gmail.com>
Subject: =?GB2312?B?VGVzdCBmb3Ig1tDOxA==?=
From: =?GB2312?B?1cXV8rar?= <zzdhidden@gmail.com>
To: test@push.notihub.com
Content-Type: multipart/alternative; boundary=0015175d037e0340c304afbb0215
--0015175d037e0340c304afbb0215
Content-Type: text/plain; charset=GB2312
Content-Transfer-Encoding: base64
yMvD8c34MTDUwjIwyNW15yCjqLCyufrVwqOpIL7dwLTX1MD7scjRx7XEz/vPoqOsCsD7scjRx9a0
1f61sb7Wsr+2073xzOzS0b6tzerIq7/Y1sbBy7+o1Pq3xrXEwM+80svVtvvM2KOsv6jU+rfGwb3N
yMrcycu687G7tP6ytqOs0tGxu8vNzfnSvdS6oaMgvt3A+7HI0ce158rTzKixqLXAo6zA+7HI0cfW
tNX+tbG+1rXEsr+2073xzOzH5bO/ttS/qAouLi4K
--0015175d037e0340c304afbb0215
Content-Type: text/html; charset=GB2312
Content-Transfer-Encoding: base64
PGRpdj7Iy8PxzfgxMNTCMjDI1bXnIKOosLK5+tXCo6kgvt3AtNfUwPuxyNHHtcTP+8+io6w8L2Rp
dj48ZGl2PsD7scjRx9a01f61sb7Wsr+2073xzOzS0b6tzerIq7/Y1sbBy7+o1Pq3xrXEwM+80svV
tvvM2KOsv6jU+rfGwb3NyMrcycu687G7tP6ytqOs0tGxu8vNzfnSvdS6oaMgvt3A+7HI0ce158rT
zKixqLXAo6zA+7HI0cfWtNX+tbG+1rXEsr+2073xzOzH5bO/ttS/qCAuLi48L2Rpdj4K
--0015175d037e0340c304afbb0215--
Received: by host.monit.cn (Postfix, from userid 501)
id 1C286588DDA8; Thu, 20 Oct 2011 21:27:40 +0800 (CST)
To: test@push.notihub.com
Subject: Test for 中文
Message-Id: <20111020132740.1C286588DDA8@host.monit.cn>
Date: Thu, 20 Oct 2011 21:27:40 +0800 (CST)
From: hidden@monit.cn (hidden)
Test for chinese
人民网10月20日电 (安国章) 据来自利比亚的消息,
利比亚执政当局部队今天已经完全控制了卡扎菲的老家苏尔特,卡扎菲两腿受伤后被逮捕,已被送往医院。 据利比亚电视台报道,利比亚执政当局的部队今天清晨对卡 ...
var test = require("tap").test;
require('../configfile').watch_files = false;
var Address = require("../address.js").Address
, trans = require("../transaction.js")
, fs = require("fs");
var subjectText = "Test for 中文"
, bodyText = "Test for chinese\n人民网10月20日电 (安国章) 据来自利比亚的消息,\n利比亚执政当局部队今天已经完全控制了卡扎菲的老家苏尔特,卡扎菲两腿受伤后被逮捕,已被送往医院。 据利比亚电视台报道,利比亚执政当局的部队今天清晨对卡 ..."
, wordForCheck = "人民网"
, gmailText = fs.readFileSync(__dirname + '/fixtures_mail.gmail.txt', 'utf8')
, applemailText = fs.readFileSync(__dirname + '/fixtures_mail.apple-mail.txt', 'utf8')
, postfixText = fs.readFileSync(__dirname + '/fixtures_mail.postfix.txt', 'utf8');
function createTransaction (text) {
var transaction = trans.createTransaction();
transaction.parse_body = true;
text.split(/\r?\n/).forEach(function(line) {
transaction.add_data(line);
});
return transaction;
}
test("Parse mail from postfix", function(t) {
var transaction = createTransaction(postfixText);
//if( transaction.body.body_text_encoded )
// transaction.body.parse_end();
var body = transaction.body;
t.equal(body.header.get_decoded("subject"), subjectText, "Check subject");
t.ok(body.bodytext, "Should have bodytext");
t.ok(body.bodytext.indexOf(wordForCheck) != -1, "Check word in body");
t.end();
});
test("Parse mail from apple mail", function(t) {
var transaction = createTransaction(applemailText)
, body = transaction.body;
var children = body.children
, first = children[0]
, second = children[1];
t.equal(body.header.get_decoded("subject"), subjectText, "Check subject");
t.equal(children.length, 2, "should have to child body");
t.ok(first.bodytext.indexOf(wordForCheck) != -1, "Check word in first part body");
t.ok(second.bodytext.indexOf(wordForCheck) != -1, "Check word in second part body");
t.end();
});
test("Parse mail from gmail", function(t) {
var transaction = createTransaction(applemailText)
, body = transaction.body;
var children = body.children
, first = children[0]
, second = children[1];
t.equal(body.header.get_decoded("subject"), subjectText, "Check subject");
t.equal(children.length, 2, "should have to child body");
t.ok(first.bodytext.indexOf(wordForCheck) != -1, "Check word in first part body");
t.ok(second.bodytext.indexOf(wordForCheck) != -1, "Check word in second part body");
t.end();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment