multi_mail 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +4 -0
- data/.yardopts +4 -0
- data/Gemfile +1 -1
- data/README.md +107 -12
- data/Rakefile +75 -52
- data/lib/multi_mail/cloudmailin/receiver.rb +100 -0
- data/lib/multi_mail/mailgun/receiver.rb +74 -36
- data/lib/multi_mail/mailgun/sender.rb +14 -0
- data/lib/multi_mail/mandrill/receiver.rb +77 -35
- data/lib/multi_mail/mandrill/sender.rb +14 -0
- data/lib/multi_mail/postmark/receiver.rb +68 -0
- data/lib/multi_mail/postmark/sender.rb +14 -0
- data/lib/multi_mail/receiver/base.rb +125 -8
- data/lib/multi_mail/receiver.rb +10 -4
- data/lib/multi_mail/sender/base.rb +7 -0
- data/lib/multi_mail/sender.rb +10 -4
- data/lib/multi_mail/sendgrid/receiver.rb +42 -0
- data/lib/multi_mail/sendgrid/sender.rb +11 -0
- data/lib/multi_mail/service.rb +15 -4
- data/lib/multi_mail/simple/receiver.rb +15 -0
- data/lib/multi_mail/simple/sender.rb +14 -0
- data/lib/multi_mail/version.rb +1 -1
- data/lib/multi_mail.rb +71 -3
- data/multi_mail.gemspec +12 -5
- data/spec/cloudmailin/receiver_spec.rb +112 -0
- data/spec/fixtures/cloudmailin/json/spam.txt +59 -0
- data/spec/fixtures/cloudmailin/json/valid.txt +59 -0
- data/spec/fixtures/cloudmailin/multipart/spam.txt +135 -0
- data/spec/fixtures/cloudmailin/multipart/valid.txt +135 -0
- data/spec/fixtures/cloudmailin/raw/spam.txt +137 -0
- data/spec/fixtures/cloudmailin/raw/valid.txt +137 -0
- data/spec/fixtures/mailgun/parsed/invalid.txt +8 -0
- data/spec/fixtures/mailgun/parsed/missing.txt +8 -0
- data/spec/fixtures/mailgun/parsed/spam.txt +8 -0
- data/spec/fixtures/mailgun/parsed/valid.txt +187 -0
- data/spec/fixtures/mandrill/spam.txt +9 -0
- data/spec/fixtures/mandrill/valid.txt +10 -0
- data/spec/fixtures/multipart.txt +99 -0
- data/spec/fixtures/postmark/spam.txt +83 -0
- data/spec/fixtures/postmark/valid.txt +92 -0
- data/spec/fixtures/simple/valid.txt +4 -0
- data/spec/mailgun/receiver_spec.rb +105 -50
- data/spec/mailgun/sender_spec.rb +0 -0
- data/spec/mandrill/receiver_spec.rb +35 -35
- data/spec/mandrill/sender_spec.rb +0 -0
- data/spec/multi_mail_spec.rb +63 -0
- data/spec/postmark/receiver_spec.rb +60 -0
- data/spec/postmark/sender_spec.rb +0 -0
- data/spec/receiver/base_spec.rb +73 -8
- data/spec/sender/base_spec.rb +21 -0
- data/spec/service_spec.rb +2 -2
- data/spec/simple/receiver_spec.rb +36 -0
- data/spec/simple/sender_spec.rb +0 -0
- data/spec/spec_helper.rb +123 -10
- metadata +141 -21
- data/spec/fixtures/mailgun/invalid.txt +0 -8
- data/spec/fixtures/mailgun/missing.txt +0 -8
- data/spec/fixtures/mailgun/spam.txt +0 -8
- data/spec/fixtures/mailgun/valid.txt +0 -8
@@ -0,0 +1,99 @@
|
|
1
|
+
Received: from mail-ia0-f170.google.com (mail-ia0-f170.google.com [209.85.210.170])
|
2
|
+
by ip-10-254-10-35 (Postfix) with ESMTPS id D6B554B407F
|
3
|
+
for <foo+bar@govkit.org>; Tue, 16 Apr 2013 16:59:11 +0000 (UTC)
|
4
|
+
Received: by mail-ia0-f170.google.com with SMTP id 21so418031iay.1
|
5
|
+
for <foo+bar@govkit.org>; Tue, 16 Apr 2013 09:59:11 -0700 (PDT)
|
6
|
+
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
|
7
|
+
d=google.com; s=20120113;
|
8
|
+
h=x-received:from:content-type:subject:date:message-id:to
|
9
|
+
:mime-version:x-mailer:x-gm-message-state;
|
10
|
+
bh=t65yBTqkEtSef4tR7ISM9vxoaTyBuQsL0pSLruHpibE=;
|
11
|
+
b=dTBm7fXAoceod/ldOdJMbvMc1bhPTn60q9wh2PYKRcptz1FSV1OrU/JyXi2G9ju9kB
|
12
|
+
jSXystAlcoq7P4CrbBwaC5oI0ah4bvttUel7Z7+1y6+ynEhq/SllXzthTnFaE2BaWBer
|
13
|
+
eoaQW4D02SVxCcn5jCOjVR6gJMSWmMET+SfBplpnaTFy+HOr8l0pfNTmD9Vojybrbn+e
|
14
|
+
oPiyCRd12aEo1o4celDDwHpVXmN9c/RJTM6d1/b0hw9fNC5Fehbo1u1Q5J6G1ORMyNkM
|
15
|
+
KYOmQRE+5Ya1+377s/heGwVw8YoIfepzvIlpTyqA7B8O49X/T2GDH8HIiOC92BFZuqA4
|
16
|
+
fYkg==
|
17
|
+
X-Received: by 10.50.55.73 with SMTP id q9mr1850586igp.44.1366131550864;
|
18
|
+
Tue, 16 Apr 2013 09:59:10 -0700 (PDT)
|
19
|
+
Received: from [192.168.0.110] ([69.165.215.199])
|
20
|
+
by mx.google.com with ESMTPS id m4sm1430594igd.0.2013.04.16.09.59.08
|
21
|
+
(version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
|
22
|
+
Tue, 16 Apr 2013 09:59:09 -0700 (PDT)
|
23
|
+
From: James McKinney <james@opennorth.ca>
|
24
|
+
Content-Type: multipart/alternative; boundary="Apple-Mail=_DB17A68A-87B7-4691-928D-1B6E57DD137B"
|
25
|
+
Subject: Test
|
26
|
+
Date: Tue, 15 Apr 2013 20:20:12 -0400
|
27
|
+
Message-Id: <2C60A16D-5B23-4BA6-9211-867AF28F251A@opennorth.ca>
|
28
|
+
To: foo+bar@govkit.org
|
29
|
+
Mime-Version: 1.0 (Apple Message framework v1283)
|
30
|
+
X-Mailer: Apple Mail (2.1283)
|
31
|
+
X-Gm-Message-State: ALoCoQnOht/eguXrGfkiTTa/As+g7RBOQscv5d85HA1rB4BzpPvN9f6jnZogS/cYGAOC4ns38GkP
|
32
|
+
|
33
|
+
|
34
|
+
--Apple-Mail=_DB17A68A-87B7-4691-928D-1B6E57DD137B
|
35
|
+
Content-Transfer-Encoding: 7bit
|
36
|
+
Content-Type: text/plain;
|
37
|
+
charset=us-ascii
|
38
|
+
|
39
|
+
bold text
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
some more bold text
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
some italic text
|
48
|
+
|
49
|
+
> multiline
|
50
|
+
> quoted
|
51
|
+
> text
|
52
|
+
|
53
|
+
|
54
|
+
--
|
55
|
+
Signature block
|
56
|
+
--Apple-Mail=_DB17A68A-87B7-4691-928D-1B6E57DD137B
|
57
|
+
Content-Type: multipart/mixed;
|
58
|
+
boundary="Apple-Mail=_62F1A9B0-BB56-4D14-9454-A18AF00A4AA1"
|
59
|
+
|
60
|
+
|
61
|
+
--Apple-Mail=_62F1A9B0-BB56-4D14-9454-A18AF00A4AA1
|
62
|
+
Content-Transfer-Encoding: 7bit
|
63
|
+
Content-Type: text/html;
|
64
|
+
charset=us-ascii
|
65
|
+
|
66
|
+
<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><b>bold text</b><div><br></div><div></div></body></html>
|
67
|
+
--Apple-Mail=_62F1A9B0-BB56-4D14-9454-A18AF00A4AA1
|
68
|
+
Content-Disposition: attachment;
|
69
|
+
filename=foo.txt
|
70
|
+
Content-Type: text/plain;
|
71
|
+
name="foo.txt"
|
72
|
+
Content-Transfer-Encoding: 7bit
|
73
|
+
|
74
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
75
|
+
|
76
|
+
--Apple-Mail=_62F1A9B0-BB56-4D14-9454-A18AF00A4AA1
|
77
|
+
Content-Transfer-Encoding: 7bit
|
78
|
+
Content-Type: text/html;
|
79
|
+
charset=us-ascii
|
80
|
+
|
81
|
+
<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><head></head><br><div></div><div><br></div><div><b>some more bold text</b></div><div><b><br></b></div><div><b></b></div></body></html>
|
82
|
+
--Apple-Mail=_62F1A9B0-BB56-4D14-9454-A18AF00A4AA1
|
83
|
+
Content-Disposition: attachment;
|
84
|
+
filename=bar.txt
|
85
|
+
Content-Type: text/plain;
|
86
|
+
name="bar.txt"
|
87
|
+
Content-Transfer-Encoding: 7bit
|
88
|
+
|
89
|
+
Nam accumsan euismod eros et rhoncus.
|
90
|
+
|
91
|
+
--Apple-Mail=_62F1A9B0-BB56-4D14-9454-A18AF00A4AA1
|
92
|
+
Content-Transfer-Encoding: 7bit
|
93
|
+
Content-Type: text/html;
|
94
|
+
charset=us-ascii
|
95
|
+
|
96
|
+
<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><b></b></div><div><b><span class="Apple-style-span" style="font-weight: normal; "><br></span></b></div><div><b><span class="Apple-style-span" style="font-weight: normal; "><i>some italic text</i></span></b></div><div><b><span class="Apple-style-span" style="font-weight: normal; "><br></span></b></div><div><blockquote type="cite">multiline</blockquote><blockquote type="cite">quoted</blockquote><blockquote type="cite">text</blockquote></div><div><br></div><div>--</div><div>Signature block</div></body></html>
|
97
|
+
--Apple-Mail=_62F1A9B0-BB56-4D14-9454-A18AF00A4AA1--
|
98
|
+
|
99
|
+
--Apple-Mail=_DB17A68A-87B7-4691-928D-1B6E57DD137B--
|
@@ -0,0 +1,83 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
User-Agent: Postmark
|
3
|
+
Host: requestb.in
|
4
|
+
Content-Type: application/json
|
5
|
+
Content-Length: 2768
|
6
|
+
Connection: close
|
7
|
+
Accept: application/json
|
8
|
+
|
9
|
+
{
|
10
|
+
"From": "james@opennorth.ca",
|
11
|
+
"FromFull": {
|
12
|
+
"Email": "james@opennorth.ca",
|
13
|
+
"Name": "James McKinney"
|
14
|
+
},
|
15
|
+
"To": "4354473e2e6ab001fa836f627a54004e@inbound.postmarkapp.com",
|
16
|
+
"ToFull": [
|
17
|
+
{
|
18
|
+
"Email": "4354473e2e6ab001fa836f627a54004e@inbound.postmarkapp.com",
|
19
|
+
"Name": ""
|
20
|
+
}
|
21
|
+
],
|
22
|
+
"Cc": "",
|
23
|
+
"CcFull": [],
|
24
|
+
"ReplyTo": "",
|
25
|
+
"Subject": "",
|
26
|
+
"MessageID": "1511e3f0-2341-44ab-b272-6861d3992494",
|
27
|
+
"Date": "Wed, 15 May 2013 14:31:58 -0400",
|
28
|
+
"MailboxHash": "",
|
29
|
+
"TextBody": "XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X\n ",
|
30
|
+
"HtmlBody": "",
|
31
|
+
"Tag": "",
|
32
|
+
"Headers": [
|
33
|
+
{
|
34
|
+
"Name": "X-Spam-Checker-Version",
|
35
|
+
"Value": "SpamAssassin 3.3.1 (2010-03-16) on ip-10-90-190-53"
|
36
|
+
},
|
37
|
+
{
|
38
|
+
"Name": "X-Spam-Status",
|
39
|
+
"Value": "Yes"
|
40
|
+
},
|
41
|
+
{
|
42
|
+
"Name": "X-Spam-Score",
|
43
|
+
"Value": "1000.0"
|
44
|
+
},
|
45
|
+
{
|
46
|
+
"Name": "X-Spam-Tests",
|
47
|
+
"Value": "GTUBE,RCVD_IN_DNSWL_BLOCKED,SPF_PASS,TVD_SPACE_RATIO"
|
48
|
+
},
|
49
|
+
{
|
50
|
+
"Name": "Received-SPF",
|
51
|
+
"Value": "Pass (sender SPF authorized) identity=mailfrom; client-ip=209.85.128.173; helo=mail-ve0-f173.google.com; envelope-from=james@opennorth.ca; receiver=4354473e2e6ab001fa836f627a54004e@inbound.postmarkapp.com"
|
52
|
+
},
|
53
|
+
{
|
54
|
+
"Name": "X-Google-DKIM-Signature",
|
55
|
+
"Value": "v=1; a=rsa-sha256; c=relaxed\/relaxed; d=google.com; s=20120113; h=x-received:from:content-type:content-transfer-encoding:subject:date :message-id:to:mime-version:x-mailer:x-gm-message-state; bh=id84uDPa9SMZAVd+g2pYg3Hl9aPfnapoGlOygxrIuV4=; b=FBOYbZeMltWT5lSQqGEQeOrI0zlmPh+k+OrdlX0RTfHDNjXKcWUnMNQI5nCLCZmMx2 kc4wjWBhJUyKL49GmXPlsNmklwhtJw9jXykyY3lp67ADeIxvNQap9GdTcmmPD1tbwZCD MMXVUGOSNc2avykFJVgGGb72ODhXWK0Id+aCGfH2RlQbIiLnZ665ESn4De7LBGBjWM3B Y50rmKM8p0Y1l487Gr4FYhkbvoPzQRCgnzUSuRhwW8KDD1Wc4pDmZw+xsT8gVs9WE4uU 4pmB17MmH79jNJ1BQmnYGKqVFmfd8qUczGtGvfCJ94TnxY\/ggduXNk+6pGbDGzjMTgYK VNBQ=="
|
56
|
+
},
|
57
|
+
{
|
58
|
+
"Name": "X-Received",
|
59
|
+
"Value": "by 10.52.33.143 with SMTP id r15mr1480858vdi.27.1368642721260; Wed, 15 May 2013 11:32:01 -0700 (PDT)"
|
60
|
+
},
|
61
|
+
{
|
62
|
+
"Name": "Content-Transfer-Encoding",
|
63
|
+
"Value": "7bit"
|
64
|
+
},
|
65
|
+
{
|
66
|
+
"Name": "Message-Id",
|
67
|
+
"Value": "<F0C4C026-AA7E-4CA6-8995-92364019F748@opennorth.ca>"
|
68
|
+
},
|
69
|
+
{
|
70
|
+
"Name": "Mime-Version",
|
71
|
+
"Value": "1.0 (Apple Message framework v1283)"
|
72
|
+
},
|
73
|
+
{
|
74
|
+
"Name": "X-Mailer",
|
75
|
+
"Value": "Apple Mail (2.1283)"
|
76
|
+
},
|
77
|
+
{
|
78
|
+
"Name": "X-Gm-Message-State",
|
79
|
+
"Value": "ALoCoQmUwR7xEUEvsrsXgQsSDgDyR8ovC+5qExdPxXJOIPY85ZYVQj32e3oP0xre4qa3hHQUIxwR"
|
80
|
+
}
|
81
|
+
],
|
82
|
+
"Attachments": []
|
83
|
+
}
|
@@ -0,0 +1,92 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
User-Agent: Postmark
|
3
|
+
Host: requestb.in
|
4
|
+
Content-Type: application/json
|
5
|
+
Content-Length: 3355
|
6
|
+
Connection: close
|
7
|
+
Accept: application/json
|
8
|
+
|
9
|
+
{
|
10
|
+
"From": "james@opennorth.ca",
|
11
|
+
"FromFull": {
|
12
|
+
"Email": "james@opennorth.ca",
|
13
|
+
"Name": "James McKinney"
|
14
|
+
},
|
15
|
+
"To": "4354473e2e6ab001fa836f627a54004e@inbound.postmarkapp.com",
|
16
|
+
"ToFull": [
|
17
|
+
{
|
18
|
+
"Email": "4354473e2e6ab001fa836f627a54004e@inbound.postmarkapp.com",
|
19
|
+
"Name": ""
|
20
|
+
}
|
21
|
+
],
|
22
|
+
"Cc": "",
|
23
|
+
"CcFull": [],
|
24
|
+
"ReplyTo": "",
|
25
|
+
"Subject": "Test",
|
26
|
+
"MessageID": "61c7c8b8-ba7e-43c3-b9ad-0ba865e8caa2",
|
27
|
+
"Date": "Mon, 15 Apr 2013 20:20:12 -0400",
|
28
|
+
"MailboxHash": "",
|
29
|
+
"TextBody": "bold text\n\n\n\nsome more bold text\n\n\n\nsome italic text\n\n> multiline\n> quoted\n> text\n\n\n--\nSignature block",
|
30
|
+
"HtmlBody": "<html><head><\/head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><b>bold text<\/b><div><br><\/div><div><\/div><\/body><\/html>",
|
31
|
+
"Tag": "",
|
32
|
+
"Headers": [
|
33
|
+
{
|
34
|
+
"Name": "X-Spam-Checker-Version",
|
35
|
+
"Value": "SpamAssassin 3.3.1 (2010-03-16) on ip-10-90-190-53"
|
36
|
+
},
|
37
|
+
{
|
38
|
+
"Name": "X-Spam-Status",
|
39
|
+
"Value": "No"
|
40
|
+
},
|
41
|
+
{
|
42
|
+
"Name": "X-Spam-Score",
|
43
|
+
"Value": "-0.7"
|
44
|
+
},
|
45
|
+
{
|
46
|
+
"Name": "X-Spam-Tests",
|
47
|
+
"Value": "HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS"
|
48
|
+
},
|
49
|
+
{
|
50
|
+
"Name": "Received-SPF",
|
51
|
+
"Value": "Pass (sender SPF authorized) identity=mailfrom; client-ip=209.85.128.182; helo=mail-ve0-f182.google.com; envelope-from=james@opennorth.ca; receiver=4354473e2e6ab001fa836f627a54004e@inbound.postmarkapp.com"
|
52
|
+
},
|
53
|
+
{
|
54
|
+
"Name": "X-Google-DKIM-Signature",
|
55
|
+
"Value": "v=1; a=rsa-sha256; c=relaxed\/relaxed; d=google.com; s=20120113; h=x-received:from:content-type:subject:date:message-id:to :mime-version:x-mailer:x-gm-message-state; bh=6BFmo0mUeQt+IiTRnSXv3DGerJst54bEHOqdmK9J6dc=; b=kZ0dA4IGLc8i8\/esvJLboiTLam2UPsl4vanU5jmd2rHy7UKxG2iW8MPIOkn\/xCLd3r x1k0Sc20pR6ekCIPtTlDaoTO2MtZ4M5ap0t4zLChQUTXLbtu2vJhCzbdtiYyO9iX8016 da4XyWlSibafevpH67vqeemgTOiN51SDRm8d89QMPeGlN7ZOX6Vlvy3vHjuMwsM2W\/Cw OsN8dxI7ak\/Zs8bnKNzFidj468vgDmhcTTG7yOkSMCVy9JfYs4PnVKP6FypWU+392WGR f2KB1WL0nG+jDXf0BwoqiR4m9Xr2iZgQZriBwPjs0mq4PtP8EyZ3cqoGRg8frwXOS+lF F8hA=="
|
56
|
+
},
|
57
|
+
{
|
58
|
+
"Name": "X-Received",
|
59
|
+
"Value": "by 10.58.220.129 with SMTP id pw1mr25886445vec.32.1368642705636; Wed, 15 May 2013 11:31:45 -0700 (PDT)"
|
60
|
+
},
|
61
|
+
{
|
62
|
+
"Name": "Message-Id",
|
63
|
+
"Value": "<3F47B6AB-FD2E-4BC6-9E1F-666D44341D15@opennorth.ca>"
|
64
|
+
},
|
65
|
+
{
|
66
|
+
"Name": "Mime-Version",
|
67
|
+
"Value": "1.0 (Apple Message framework v1283)"
|
68
|
+
},
|
69
|
+
{
|
70
|
+
"Name": "X-Mailer",
|
71
|
+
"Value": "Apple Mail (2.1283)"
|
72
|
+
},
|
73
|
+
{
|
74
|
+
"Name": "X-Gm-Message-State",
|
75
|
+
"Value": "ALoCoQkJ2Fj4y+iFzvfYnN1rFI4mx8y5hskCquYjWJKOWnqxsYHNrZffh99h2AA6Gos8pSmDZhL3"
|
76
|
+
}
|
77
|
+
],
|
78
|
+
"Attachments": [
|
79
|
+
{
|
80
|
+
"Name": "foo.txt",
|
81
|
+
"Content": "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4K",
|
82
|
+
"ContentType": "text/plain",
|
83
|
+
"ContentLength": 76
|
84
|
+
},
|
85
|
+
{
|
86
|
+
"Name": "bar.txt",
|
87
|
+
"Content": "TmFtIGFjY3Vtc2FuIGV1aXNtb2QgZXJvcyBldCByaG9uY3VzLgo=",
|
88
|
+
"ContentType": "text/plain",
|
89
|
+
"ContentLength": 52
|
90
|
+
}
|
91
|
+
]
|
92
|
+
}
|
@@ -0,0 +1,4 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Content-Type: application/x-www-form-urlencoded
|
3
|
+
|
4
|
+
message=Return-Path%3A+%3Cjames%40opennorth.ca%3E%0AReceived%3A+from+%5B192.168.0.104%5D+%28%5B69.165.204.186%5D%29%0A++++++++by+mx.google.com+with+ESMTPS+id+ez8sm24876706igb.17.2012.12.27.12.25.27%0A++++++++%28version%3DTLSv1%2FSSLv3+cipher%3DOTHER%29%3B%0A++++++++Thu%2C+27+Dec+2012+12%3A25%3A28+-0800+%28PST%29%0AFrom%3A+James+McKinney+%3Cjames%40opennorth.ca%3E%0AContent-Type%3A+multipart%2Falternative%3B+boundary%3D%22Apple-Mail%3D_9BF84D11-673B-4F5C-B5F7-46FA0E73983F%22%0ASubject%3A+Test%0ADate%3A+Thu%2C+27+Dec+2012+15%3A25%3A37+-0500%0AMessage-Id%3A+%3C24D8D853-1C75-4F64-ABA5-33A6C81471FA%40opennorth.ca%3E%0ATo%3A+foo%2Bbar%40govkit.org%0AMime-Version%3A+1.0+%28Apple+Message+framework+v1283%29%0AX-Mailer%3A+Apple+Mail+%282.1283%29%0A%0A%0A--Apple-Mail%3D_9BF84D11-673B-4F5C-B5F7-46FA0E73983F%0AContent-Transfer-Encoding%3A+7bit%0AContent-Type%3A+text%2Fplain%3B%0A++charset%3Dus-ascii%0A%0Abold+text%0A%0A%0A%3E+multiline%0A%3E+quoted%0A%3E+text%0A%0A--%0ASignature+block%0A--Apple-Mail%3D_9BF84D11-673B-4F5C-B5F7-46FA0E73983F%0AContent-Transfer-Encoding%3A+7bit%0AContent-Type%3A+text%2Fhtml%3B%0A++charset%3Dus-ascii%0A%0A%3Chtml%3E%3Chead%3E%3C%2Fhead%3E%3Cbody+style%3D%22word-wrap%3A+break-word%3B+-webkit-nbsp-mode%3A+space%3B+-webkit-line-break%3A+after-white-space%3B+%22%3E%3Cdiv%3E%3Cb%3Ebold+text%3C%2Fb%3E%3C%2Fdiv%3E%3Cdiv%3E%3Cbr%3E%3C%2Fdiv%3E%3Cdiv%3E%3Cblockquote+type%3D%22cite%22%3E%3C%2Fblockquote%3E%3C%2Fdiv%3E%3Cdiv%3E%3Cblockquote+type%3D%22cite%22%3Emultiline%3C%2Fblockquote%3E%3C%2Fdiv%3E%3Cblockquote+type%3D%22cite%22%3E%3Cdiv%3Equoted%3C%2Fdiv%3E%3Cdiv%3Etext%3C%2Fdiv%3E%3C%2Fblockquote%3E%3Cbr%3E%3Cdiv%3E--%3C%2Fdiv%3E%3Cdiv%3ESignature+block%3C%2Fdiv%3E%3C%2Fbody%3E%3C%2Fhtml%3E%0A--Apple-Mail%3D_9BF84D11-673B-4F5C-B5F7-46FA0E73983F--%0A
|
@@ -10,65 +10,120 @@ describe MultiMail::Receiver::Mailgun do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
context 'after initialization' do
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
context 'with invalid HTTP POST format' do
|
14
|
+
let :service do
|
15
|
+
MultiMail::Receiver.new({
|
16
|
+
:provider => :mailgun,
|
17
|
+
:mailgun_api_key => 'foo',
|
18
|
+
:http_post_format => 'invalid',
|
19
|
+
})
|
20
|
+
end
|
16
21
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
+
describe '#transform' do
|
23
|
+
it 'should raise an error if :http_post_format is invalid' do
|
24
|
+
expect{ service.transform({}) }.to raise_error(ArgumentError)
|
25
|
+
end
|
26
|
+
end
|
22
27
|
end
|
23
28
|
|
24
|
-
|
25
|
-
|
26
|
-
|
29
|
+
[false, true].each do |action_dispatch|
|
30
|
+
let :action_dispatch do
|
31
|
+
action_dispatch
|
27
32
|
end
|
28
33
|
|
29
|
-
|
30
|
-
|
31
|
-
|
34
|
+
# @todo Write my own Postbin to have a URL ending with "mime" in order
|
35
|
+
# to get fixtures to test the raw MIME HTTP POST format; all existing
|
36
|
+
# OS code for bins suck. Simple Rack app with in-memory storage?
|
37
|
+
['parsed', '', nil].each do |http_post_format|
|
38
|
+
context "with #{http_post_format.inspect} format and #{action_dispatch ? 'ActionDispatch' : 'Rack'}" do
|
39
|
+
let :http_post_format do
|
40
|
+
http_post_format
|
41
|
+
end
|
32
42
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
43
|
+
let :actual_http_post_format do
|
44
|
+
http_post_format.to_s.empty? ? 'parsed' : http_post_format
|
45
|
+
end
|
37
46
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
message.to.should == ['foo+bar@multimail.mailgun.org']
|
46
|
-
message.subject.should == 'Test'
|
47
|
-
|
48
|
-
# Body
|
49
|
-
message.multipart?.should == true
|
50
|
-
message.parts.size.should == 2
|
51
|
-
message.parts[0].content_type.should == 'text/plain'
|
52
|
-
message.parts[0].body.should == "bold text\n\n> multiline\n> quoted\n> text\n\n\n--\nSignature block"
|
53
|
-
message.parts[1].content_type.should == 'text/html; charset=UTF-8'
|
54
|
-
message.parts[1].body.should == %(<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><b>bold text</b><div><br></div><div><blockquote type="cite">multiline</blockquote><blockquote type="cite">quoted</blockquote><blockquote type="cite">text</blockquote></div><div><br></div><div>--</div><div>Signature block</div></body></html>)
|
55
|
-
|
56
|
-
# Extra Mailgun parameters
|
57
|
-
message['stripped-text'].value.should == 'bold text'
|
58
|
-
message['stripped-signature'].value.should == "--\r\nSignature block"
|
59
|
-
message['stripped-html'].value.should == '<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><b>bold text</b><div><br></div><div><br></div><div>--</div><div>Signature block</div></body></html>'
|
60
|
-
end
|
61
|
-
end
|
47
|
+
let :service do
|
48
|
+
MultiMail::Receiver.new({
|
49
|
+
:provider => :mailgun,
|
50
|
+
:mailgun_api_key => 'foo',
|
51
|
+
:http_post_format => http_post_format,
|
52
|
+
})
|
53
|
+
end
|
62
54
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
55
|
+
def params(fixture)
|
56
|
+
MultiMail::Receiver::Mailgun.parse(response("mailgun/#{actual_http_post_format}", fixture, action_dispatch))
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#valid?' do
|
60
|
+
it 'should return true if the response is valid' do
|
61
|
+
service.valid?(params('valid')).should == true
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should return false if the response is invalid' do
|
65
|
+
service.valid?(params('invalid')).should == false
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should raise an error if parameters are missing' do
|
69
|
+
expect{ service.valid?(params('missing')) }.to raise_error(IndexError)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#transform' do
|
74
|
+
it 'should return a mail message' do
|
75
|
+
messages = service.transform(params('valid'))
|
76
|
+
messages.size.should == 1
|
77
|
+
message = messages[0]
|
78
|
+
|
79
|
+
# Headers
|
80
|
+
message.date.should == DateTime.parse('Mon, 15 Apr 2013 20:20:12 -04:00')
|
81
|
+
message.from.should == ['james@opennorth.ca']
|
82
|
+
message.to.should == ['foo+bar@multimail.mailgun.org']
|
83
|
+
message.subject.should == 'Test'
|
84
|
+
|
85
|
+
# Body
|
86
|
+
message.multipart?.should == true
|
87
|
+
message.parts.size.should == 4
|
88
|
+
message.parts[0].content_type.should == 'text/plain'
|
89
|
+
message.parts[1].content_type.should == 'text/html; charset=UTF-8'
|
90
|
+
message.parts[0].body.decoded.should == "bold text\n\n\n\nsome more bold text\n\n\n\nsome italic text\n\n> multiline\n> quoted\n> text\n\n\n--\nSignature block"
|
91
|
+
message.parts[1].body.decoded.should == %(<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><b>bold text</b><div><br></div><div></div></body></html><html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><head></head><br><div></div><div><br></div><div><b>some more bold text</b></div><div><b><br></b></div><div><b></b></div></body></html><html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><b></b></div><div><b><span class="Apple-style-span" style="font-weight: normal; "><br></span></b></div><div><b><span class="Apple-style-span" style="font-weight: normal; "><i>some italic text</i></span></b></div><div><b><span class="Apple-style-span" style="font-weight: normal; "><br></span></b></div><div><blockquote type="cite">multiline</blockquote><blockquote type="cite">quoted</blockquote><blockquote type="cite">text</blockquote></div><div><br></div><div>--</div><div>Signature block</div></body></html>)
|
92
|
+
|
93
|
+
# Attachments
|
94
|
+
message.attachments[0].filename.should == 'foo.txt'
|
95
|
+
message.attachments[0].read.should == "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n"
|
96
|
+
message.attachments[1].filename.should == 'bar.txt'
|
97
|
+
message.attachments[1].read.should == "Nam accumsan euismod eros et rhoncus.\n"
|
98
|
+
|
99
|
+
# Extra Mailgun parameters
|
100
|
+
# @note Due to a Mailgun bug, `stripped-text` contains "some italic
|
101
|
+
# text" but `stripped-html` doesn't. `stripped-signature` and
|
102
|
+
# `stripped-text` use CRLF line endings.
|
103
|
+
if actual_http_post_format == 'raw'
|
104
|
+
message['stripped-text'].should be_nil
|
105
|
+
message['stripped-signature'].should be_nil
|
106
|
+
message['stripped-html'].should be_nil
|
107
|
+
else
|
108
|
+
message['stripped-text'].value.should == "bold text\r\n\r\n\r\n\r\nsome more bold text\r\n\r\n\r\n\r\nsome italic text"
|
109
|
+
message['stripped-signature'].value.should == "--\r\nSignature block"
|
110
|
+
message['stripped-html'].value.should == '<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><b>bold text</b><div><br></div><div></div></body><html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div></div><div><br></div><div><b>some more bold text</b></div><div><b><br></b></div><div><b></b></div></body></html><html><head></head></html></html>'
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe '#spam?' do
|
116
|
+
it 'should return true if the response is spam' do
|
117
|
+
message = service.transform(params('spam'))[0]
|
118
|
+
service.spam?(message).should == true
|
119
|
+
end
|
68
120
|
|
69
|
-
|
70
|
-
|
71
|
-
|
121
|
+
it 'should return false if the response is ham' do
|
122
|
+
message = service.transform(params('valid'))[0]
|
123
|
+
service.spam?(message).should == false
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
72
127
|
end
|
73
128
|
end
|
74
129
|
end
|
File without changes
|
@@ -2,62 +2,62 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
2
|
require 'multi_mail/mandrill/receiver'
|
3
3
|
|
4
4
|
describe MultiMail::Receiver::Mandrill do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
expect{ MultiMail::Receiver.new :provider => :mandrill, :mandrill_api_key => nil }.to raise_error(ArgumentError)
|
5
|
+
context 'after initialization' do
|
6
|
+
let :service do
|
7
|
+
MultiMail::Receiver.new(:provider => :mandrill)
|
9
8
|
end
|
10
|
-
end
|
11
9
|
|
12
|
-
context 'after initialization' do
|
13
10
|
def params(fixture)
|
14
11
|
MultiMail::Receiver::Mandrill.parse(response('mandrill', fixture))
|
15
12
|
end
|
16
13
|
|
17
|
-
|
18
|
-
@service = MultiMail::Receiver.new({
|
19
|
-
:provider => :mandrill,
|
20
|
-
:mandrill_api_key => credentials[:mandrill_api_key],
|
21
|
-
})
|
22
|
-
end
|
23
|
-
|
24
|
-
describe '#valid?' do
|
25
|
-
it 'should return true if the response is valid' do
|
26
|
-
@service.valid?(params('valid')).should == true
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'should return false if the response is invalid' do
|
30
|
-
@service.valid?(params('invalid')).should == false
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'should raise an error if parameters are missing' do
|
34
|
-
expect{ @service.valid?(params('missing')) }.to raise_error(KeyError)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
14
|
+
# @todo Add a spec for multiple Mandrill events.
|
38
15
|
describe '#transform' do
|
39
16
|
it 'should return a mail message' do
|
40
|
-
|
17
|
+
messages = service.transform(params('valid'))
|
18
|
+
messages.size.should == 1
|
19
|
+
message = messages[0]
|
41
20
|
|
42
21
|
# Headers
|
43
|
-
message.date.should == DateTime.parse('
|
22
|
+
message.date.should == DateTime.parse('Mon, 15 Apr 2013 20:20:12 -04:00')
|
44
23
|
message.from.should == ['james@opennorth.ca']
|
45
24
|
message.to.should == ['foo+bar@govkit.org']
|
46
25
|
message.subject.should == 'Test'
|
47
26
|
|
48
27
|
# Body
|
49
28
|
message.multipart?.should == true
|
50
|
-
message.parts.size.should ==
|
29
|
+
message.parts.size.should == 4
|
51
30
|
message.parts[0].content_type.should == 'text/plain'
|
52
|
-
message.parts[0].body.should == "bold text\n\n\n> multiline\n> quoted\n> text\n\n--\nSignature block\n"
|
53
31
|
message.parts[1].content_type.should == 'text/html; charset=UTF-8'
|
54
|
-
|
55
|
-
message.parts[
|
32
|
+
# @note Mandrill adds a newline at the end of each part.
|
33
|
+
message.parts[0].body.decoded.should == "bold text\n\n\n\nsome more bold text\n\n\n\nsome italic text\n\n> multiline\n> quoted\n> text\n\n\n--\nSignature block\n"
|
34
|
+
message.parts[1].body.decoded.should == %(<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><b>bold text</b><div><br></div><div></div></body></html><html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><head></head><br><div></div><div><br></div><div><b>some more bold text</b></div><div><b><br></b></div><div><b></b></div></body></html><html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><b></b></div><div><b><span class="Apple-style-span" style="font-weight: normal; "><br></span></b></div><div><b><span class="Apple-style-span" style="font-weight: normal; "><i>some italic text</i></span></b></div><div><b><span class="Apple-style-span" style="font-weight: normal; "><br></span></b></div><div><blockquote type="cite">multiline</blockquote><blockquote type="cite">quoted</blockquote><blockquote type="cite">text</blockquote></div><div><br></div><div>--</div><div>Signature block</div></body></html>)
|
35
|
+
|
36
|
+
# Attachments
|
37
|
+
attachment0 = message.attachments.find{|attachment| attachment.filename == 'foo.txt'}
|
38
|
+
attachment1 = message.attachments.find{|attachment| attachment.filename == 'bar.txt'}
|
39
|
+
attachment0.read.should == "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n\n"
|
40
|
+
attachment1.read.should == "Nam accumsan euismod eros et rhoncus.\n\n"
|
56
41
|
|
57
42
|
# Extra Mandrill parameters
|
43
|
+
message['ts'].value.should == '1368657709'
|
58
44
|
message['email'].value.should == 'foo+bar@govkit.org'
|
59
|
-
message['
|
60
|
-
message['
|
45
|
+
message['dkim-signed'].value.should == 'false'
|
46
|
+
message['dkim-valid'].value.should == 'false'
|
47
|
+
message['spam_report-score'].value.should == '0'
|
48
|
+
message['spf-result'].value.should == 'pass'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#spam?' do
|
53
|
+
it 'should return true if the response is spam' do
|
54
|
+
message = service.transform(params('spam'))[0]
|
55
|
+
service.spam?(message).should == true
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should return false if the response is ham' do
|
59
|
+
message = service.transform(params('valid'))[0]
|
60
|
+
service.spam?(message).should == false
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
File without changes
|
data/spec/multi_mail_spec.rb
CHANGED
@@ -1,4 +1,67 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
3
|
describe MultiMail do
|
4
|
+
describe '#setup' do
|
5
|
+
before :all do
|
6
|
+
MultiMail.setup do |config|
|
7
|
+
config.autoresponse_pattern = /^Out of Office AutoReply:/i
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should set the autoresponse pattern' do
|
12
|
+
MultiMail.autoresponse_pattern.should == /^Out of Office AutoReply:/i
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#autoresponse?' do
|
17
|
+
before :each do
|
18
|
+
@message = Mail.new
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should return false if the message is not an autoresponse' do
|
22
|
+
MultiMail.autoresponse?(@message).should == false
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should return true if an autoresponder header is found' do
|
26
|
+
@message['X-Autogenerated'] = 'value'
|
27
|
+
MultiMail.autoresponse?(@message).should == true
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should return true if an autoresponder value is found' do
|
31
|
+
@message['Return-Path'] = '<>'
|
32
|
+
MultiMail.autoresponse?(@message).should == true
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should return true if Auto-Submitted is not "no"' do
|
36
|
+
@message['Auto-Submitted'] = 'auto-replied'
|
37
|
+
MultiMail.autoresponse?(@message).should == true
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should return false if Auto-Submitted is "no"' do
|
41
|
+
@message['Auto-Submitted'] = 'no'
|
42
|
+
MultiMail.autoresponse?(@message).should == false
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'without an autoresponse pattern' do
|
46
|
+
before :all do
|
47
|
+
MultiMail.autoresponse_pattern = nil
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should not match the subject against the autoresponse pattern' do
|
51
|
+
@message.subject = 'Out of Office AutoReply: Subject'
|
52
|
+
MultiMail.autoresponse?(@message).should == false
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'with an autoresponse pattern' do
|
57
|
+
before :all do
|
58
|
+
MultiMail.autoresponse_pattern = /^Out of Office AutoReply:/i
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should return true if the subject matches the autoresponse pattern' do
|
62
|
+
@message.subject = 'Out of Office AutoReply: Subject'
|
63
|
+
MultiMail.autoresponse?(@message).should == true
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
4
67
|
end
|