rmail 0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. data/NEWS +309 -0
  2. data/NOTES +14 -0
  3. data/README +83 -0
  4. data/THANKS +25 -0
  5. data/TODO +112 -0
  6. data/guide/Intro.txt +122 -0
  7. data/guide/MIME.txt +6 -0
  8. data/guide/TableOfContents.txt +13 -0
  9. data/install.rb +1023 -0
  10. data/lib/rmail.rb +50 -0
  11. data/lib/rmail/address.rb +829 -0
  12. data/lib/rmail/header.rb +987 -0
  13. data/lib/rmail/mailbox.rb +62 -0
  14. data/lib/rmail/mailbox/mboxreader.rb +182 -0
  15. data/lib/rmail/message.rb +201 -0
  16. data/lib/rmail/parser.rb +412 -0
  17. data/lib/rmail/parser/multipart.rb +217 -0
  18. data/lib/rmail/parser/pushbackreader.rb +173 -0
  19. data/lib/rmail/serialize.rb +190 -0
  20. data/lib/rmail/utils.rb +59 -0
  21. data/rmail.gemspec +17 -0
  22. data/tests/addrgrammar.txt +113 -0
  23. data/tests/data/mbox.odd +4 -0
  24. data/tests/data/mbox.simple +8 -0
  25. data/tests/data/multipart/data.1 +5 -0
  26. data/tests/data/multipart/data.10 +1 -0
  27. data/tests/data/multipart/data.11 +9 -0
  28. data/tests/data/multipart/data.12 +9 -0
  29. data/tests/data/multipart/data.13 +3 -0
  30. data/tests/data/multipart/data.14 +3 -0
  31. data/tests/data/multipart/data.15 +3 -0
  32. data/tests/data/multipart/data.16 +3 -0
  33. data/tests/data/multipart/data.17 +0 -0
  34. data/tests/data/multipart/data.2 +5 -0
  35. data/tests/data/multipart/data.3 +2 -0
  36. data/tests/data/multipart/data.4 +3 -0
  37. data/tests/data/multipart/data.5 +1 -0
  38. data/tests/data/multipart/data.6 +2 -0
  39. data/tests/data/multipart/data.7 +3 -0
  40. data/tests/data/multipart/data.8 +5 -0
  41. data/tests/data/multipart/data.9 +4 -0
  42. data/tests/data/parser.badmime1 +4 -0
  43. data/tests/data/parser.badmime2 +6 -0
  44. data/tests/data/parser.nested-multipart +75 -0
  45. data/tests/data/parser.nested-simple +12 -0
  46. data/tests/data/parser.nested-simple2 +16 -0
  47. data/tests/data/parser.nested-simple3 +21 -0
  48. data/tests/data/parser.rfc822 +65 -0
  49. data/tests/data/parser.simple-mime +24 -0
  50. data/tests/data/parser/multipart.1 +8 -0
  51. data/tests/data/parser/multipart.10 +4 -0
  52. data/tests/data/parser/multipart.11 +12 -0
  53. data/tests/data/parser/multipart.12 +12 -0
  54. data/tests/data/parser/multipart.13 +6 -0
  55. data/tests/data/parser/multipart.14 +6 -0
  56. data/tests/data/parser/multipart.15 +6 -0
  57. data/tests/data/parser/multipart.16 +6 -0
  58. data/tests/data/parser/multipart.2 +8 -0
  59. data/tests/data/parser/multipart.3 +5 -0
  60. data/tests/data/parser/multipart.4 +6 -0
  61. data/tests/data/parser/multipart.5 +4 -0
  62. data/tests/data/parser/multipart.6 +5 -0
  63. data/tests/data/parser/multipart.7 +6 -0
  64. data/tests/data/parser/multipart.8 +8 -0
  65. data/tests/data/parser/multipart.9 +7 -0
  66. data/tests/data/transparency/absolute.1 +5 -0
  67. data/tests/data/transparency/absolute.2 +1 -0
  68. data/tests/data/transparency/absolute.3 +2 -0
  69. data/tests/data/transparency/absolute.4 +3 -0
  70. data/tests/data/transparency/absolute.5 +4 -0
  71. data/tests/data/transparency/absolute.6 +49 -0
  72. data/tests/data/transparency/message.1 +73 -0
  73. data/tests/data/transparency/message.2 +34 -0
  74. data/tests/data/transparency/message.3 +63 -0
  75. data/tests/data/transparency/message.4 +5 -0
  76. data/tests/data/transparency/message.5 +15 -0
  77. data/tests/data/transparency/message.6 +1185 -0
  78. data/tests/runtests.rb +35 -0
  79. data/tests/testaddress.rb +1192 -0
  80. data/tests/testbase.rb +207 -0
  81. data/tests/testheader.rb +1207 -0
  82. data/tests/testmailbox.rb +47 -0
  83. data/tests/testmboxreader.rb +161 -0
  84. data/tests/testmessage.rb +257 -0
  85. data/tests/testparser.rb +634 -0
  86. data/tests/testparsermultipart.rb +205 -0
  87. data/tests/testpushbackreader.rb +40 -0
  88. data/tests/testserialize.rb +264 -0
  89. data/tests/testtestbase.rb +112 -0
  90. data/tests/testtranspparency.rb +105 -0
  91. metadata +143 -0
@@ -0,0 +1,59 @@
1
+ #--
2
+ # Copyright (C) 2002, 2003 Matt Armstrong. All rights reserved.
3
+ #
4
+ # Redistribution and use in source and binary forms, with or without
5
+ # modification, are permitted provided that the following conditions are met:
6
+ #
7
+ # 1. Redistributions of source code must retain the above copyright notice,
8
+ # this list of conditions and the following disclaimer.
9
+ # 2. Redistributions in binary form must reproduce the above copyright
10
+ # notice, this list of conditions and the following disclaimer in the
11
+ # documentation and/or other materials provided with the distribution.
12
+ # 3. The name of the author may not be used to endorse or promote products
13
+ # derived from this software without specific prior written permission.
14
+ #
15
+ # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16
+ # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17
+ # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
18
+ # NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19
+ # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
20
+ # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
22
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+ #
26
+ #++
27
+ # Implements the RMail::Utils module.
28
+
29
+ module RMail
30
+
31
+ # The RMail::Utils module is a collection of random utility methods
32
+ # that are useful for dealing with email.
33
+ module Utils
34
+
35
+ class << self
36
+
37
+ # Return the given string unquoted if it is quoted.
38
+ def unquote(str)
39
+ if str =~ /\s*"(.*?([^\\]|\\\\))"/m
40
+ $1.gsub(/\\(.)/, '\1')
41
+ else
42
+ str
43
+ end
44
+ end
45
+
46
+ # Decode the given string as if it were a chunk of base64 data
47
+ def base64_decode(str)
48
+ str.unpack("m*").first
49
+ end
50
+
51
+ # Decode the given string as if it were a chunk of quoted
52
+ # printable data
53
+ def quoted_printable_decode(str)
54
+ str.unpack("M*").first
55
+ end
56
+
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,17 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{rmail}
3
+ s.version = "0.17"
4
+ s.date = Time.now
5
+ s.summary = %q{This is RubyMail, a lightweight mail library containing various utility classes and modules that allow Ruby scripts to parse, modify, and generate MIME mail messages.}
6
+ s.author = %q{Matt Armstrong}
7
+ s.email = %q{matt@lickey.com}
8
+ s.homepage = %q{http://www.lickey.com/rubymail/}
9
+ s.has_rdoc = true
10
+ s.required_ruby_version = Gem::Version::Requirement.new(">= 1.6.7")
11
+ s.files = Dir.glob('**/*')
12
+ s.require_path = %q{lib}
13
+ s.autorequire = %q{rmail}
14
+ s.test_files = ["tests/runtests.rb"]
15
+ s.rdoc_options = ["--main", "README"]
16
+ s.extra_rdoc_files = %w{README NOTES NEWS TODO THANKS}
17
+ end
@@ -0,0 +1,113 @@
1
+ Primarily concerned about mailbox, mailbox-list, and address-list
2
+
3
+ mailbox - sender, resent-sender
4
+
5
+ mailbox-list - from, resent-from
6
+
7
+ address-list - reply-to, to, cc, bcc, resent-to, resent-cc, resent-bcc
8
+
9
+ ----------------------------------------------------------------------
10
+ Tokens
11
+ ----------------------------------------------------------------------
12
+
13
+ Primitive -- these do not appear in Address Spedifications
14
+ ----------------------------------------------------------------------
15
+
16
+ NO-WS-CTL = %d1-8 / ; US-ASCII control characters
17
+ %d11 / ; that do not include the
18
+ %d12 / ; carriage return, line feed,
19
+ %d14-31 / ; and white space characters
20
+ %d127
21
+
22
+ atext = a-z / A-Z / ; Any character except controls,
23
+ 0-9 /
24
+ "!" / "#" / ; SP, and specials.
25
+ "$" / "%" / ; Used for atoms
26
+ "&" / "'" /
27
+ "*" / "+" /
28
+ "-" / "/" /
29
+ "=" / "?" /
30
+ "^" / "_" /
31
+ "`" / "{" /
32
+ "|" / "}" /
33
+ "~"
34
+
35
+ quoted-pair = "\" (%d0-127)
36
+
37
+ qtext = NO-WS-CTL / ; Non white space controls
38
+ %d33 / ; The rest of the US-ASCII
39
+ %d35-91 / ; characters not including "\"
40
+ %d93-126 ; or the quote character
41
+
42
+ WSP = %d32 / %d09 ; SPACE or TAB
43
+
44
+ ctext = NO-WS-CTL / ; Non white space controls
45
+ %d33-39 / ; The rest of the US-ASCII
46
+ %d42-91 / ; characters not including "(",
47
+ %d93-126 ; ")", or "\"
48
+
49
+ comment = "(" *([FWS] ccontent) [FWS] ")"
50
+
51
+ ccontent = ctext / quoted-pair / comment
52
+
53
+ qcontent = qtext / quoted-pair
54
+
55
+ dtext = NO-WS-CTL / ; Non white space controls
56
+ %d33-90 / ; The rest of the US-ASCII
57
+ %d94-126 ; characters not including "[",
58
+ ; "]", or "\"
59
+
60
+ Less primitive - these appear in Address Specifications
61
+ ----------------------------------------------------------------------
62
+
63
+ FWS = 1*([CRLF] WSP)
64
+
65
+ CFWS = *([FWS] comment) (([FWS] comment) / FWS)
66
+
67
+ atom = [CFWS] 1*atext [CFWS]
68
+
69
+ quoted-string = [CFWS]
70
+ " *([FWS] qcontent) [FWS] "
71
+ [CFWS]
72
+
73
+ phrase = word *(word / "." / CFWS)
74
+
75
+ word = atom / quoted-string
76
+
77
+ dcontent = dtext / quoted-pair
78
+
79
+ ----------------------------------------------------------------------
80
+ Address Specification
81
+ ----------------------------------------------------------------------
82
+
83
+ address-list = 1*([address] [CFWS] "," [CFWS]) [address]
84
+
85
+ address = mailbox / group
86
+
87
+ mailbox = name-addr / addr-spec
88
+
89
+ group = display-name ":" [mailbox-list / CFWS] ";"
90
+ [CFWS]
91
+
92
+ mailbox-list = 1*([mailbox] [CFWS] "," [CFWS]) [mailbox]
93
+
94
+ name-addr = [display-name] angle-addr
95
+
96
+ display-name = phrase
97
+
98
+ angle-addr = [CFWS] "<" [obs-route] addr-spec ">" [CFWS]
99
+
100
+ obs-route = [CFWS] obs-domain-list ":" [CFWS]
101
+
102
+ obs-domain-list = "@" domain *(*(CFWS / "," ) [CFWS] "@" domain)
103
+
104
+ domain = domain-literal / obs-domain
105
+
106
+ domain-literal = [CFWS] "[" *([FWS] dcontent) [FWS] "]" [CFWS]
107
+
108
+ obs-domain = atom *("." atom)
109
+
110
+ addr-spec = local-part "@" domain
111
+
112
+ local-part = word *("." word)
113
+
@@ -0,0 +1,4 @@
1
+ From foo@bar Wed Nov 27 12:27:36 2002
2
+ message1
3
+ From foo@bar Wed Nov 27 12:27:40 2002
4
+ message2
@@ -0,0 +1,8 @@
1
+ From foo@bar Wed Nov 27 12:27:32 2002
2
+ message1
3
+
4
+ From foo@bar Wed Nov 27 12:27:36 2002
5
+ message2
6
+
7
+ From foo@bar Wed Nov 27 12:27:40 2002
8
+ message3
@@ -0,0 +1,5 @@
1
+ preamble
2
+ --aa
3
+ part1
4
+ --aa--
5
+ epilogue
@@ -0,0 +1 @@
1
+ --aa--
@@ -0,0 +1,9 @@
1
+ preamble
2
+ --aa
3
+ part1
4
+ --aa
5
+ part2
6
+ --aa
7
+ part3
8
+ --aa--
9
+ epilogue
@@ -0,0 +1,9 @@
1
+ preamble
2
+ --aaZ
3
+ part1
4
+ --aa notignored
5
+ part2
6
+ --aa notignored
7
+ part3
8
+ --aa--notignored
9
+ epilogue
@@ -0,0 +1,3 @@
1
+ preamble
2
+ --aa
3
+ part1
@@ -0,0 +1,3 @@
1
+ preamble
2
+ --aa
3
+ part1
@@ -0,0 +1,3 @@
1
+ preamble
2
+ line1
3
+ line2
@@ -0,0 +1,3 @@
1
+ preamble
2
+ line1
3
+ line2
File without changes
@@ -0,0 +1,5 @@
1
+
2
+ --aa
3
+
4
+ --aa--
5
+
@@ -0,0 +1,2 @@
1
+ --aa
2
+ --aa--
@@ -0,0 +1,3 @@
1
+ preamble
2
+ --aa--
3
+ epilogue
@@ -0,0 +1 @@
1
+ --aa--
@@ -0,0 +1,2 @@
1
+
2
+ --aa--
@@ -0,0 +1,3 @@
1
+ preamble
2
+
3
+ --aa--
@@ -0,0 +1,5 @@
1
+ preamble
2
+ --aa
3
+ part1
4
+ --aa--
5
+ epilogue
@@ -0,0 +1,4 @@
1
+
2
+ --aa
3
+
4
+ --aa--
@@ -0,0 +1,4 @@
1
+ MIME-Version: 1.0
2
+ Content-Type: multipart/alternative; boundary=X
3
+
4
+ --X--
@@ -0,0 +1,6 @@
1
+ MIME-Version: 1.0
2
+ Content-Type: multipart/alternative; boundary=X
3
+
4
+ preamble
5
+ --X--
6
+ epilogue
@@ -0,0 +1,75 @@
1
+ Return-Path: <matt@lickey.com>
2
+ Delivered-To: matt@lickey.com
3
+ Received: from localhost (localhost [127.0.0.1])
4
+ by squeaker.lickey.com (Postfix) with ESMTP id 78B08C0BE
5
+ for <matt@lickey.com>; Thu, 7 Feb 2002 19:35:13 -0700 (MST)
6
+ Received: by squeaker.lickey.com (Postfix, from userid 1000)
7
+ id 52497BE6D; Thu, 7 Feb 2002 19:35:12 -0700 (MST)
8
+ To: matt@lickey.com
9
+ Subject: Some nested multiparts
10
+ From: Matt Armstrong <matt@lickey.com>
11
+ Date: Thu, 07 Feb 2002 19:35:11 -0700
12
+ X-Gnus-Mail-Source: directory:~/.incoming
13
+ Message-ID: <877kpolmzk.fsf@squeaker.lickey.com>
14
+ User-Agent: Gnus/5.090006 (Oort Gnus v0.06) Emacs/21.1
15
+ (i386-debian-linux-gnu)
16
+ MIME-Version: 1.0
17
+ Content-Type: multipart/mixed; boundary="=-=-="
18
+ X-Virus-Scanned: by AMaViS snapshot-20010714
19
+ Lines: 45
20
+ Xref: squeaker.lickey.com inbox:7709
21
+
22
+ This is level 1's preamble.
23
+
24
+ --=-=-=
25
+
26
+ Let's see here.
27
+
28
+ --=-=-=
29
+ Content-Disposition: inline
30
+
31
+ This is the first part.
32
+
33
+ --=-=-=
34
+ Content-Type: multipart/mixed; boundary="==-=-="
35
+
36
+ This is level 2's preamble.
37
+
38
+ --==-=-=
39
+ Content-Disposition: inline
40
+
41
+ This is the first nested part.
42
+
43
+ --==-=-=
44
+ Content-Disposition: inline
45
+
46
+ This is the second nested part.
47
+
48
+ --==-=-=
49
+ Content-Type: multipart/mixed; boundary="===-=-="
50
+
51
+ This is level 3's preamble.
52
+
53
+ --===-=-=
54
+
55
+ This is the first doubly nested part.
56
+
57
+ --===-=-=
58
+ Content-Disposition: inline
59
+
60
+ This is the second doubly nested part.
61
+
62
+ --===-=-=--
63
+ This is level 3's epilogue.
64
+
65
+ --==-=-=--
66
+ This is level 2's epilogue. It has no trailing end of line.
67
+ --=-=-=
68
+ Content-Disposition: inline
69
+
70
+ This is the third part.
71
+
72
+ --=-=-=--
73
+
74
+ This is level 1's epilogue.
75
+
@@ -0,0 +1,12 @@
1
+ Content-Type: multipart/mixed; boundary="=-=-="
2
+ MIME-Version: 1.0
3
+
4
+ --=-=-=
5
+ Content-Type: multipart/mixed; boundary="==-=-="
6
+
7
+ --==-=-=
8
+
9
+ --==-=-=
10
+
11
+ --==-=-=--
12
+ --=-=-=--
@@ -0,0 +1,16 @@
1
+ Content-Type: multipart/mixed; boundary="=-=-="
2
+ MIME-Version: 1.0
3
+
4
+
5
+ --=-=-=
6
+ Content-Type: multipart/mixed; boundary="==-=-="
7
+
8
+
9
+ --==-=-=
10
+
11
+ --==-=-=
12
+
13
+ --==-=-=--
14
+
15
+ --=-=-=--
16
+
@@ -0,0 +1,21 @@
1
+ Content-Type: multipart/mixed; boundary="X"
2
+ MIME-Version: 1.0
3
+
4
+
5
+
6
+ --X
7
+ Content-Type: multipart/mixed; boundary="Y"
8
+
9
+
10
+
11
+ --Y
12
+
13
+ --Y
14
+
15
+
16
+ --Y--
17
+
18
+
19
+ --X--
20
+
21
+