sa-tmail 1.2.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (201) hide show
  1. data/CHANGES +74 -0
  2. data/LICENSE +21 -0
  3. data/NOTES +7 -0
  4. data/README +179 -0
  5. data/Rakefile +2 -0
  6. data/ext/Makefile +20 -0
  7. data/ext/tmailscanner/tmail/MANIFEST +4 -0
  8. data/ext/tmailscanner/tmail/depend +1 -0
  9. data/ext/tmailscanner/tmail/extconf.rb +34 -0
  10. data/ext/tmailscanner/tmail/tmailscanner.c +614 -0
  11. data/lib/tmail.rb +6 -0
  12. data/lib/tmail/Makefile +18 -0
  13. data/lib/tmail/address.rb +392 -0
  14. data/lib/tmail/attachments.rb +65 -0
  15. data/lib/tmail/base64.rb +46 -0
  16. data/lib/tmail/compat.rb +41 -0
  17. data/lib/tmail/config.rb +67 -0
  18. data/lib/tmail/core_extensions.rb +63 -0
  19. data/lib/tmail/encode.rb +590 -0
  20. data/lib/tmail/header.rb +962 -0
  21. data/lib/tmail/index.rb +9 -0
  22. data/lib/tmail/interface.rb +1162 -0
  23. data/lib/tmail/loader.rb +3 -0
  24. data/lib/tmail/mail.rb +578 -0
  25. data/lib/tmail/mailbox.rb +496 -0
  26. data/lib/tmail/main.rb +6 -0
  27. data/lib/tmail/mbox.rb +3 -0
  28. data/lib/tmail/net.rb +250 -0
  29. data/lib/tmail/obsolete.rb +132 -0
  30. data/lib/tmail/parser.rb +1060 -0
  31. data/lib/tmail/parser.y +416 -0
  32. data/lib/tmail/port.rb +379 -0
  33. data/lib/tmail/quoting.rb +155 -0
  34. data/lib/tmail/require_arch.rb +58 -0
  35. data/lib/tmail/scanner.rb +49 -0
  36. data/lib/tmail/scanner_r.rb +261 -0
  37. data/lib/tmail/stringio.rb +280 -0
  38. data/lib/tmail/utils.rb +361 -0
  39. data/lib/tmail/version.rb +39 -0
  40. data/lib/vendor/rchardet-1.3/COPYING +504 -0
  41. data/lib/vendor/rchardet-1.3/README +12 -0
  42. data/lib/vendor/rchardet-1.3/lib/rchardet.rb +67 -0
  43. data/lib/vendor/rchardet-1.3/lib/rchardet/big5freq.rb +927 -0
  44. data/lib/vendor/rchardet-1.3/lib/rchardet/big5prober.rb +42 -0
  45. data/lib/vendor/rchardet-1.3/lib/rchardet/chardistribution.rb +237 -0
  46. data/lib/vendor/rchardet-1.3/lib/rchardet/charsetgroupprober.rb +112 -0
  47. data/lib/vendor/rchardet-1.3/lib/rchardet/charsetprober.rb +75 -0
  48. data/lib/vendor/rchardet-1.3/lib/rchardet/codingstatemachine.rb +64 -0
  49. data/lib/vendor/rchardet-1.3/lib/rchardet/constants.rb +42 -0
  50. data/lib/vendor/rchardet-1.3/lib/rchardet/escprober.rb +90 -0
  51. data/lib/vendor/rchardet-1.3/lib/rchardet/escsm.rb +244 -0
  52. data/lib/vendor/rchardet-1.3/lib/rchardet/eucjpprober.rb +88 -0
  53. data/lib/vendor/rchardet-1.3/lib/rchardet/euckrfreq.rb +596 -0
  54. data/lib/vendor/rchardet-1.3/lib/rchardet/euckrprober.rb +42 -0
  55. data/lib/vendor/rchardet-1.3/lib/rchardet/euctwfreq.rb +430 -0
  56. data/lib/vendor/rchardet-1.3/lib/rchardet/euctwprober.rb +42 -0
  57. data/lib/vendor/rchardet-1.3/lib/rchardet/gb2312freq.rb +474 -0
  58. data/lib/vendor/rchardet-1.3/lib/rchardet/gb2312prober.rb +42 -0
  59. data/lib/vendor/rchardet-1.3/lib/rchardet/hebrewprober.rb +289 -0
  60. data/lib/vendor/rchardet-1.3/lib/rchardet/jisfreq.rb +570 -0
  61. data/lib/vendor/rchardet-1.3/lib/rchardet/jpcntx.rb +229 -0
  62. data/lib/vendor/rchardet-1.3/lib/rchardet/langbulgarianmodel.rb +229 -0
  63. data/lib/vendor/rchardet-1.3/lib/rchardet/langcyrillicmodel.rb +330 -0
  64. data/lib/vendor/rchardet-1.3/lib/rchardet/langgreekmodel.rb +227 -0
  65. data/lib/vendor/rchardet-1.3/lib/rchardet/langhebrewmodel.rb +202 -0
  66. data/lib/vendor/rchardet-1.3/lib/rchardet/langhungarianmodel.rb +226 -0
  67. data/lib/vendor/rchardet-1.3/lib/rchardet/langthaimodel.rb +201 -0
  68. data/lib/vendor/rchardet-1.3/lib/rchardet/latin1prober.rb +147 -0
  69. data/lib/vendor/rchardet-1.3/lib/rchardet/mbcharsetprober.rb +89 -0
  70. data/lib/vendor/rchardet-1.3/lib/rchardet/mbcsgroupprober.rb +47 -0
  71. data/lib/vendor/rchardet-1.3/lib/rchardet/mbcssm.rb +542 -0
  72. data/lib/vendor/rchardet-1.3/lib/rchardet/sbcharsetprober.rb +124 -0
  73. data/lib/vendor/rchardet-1.3/lib/rchardet/sbcsgroupprober.rb +58 -0
  74. data/lib/vendor/rchardet-1.3/lib/rchardet/sjisprober.rb +88 -0
  75. data/lib/vendor/rchardet-1.3/lib/rchardet/universaldetector.rb +166 -0
  76. data/lib/vendor/rchardet-1.3/lib/rchardet/utf8prober.rb +87 -0
  77. data/log/BugTrackingLog.txt +1245 -0
  78. data/log/Changelog.txt +534 -0
  79. data/log/Testlog.txt +2340 -0
  80. data/log/Todo.txt +30 -0
  81. data/meta/MANIFEST +128 -0
  82. data/meta/VERSION +1 -0
  83. data/meta/project.yaml +30 -0
  84. data/meta/unixname +1 -0
  85. data/sample/bench_base64.rb +48 -0
  86. data/sample/data/multipart +23 -0
  87. data/sample/data/normal +29 -0
  88. data/sample/data/sendtest +5 -0
  89. data/sample/data/simple +14 -0
  90. data/sample/data/test +27 -0
  91. data/sample/extract-attachements.rb +33 -0
  92. data/sample/from-check.rb +26 -0
  93. data/sample/multipart.rb +26 -0
  94. data/sample/parse-bench.rb +68 -0
  95. data/sample/parse-test.rb +19 -0
  96. data/sample/sendmail.rb +94 -0
  97. data/setup.rb +1482 -0
  98. data/site/contributing/index.html +183 -0
  99. data/site/css/clean.css +27 -0
  100. data/site/css/layout.css +31 -0
  101. data/site/css/style.css +60 -0
  102. data/site/download/index.html +61 -0
  103. data/site/img/envelope.jpg +0 -0
  104. data/site/img/mailman.gif +0 -0
  105. data/site/img/stamp-sm.jpg +0 -0
  106. data/site/img/stamp.jpg +0 -0
  107. data/site/img/stampborder.jpg +0 -0
  108. data/site/img/tfire.jpg +0 -0
  109. data/site/img/tmail.png +0 -0
  110. data/site/index.html +272 -0
  111. data/site/js/jquery.js +31 -0
  112. data/site/log/Changelog.xsl +33 -0
  113. data/site/log/changelog.xml +1677 -0
  114. data/site/outdated/BUGS +3 -0
  115. data/site/outdated/DEPENDS +1 -0
  116. data/site/outdated/Incompatibilities +89 -0
  117. data/site/outdated/Incompatibilities.ja +102 -0
  118. data/site/outdated/NEWS +9 -0
  119. data/site/outdated/README.ja +73 -0
  120. data/site/outdated/doc.ja/address.html +275 -0
  121. data/site/outdated/doc.ja/basics.html +405 -0
  122. data/site/outdated/doc.ja/config.html +49 -0
  123. data/site/outdated/doc.ja/details.html +146 -0
  124. data/site/outdated/doc.ja/index.html +39 -0
  125. data/site/outdated/doc.ja/mail.html +793 -0
  126. data/site/outdated/doc.ja/mailbox.html +265 -0
  127. data/site/outdated/doc.ja/port.html +95 -0
  128. data/site/outdated/doc.ja/tmail.html +58 -0
  129. data/site/outdated/doc.ja/usage.html +202 -0
  130. data/site/outdated/rdd/address.rrd.m +229 -0
  131. data/site/outdated/rdd/basics.rd.m +275 -0
  132. data/site/outdated/rdd/config.rrd.m +26 -0
  133. data/site/outdated/rdd/details.rd.m +117 -0
  134. data/site/outdated/rdd/index.rhtml.m +54 -0
  135. data/site/outdated/rdd/mail.rrd.m +701 -0
  136. data/site/outdated/rdd/mailbox.rrd.m +228 -0
  137. data/site/outdated/rdd/port.rrd.m +69 -0
  138. data/site/outdated/rdd/tmail.rrd.m +33 -0
  139. data/site/outdated/rdd/usage.rd.m +247 -0
  140. data/site/quickstart/index.html +69 -0
  141. data/site/quickstart/quickstart.html +52 -0
  142. data/site/quickstart/usage.html +193 -0
  143. data/site/reference/address.html +247 -0
  144. data/site/reference/config.html +30 -0
  145. data/site/reference/index.html +101 -0
  146. data/site/reference/mail.html +726 -0
  147. data/site/reference/mailbox.html +245 -0
  148. data/site/reference/port.html +75 -0
  149. data/site/reference/tmail.html +35 -0
  150. data/test/extctrl.rb +6 -0
  151. data/test/fixtures/mailbox +414 -0
  152. data/test/fixtures/mailbox_without_any_from_or_sender +10 -0
  153. data/test/fixtures/mailbox_without_from +11 -0
  154. data/test/fixtures/mailbox_without_return_path +12 -0
  155. data/test/fixtures/raw_attack_email_with_zero_length_whitespace +29 -0
  156. data/test/fixtures/raw_base64_decoded_string +0 -0
  157. data/test/fixtures/raw_base64_email +83 -0
  158. data/test/fixtures/raw_base64_encoded_string +1 -0
  159. data/test/fixtures/raw_email +14 -0
  160. data/test/fixtures/raw_email10 +20 -0
  161. data/test/fixtures/raw_email11 +34 -0
  162. data/test/fixtures/raw_email12 +32 -0
  163. data/test/fixtures/raw_email13 +29 -0
  164. data/test/fixtures/raw_email2 +114 -0
  165. data/test/fixtures/raw_email3 +70 -0
  166. data/test/fixtures/raw_email4 +59 -0
  167. data/test/fixtures/raw_email5 +19 -0
  168. data/test/fixtures/raw_email6 +20 -0
  169. data/test/fixtures/raw_email7 +66 -0
  170. data/test/fixtures/raw_email8 +47 -0
  171. data/test/fixtures/raw_email9 +28 -0
  172. data/test/fixtures/raw_email_multiple_from +30 -0
  173. data/test/fixtures/raw_email_quoted_with_0d0a +14 -0
  174. data/test/fixtures/raw_email_reply +32 -0
  175. data/test/fixtures/raw_email_simple +11 -0
  176. data/test/fixtures/raw_email_with_bad_date +48 -0
  177. data/test/fixtures/raw_email_with_illegal_boundary +58 -0
  178. data/test/fixtures/raw_email_with_mimepart_without_content_type +94 -0
  179. data/test/fixtures/raw_email_with_multipart_mixed_quoted_boundary +50 -0
  180. data/test/fixtures/raw_email_with_nested_attachment +100 -0
  181. data/test/fixtures/raw_email_with_partially_quoted_subject +14 -0
  182. data/test/fixtures/raw_email_with_quoted_illegal_boundary +58 -0
  183. data/test/kcode.rb +14 -0
  184. data/test/temp_test_one.rb +46 -0
  185. data/test/test_address.rb +1216 -0
  186. data/test/test_attachments.rb +131 -0
  187. data/test/test_base64.rb +64 -0
  188. data/test/test_encode.rb +139 -0
  189. data/test/test_header.rb +1021 -0
  190. data/test/test_helper.rb +9 -0
  191. data/test/test_mail.rb +756 -0
  192. data/test/test_mbox.rb +184 -0
  193. data/test/test_port.rb +440 -0
  194. data/test/test_quote.rb +107 -0
  195. data/test/test_scanner.rb +209 -0
  196. data/test/test_utils.rb +36 -0
  197. data/work/script/make +26 -0
  198. data/work/script/rdoc +39 -0
  199. data/work/script/setup +1616 -0
  200. data/work/script/test +30 -0
  201. metadata +309 -0
data/CHANGES ADDED
@@ -0,0 +1,74 @@
1
+ === 1.2.3.1 / 2008-04-11
2
+
3
+ * Closed #19429 - Installing TMail on Windows with the gem
4
+
5
+ === 1.2.3 / 2008-04-11
6
+
7
+ * Closed #18881 - TMail goes into an endless loop if sent an crafted email
8
+ * Closed #19203 - TMail errors in Ruby 1.9.1 on invalid multibyte chars.
9
+ * Closed #18814 - Fixed attchment.rb failing on mail part that had a nil content-type
10
+ * Closed #18516 - Fix TMail::Mail#preamble, and add #preamble= (Charles Lowe) (233)
11
+ * Applied patch #18515 to remove ftools from test case (Charles Lowe) (232)
12
+ * A lot of documentation patches to the mail and utils and net files. Also added "log/BugTrackingLog.txt" for myself as my bug log got clobbered by the new changelog.txt format. (231)
13
+
14
+ === 1.2.2 / 2008-03-07
15
+
16
+ * Fixed install bug with gem pacakge (1.2.1 was not compiling on gem install)
17
+ * A _LOT_ more documentation...!
18
+ * More documentation - (Mikel)
19
+ * Applied Ruby 1.9 patches to the library - All tests passing now - (Mikel)
20
+ * Closed #17719 - Fixed UNIXMbox code - readonly was not working and raising an exception. Now works.
21
+ * Closed #18038 - Multiple froms not being parsed correctly, added a test case to cover this and show the correct handling - (Mikel)
22
+
23
+ === 1.2.1 / 2008-01-11
24
+
25
+ * More documentation (Mikel)
26
+ * Added 15 test cases from the Rails ActionMailer to TMail
27
+ * Changed mailscanner to tmailscanner (mailscanner is copyrighted)
28
+ * Closed Bug - Handled quote boundary being gready on content-type header (M. Mondragon)
29
+ * Closed #16025 - Fixed scanner.rb so it passes same tests as scanner.c
30
+ * Closed #16283 - Handled incorrect decoding of attachments (M. Aoki - garyo)
31
+ * Closed #16899 - HeaderField.new_from_port and added test cases to cover this code (Maarten O.)
32
+ * Closed #16900 - UNIXMbox.fromaddr missing port param and does not return Envelope Sender (Maarten O.)
33
+
34
+ === 1.2.0 / 2007-11-29
35
+
36
+ * 5 major enhancements:
37
+ * Extensive documentation work. (mikel)
38
+ * Renamed scanner_c.c to mailscanner.c. (trans)
39
+ * Removed base64 c extension. It's speed benefit was negligable (only 0.2 sec over 10000 sizable encode/decode runs) (trans)
40
+ * Closed 15445 - TMail::Mail#create_forward now returns a new Mail object that has the original mail as an encoded 7 bit multipart attachment. Also moved create_forward and create_reply from tmail/net into tmail/interface as it makes more sense to have it there. (mikel)
41
+ * Closed 15643 - TMail::Mail#reply_addresses was returning an empty array if reply_to was set to nil (ie, the header field existed but was empty) instead of returning the from address or default. (mikel)
42
+ * Closed 16025 - TMail scanner.rb would not parse ATOM chars correctly making it fail tests where the C version passed them. Fixed this by updating the Scanner.rb version to be in step with the C version (there was an extra @ symbol in the ATOM CHARS definition that was not in the C version.) (mikel)
43
+ * Fixed scanner.rb so that it would pass the same tests that the C version does - had a sundry @ symbol inside of the ATOM CHARS
44
+ * 3 minor enhancements:
45
+ * Renamed scanner_c.c to tmailscanner.c (trans)
46
+ * Changed TMail::Mail#sender to have a default "default" value of nil to be in alignment with all the other interface methods (mikel)
47
+ * Made base64_decode and base64_encode into ! versions as they are destructive on the mail body (encodes the body to base64 or decodes it), made aliases for base64_decode and base64_encode to point back to the bang versions. Doing this with a view to change base64_encode to a non destructive version (returns the encoded body) in future versions. (mikel)
48
+
49
+ === 1.1.1 / 2007-11-05
50
+
51
+ * 3 major enhancement:
52
+ * Created unified package, for installation in any platform.
53
+ * Added require_arch.rb to facilitate multi-platform support.
54
+ * If compilation fails, set NORUBYEXT="true" and reinstall.
55
+ * 3 minor enhancement:
56
+ * Fixed line wrapping of long header fields so that they wrap at the correct whitespace points.
57
+ * Fixed bug where re-assigning the mail.body to existing mail object that already had a parsed body would not re-parse the body.
58
+ * Started documenting the source code... lots more to do.
59
+
60
+ === 1.1.0 / 2007-10-28
61
+
62
+ * 1 minor enhancements:
63
+ * Changed the quoting of paramaters in the header fields to wrap double quotes around fields that are needed to be quoted.
64
+ * Removed keeping double quotes around a filename that does not need double quotes per RFC 1521
65
+ * More clean up and getting tests passing. Now standing at 2 failures out of 3366 assertions. One is the incorrect handling of "@"@test.com (returns @@test.com) and the other is a japanese encoding issue.
66
+
67
+ === 1.0.0 / 2007-10-28
68
+
69
+ * 1 major enhancement:
70
+ * TMail is now released as a GEM!
71
+ * 2 minor enhancements:
72
+ * Fixed bug 15077 - TMail now recognizes attachments as soon as they are added to the body.
73
+ * Refactored handling of quotations in header fields - now cleaner
74
+
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2001-2007 Minero Aoki
2
+ Changes Copyright (c) 2007 Mikel Lindsaar
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/NOTES ADDED
@@ -0,0 +1,7 @@
1
+ [ANN] TMail 1.2.3.1 - Minor Fix to Installer
2
+
3
+ This release just handles a bug with installing the gem on a Windows platform.
4
+
5
+ It is otherwise identical to 1.2.3
6
+
7
+ Mikel
data/README ADDED
@@ -0,0 +1,179 @@
1
+ = TMail
2
+
3
+ http://tmail.rubyforge.org/
4
+
5
+ Mikel Lindsaar maintainer
6
+ Trans assitant developer
7
+ Minero Aoki original developer
8
+
9
+ == RUBY 1.9 COMPATIBILITY
10
+
11
+ Note... as of 1.2.5, TMail is not compatible with Ruby 1.9.1. We are now using rchardet
12
+ to compare encodings and there is work to do for Ruby 1.9.1 due to it's encoding
13
+ capability.
14
+
15
+ For 1.9.1 + compatibility, I suggest you look at Mail (https://github.com/mikel/mail/tree)
16
+ while this is a work in progress, it is what I am working on to replace TMail for Ruby
17
+ 1.9 and beyond.
18
+
19
+ == DESCRIPTION:
20
+
21
+ TMail is a mail handling library for Ruby. It abstracts a mail message into a usable object allowing you to read, set, add and delete headers and the mail body.
22
+
23
+ TMail is used by the Ruby on Rails web framework as the Email abstraction layer for their ActionMailer module. It is also used by the Nitro framework and many other applications on and off the web.
24
+
25
+ The goal of the TMail handling library is to be able to parse and handle raw Email sources and produce RFC compliant Emails as a result. If you find something that TMail does that violates an RFC, we want to know and we'll get it fixed fast.
26
+
27
+ == DOCUMENTATION:
28
+
29
+ The place you will want to look first is the TMail::Mail class. This has the vast majority of methods you will be using to talk to your TMail object.
30
+
31
+ == FEATURES/PROBLEMS:
32
+
33
+ TMail is fairly RFC compliant on the handling of emails.
34
+
35
+ There are also some problems in the header handling, but for 99.9% of email, you will be fine. Usually, the problems revolve around parsing incomming emails and making sense of them.
36
+
37
+ I really welcome any examples of Emails that "didn't work" with TMail so I can use them as test cases.
38
+
39
+ == SYNOPSIS:
40
+
41
+ TMail is very easy to use. You simply require the library and then pass a raw email text message into the TMail::Mail.parse method. This returns a TMail::Mail object which you can now query and run methods against to modify, inspect or add to the Email.
42
+
43
+ You can find almost all of the methods that you will use to talk to and update a TMail instance in the TMail::Mail class. I am constantly updating this code, with comments, added a fair bit and have a lot more to go!.
44
+
45
+ === Short Version:
46
+
47
+ irb(main):001:0> require 'tmail'
48
+ irb(main):002:0> raw_email = File.open("my_raw_email", 'r') { |f| @mail = f.read }
49
+ irb(main):003:0> email = TMail::Mail.parse(raw_email)
50
+ irb(main):004:0> puts email['to']
51
+ mikel@example.com
52
+ => nil
53
+ irb(main):005:0> email['to'] = 'mikel@somewhere.else.com'
54
+ => "mikel@somewhere.else.com"
55
+ irb(main):006:0> puts email['to']
56
+ mikel@somewhere.else.com
57
+ => nil
58
+
59
+ === Longer Version:
60
+
61
+ Assuming you have a single raw email in the variable my_message, you can do the following:
62
+
63
+ require 'tmail'
64
+ email = TMail::Mail.parse(my_message)
65
+
66
+ This will give you a TMail::Mail class containing your parsed message. There are other methods of opening emails through Ports.
67
+
68
+ You can view this email by a simple puts:
69
+
70
+ puts email
71
+
72
+ Return-Path: <mikel@nowhere.com>
73
+ Date: Sun, 21 Oct 2007 19:38:13 +1000
74
+ From: Mikel Lindsaar <mikel@nowhere.com>
75
+ To: mikel@somewhere.com
76
+ Message-Id: <009601c813c6$19df3510$0437d30a@mikel091a>
77
+ Subject: Testing Email
78
+
79
+ Hello Mikel
80
+
81
+ Easy right?
82
+
83
+ === Adding a header to the EMail:
84
+
85
+ Say now that you have opened your message, you want to put in a Reply-To field. You do this like so:
86
+
87
+ email['reply-to'] = "My Email Address <my_address@anotherplace.com>"
88
+
89
+ Is it really there? Well, find out with a puts:
90
+
91
+ puts email
92
+
93
+ Return-Path: <mikel@nowhere.com>
94
+ Date: Sun, 21 Oct 2007 19:38:13 +1000
95
+ From: Mikel Lindsaar <mikel@nowhere.com>
96
+ Reply-To: My Email Address <my_address@anotherplace.com>
97
+ To: mikel@somewhere.com
98
+ Message-Id: <009601c813c6$19df3510$0437d30a@mikel091a>
99
+ Subject: Testing Email
100
+
101
+ Hello Mikel
102
+
103
+ Yup looks good.
104
+
105
+ === Inspecting a header:
106
+
107
+ You can then inspect your added header by doing:
108
+
109
+ email['reply-to'] # => #<TMail::AddressHeader "My Email Address <my_address@anotherplace.com>">
110
+
111
+ If you just want to the actual value, not the AddressHeader object, pass to_s to this.
112
+
113
+ email['reply-to'].to_s # => "My Email Address <my_address@anotherplace.com>"
114
+
115
+ === Deleting a header:
116
+
117
+ One way of deleting a header from an Email is just assigning it nil like so:
118
+
119
+ email['reply-to'] = nil # => nil
120
+
121
+ If you now puts the email again, it will not be included:
122
+
123
+ puts email
124
+
125
+ Return-Path: <mikel@nowhere.com>
126
+ Date: Sun, 21 Oct 2007 19:38:13 +1000
127
+ From: Mikel Lindsaar <mikel@nowhere.com>
128
+ To: mikel@somewhere.com
129
+ Message-Id: <009601c813c6$19df3510$0437d30a@mikel091a>
130
+ Subject: Testing Email
131
+
132
+ Hello Mikel
133
+
134
+ === Writing out an Email:
135
+
136
+ You can just call to_s on any email to have it serialized out as a single string with the right number of line breaks and encodings.
137
+
138
+ == CONTRIBUTING:
139
+
140
+ You can visit the {Contributing to TMail}[link:http://tmail.rubyforge.org/contributing/] to find out how to contribute to TMail, developers are welcome and wanted!
141
+
142
+ == REQUIREMENTS:
143
+
144
+ * C compiler if you want the Ruby extension for Scanner
145
+ * Ruby 1.8 or later
146
+
147
+ == INSTALLATION:
148
+
149
+ * sudo gem install tmail
150
+
151
+ Or manually,
152
+
153
+ * sudo script/setup
154
+
155
+ == LICENSE:
156
+
157
+ (The MIT License)
158
+
159
+ Copyright (c) 2007 FIX
160
+
161
+ Permission is hereby granted, free of charge, to any person obtaining
162
+ a copy of this software and associated documentation files (the
163
+ 'Software'), to deal in the Software without restriction, including
164
+ without limitation the rights to use, copy, modify, merge, publish,
165
+ distribute, sublicense, and/or sell copies of the Software, and to
166
+ permit persons to whom the Software is furnished to do so, subject to
167
+ the following conditions:
168
+
169
+ The above copyright notice and this permission notice shall be
170
+ included in all copies or substantial portions of the Software.
171
+
172
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
173
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
174
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
175
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
176
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
177
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
178
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
179
+
@@ -0,0 +1,2 @@
1
+ require File.join(File.dirname(__FILE__), "setup.rb")
2
+
@@ -0,0 +1,20 @@
1
+ #
2
+ # ext/tmail/Makefile
3
+ #
4
+
5
+ .PHONY: tmailscanner clean distclean
6
+
7
+ all: tmailscanner
8
+
9
+ tmailscanner: tmailscanner/tmail/Makefile
10
+ cd tmailscanner/tmail; $(MAKE)
11
+
12
+ tmailscanner/tmail/Makefile: tmailscanner/tmail/extconf.rb
13
+ cd tmailscanner/tmail; ruby extconf.rb
14
+
15
+ clean:
16
+ cd tmailscanner/tmail; $(MAKE) clean
17
+
18
+ distclean:
19
+ cd tmailscanner/tmail; $(MAKE) distclean
20
+
@@ -0,0 +1,4 @@
1
+ MANIFEST
2
+ tmailscanner.c
3
+ extconf.rb
4
+ depend
@@ -0,0 +1 @@
1
+ tmailscanner.o: tmailscanner.c $(hdrdir)/ruby.h $(topdir)/config.h $(hdrdir)/defines.h Makefile
@@ -0,0 +1,34 @@
1
+ require 'mkmf'
2
+ require 'rbconfig'
3
+
4
+ extension_name = 'tmailscanner'
5
+
6
+ windows = (/djgpp|(cyg|ms|bcc)win|mingw/ =~ RUBY_PLATFORM)
7
+ java = (/java/ =~ RUBY_PLATFORM)
8
+
9
+ # For now use pure Ruby tmailscanner if on Windows, since
10
+ # most Window's users don't have developer tools needed.
11
+
12
+ if (ENV['NORUBYEXT'] == 'true' || windows || java)
13
+ if windows
14
+ File.open('make.bat', 'w') do |f|
15
+ f << 'echo Native extension will be omitted.'
16
+ end
17
+ File.open('nmake.bat', 'w') do |f|
18
+ f << 'echo Native extension will be omitted.'
19
+ end
20
+ end
21
+ File.open('Makefile', 'w') do |f|
22
+ f << "all:\n"
23
+ f << "install:\n"
24
+ end
25
+ else
26
+ #dir_config(extension_name)
27
+ if windows && ENV['make'].nil?
28
+ $LIBS += " msvcprt.lib"
29
+ else
30
+ $CFLAGS += " -D_FILE_OFFSET_BITS=64" #???
31
+ end
32
+ create_makefile(extension_name)
33
+ end
34
+
@@ -0,0 +1,614 @@
1
+ /*
2
+
3
+ tmailscanner.c
4
+
5
+ Copyright (c) 1998-2007 Minero Aoki
6
+
7
+ This program is free software.
8
+ You can distribute/modify this program under the terms of
9
+ the GNU Lesser General Public License version 2.1.
10
+
11
+ */
12
+
13
+ #include <stdio.h>
14
+ #ifdef __STDC__
15
+ # include <stdlib.h>
16
+ #endif
17
+
18
+
19
+ #include "ruby.h"
20
+ #ifndef RSTRING_PTR
21
+ #define RSTRING_PTR(obj) RSTRING(obj)->ptr
22
+ #endif
23
+
24
+ #ifndef RSTRING_LEN
25
+ #define RSTRING_LEN(obj) RSTRING(obj)->len
26
+ #endif
27
+
28
+ #ifdef HAVE_RUBY_VM_H
29
+ #include "ruby/re.h"
30
+ #include "ruby/encoding.h"
31
+ #else
32
+ #include "re.h"
33
+ #endif
34
+
35
+ #ifdef HAVE_RUBY_VM_H
36
+ const unsigned char *re_mbctab;
37
+ #define ismbchar(c) re_mbctab[(unsigned char)(c)]
38
+ #endif
39
+
40
+ #define TMAIL_VERSION "1.2.3"
41
+
42
+ static VALUE TMailScanner;
43
+ static VALUE ScanError;
44
+
45
+ struct scanner
46
+ {
47
+ char *pbeg;
48
+ char *p;
49
+ char *pend;
50
+ unsigned int flags;
51
+ VALUE comments;
52
+ };
53
+
54
+ #define MODE_MIME (1 << 0)
55
+ #define MODE_RECV (1 << 1)
56
+ #define MODE_ISO2022 (1 << 2)
57
+ #define MODE_DEBUG (1 << 4)
58
+
59
+ #define MIME_MODE_P(s) ((s)->flags & MODE_MIME)
60
+ #define RECV_MODE_P(s) ((s)->flags & MODE_RECV)
61
+ #define ISO2022_MODE_P(s) ((s)->flags & MODE_ISO2022)
62
+
63
+ #define GET_SCANNER(val, s) Data_Get_Struct(val, struct scanner, s)
64
+
65
+
66
+ static void
67
+ mails_free(sc)
68
+ struct scanner *sc;
69
+ {
70
+ free(sc);
71
+ }
72
+
73
+ #ifndef StringValue
74
+ # define StringValue(s) Check_Type(str, T_STRING);
75
+ #endif
76
+
77
+ /*
78
+ * Document-method: mails_s_new
79
+ *
80
+ * Creates a new mail
81
+ *
82
+ */
83
+ static VALUE
84
+ mails_s_new(klass, str, ident, cmt)
85
+ VALUE klass, str, ident, cmt;
86
+ {
87
+ struct scanner *sc;
88
+ const char *tmp;
89
+
90
+ sc = ALLOC_N(struct scanner, 1);
91
+
92
+ StringValue(str);
93
+ sc->pbeg = RSTRING_PTR(str);
94
+ sc->p = sc->pbeg;
95
+ sc->pend = sc->p + RSTRING_LEN(str);
96
+
97
+ sc->flags = 0;
98
+ Check_Type(ident, T_SYMBOL);
99
+ tmp = rb_id2name(SYM2ID(ident));
100
+ if (strcmp(tmp, "RECEIVED") == 0) sc->flags |= MODE_RECV;
101
+ else if (strcmp(tmp, "CTYPE") == 0) sc->flags |= MODE_MIME;
102
+ else if (strcmp(tmp, "CENCODING") == 0) sc->flags |= MODE_MIME;
103
+ else if (strcmp(tmp, "CDISPOSITION") == 0) sc->flags |= MODE_MIME;
104
+
105
+ tmp = rb_get_kcode();
106
+ if (strcmp(tmp, "EUC") == 0 || strcmp(tmp, "SJIS") == 0) {
107
+ sc->flags |= MODE_ISO2022;
108
+ }
109
+
110
+ sc->comments = Qnil;
111
+ if (! NIL_P(cmt)) {
112
+ Check_Type(cmt, T_ARRAY);
113
+ sc->comments = cmt;
114
+ }
115
+
116
+ return Data_Wrap_Struct(TMailScanner, 0, mails_free, sc);
117
+ }
118
+
119
+ /*
120
+ * Document-method: mails_debug_get
121
+ *
122
+ * TODO: Documentation needed
123
+ *
124
+ */
125
+ static VALUE
126
+ mails_debug_get(self)
127
+ VALUE self;
128
+ {
129
+ struct scanner *sc;
130
+
131
+ GET_SCANNER(self, sc);
132
+ if (sc->flags & MODE_DEBUG)
133
+ return Qtrue;
134
+ else
135
+ return Qfalse;
136
+ }
137
+
138
+ /*
139
+ * Document-method: mails_debug_set
140
+ *
141
+ * TODO: Documentation needed
142
+ *
143
+ */
144
+ static VALUE
145
+ mails_debug_set(self, flag)
146
+ VALUE self, flag;
147
+ {
148
+ struct scanner *sc;
149
+
150
+ GET_SCANNER(self, sc);
151
+ if (RTEST(flag))
152
+ sc->flags |= MODE_DEBUG;
153
+ else
154
+ sc->flags &= ~MODE_DEBUG;
155
+ return Qnil;
156
+ }
157
+
158
+
159
+ /*
160
+ ----------------------------------------------------------------------
161
+ scanning routines
162
+ ----------------------------------------------------------------------
163
+ */
164
+
165
+ #define ESC '\033'
166
+ #define ATOM_SYMBOLS "_#!$%&'`*+-{|}~^/=?"
167
+ #define TOKEN_SYMBOLS "_#!$%&'`*+-{|}~^."
168
+ #define ATOM_SPECIAL "()<>[]@,;:\"\\."
169
+ #define TOKEN_SPECIAL "()<>[]@,;:\"\\/?="
170
+ #define LWSP " \t\r\n"
171
+
172
+ #define IS_ALPHA(ch) (('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z'))
173
+ #define IS_UPPER(ch) ('A' <= ch && ch <= 'Z')
174
+ #define TO_LOWER(ch) (IS_UPPER(ch) ? ch + 32 : ch)
175
+ #define IS_LWSP(ch) (strchr(LWSP, ch))
176
+ #define IS_DIGIT(ch) ('0' <= ch && ch <= '9')
177
+ #define IS_WORDCHAR(ch, symlist) \
178
+ (IS_ALPHA(ch) || IS_DIGIT(ch) || strchr(symlist, ch))
179
+ #define IS_ATOMCHAR(ch) IS_WORDCHAR(ch, ATOM_SYMBOLS)
180
+ #define IS_TOKENCHAR(ch) IS_WORDCHAR(ch, TOKEN_SYMBOLS)
181
+ #define IS_JCHAR(ch) ismbchar(ch)
182
+
183
+
184
+ /* I know this implement is ugly, but usually useful. */
185
+
186
+ /* skip until "\e(B" (us-ascii) */
187
+ static void
188
+ skip_iso2022jp_string(sc)
189
+ struct scanner *sc;
190
+ {
191
+ for (; sc->p < sc->pend; sc->p++) {
192
+ if (*sc->p == ESC) {
193
+ if (strncmp(sc->p, "\033(B", 3) == 0) {
194
+ sc->p += 3;
195
+ return;
196
+ }
197
+ }
198
+ }
199
+ }
200
+
201
+ #ifdef HAVE_RUBY_VM_H
202
+ static void
203
+ skip_japanese_string(sc)
204
+ struct scanner *sc;
205
+ {
206
+ while(sc->p < sc->pend) {
207
+ if (! ismbchar(*sc->p)) return;
208
+ rb_encoding *enc = rb_enc_get(sc);
209
+ sc->p += mbclen(sc->p, sc->pend, enc);
210
+ }
211
+ }
212
+ #else
213
+ static void
214
+ skip_japanese_string(sc)
215
+ struct scanner *sc;
216
+ {
217
+ while (sc->p < sc->pend) {
218
+ if (! ismbchar(*sc->p)) return;
219
+ sc->p += mbclen(*sc->p);
220
+ }
221
+ }
222
+ #endif
223
+
224
+
225
+ #define scan_atom(sc) scan_word(sc, ATOM_SYMBOLS)
226
+ #define scan_token(sc) scan_word(sc, TOKEN_SYMBOLS)
227
+
228
+ static VALUE
229
+ scan_word(sc, syms)
230
+ struct scanner *sc;
231
+ char *syms;
232
+ {
233
+ char *beg = sc->p;
234
+
235
+ while (sc->p < sc->pend) {
236
+ if (ISO2022_MODE_P(sc) && *sc->p == ESC) {
237
+ skip_iso2022jp_string(sc);
238
+ }
239
+ else if (IS_JCHAR(*sc->p)) {
240
+ skip_japanese_string(sc);
241
+ }
242
+ else if (IS_WORDCHAR(*sc->p, syms)) {
243
+ sc->p++;
244
+ }
245
+ else {
246
+ break;
247
+ }
248
+ }
249
+
250
+ return rb_str_new(beg, sc->p - beg);
251
+ }
252
+
253
+
254
+ #define BUFSIZE 256
255
+
256
+ static VALUE
257
+ scan_quoted_word(sc)
258
+ struct scanner *sc;
259
+ {
260
+ char buf[BUFSIZE];
261
+ char *p;
262
+ char *save;
263
+ VALUE result = rb_str_new("", 0);
264
+
265
+ sc->p++; /* discard first dquote */
266
+ p = buf;
267
+ while (sc->p < sc->pend) {
268
+ if (*sc->p == '"') {
269
+ sc->p++; /* discard terminal dquote */
270
+ rb_str_cat(result, buf, p - buf);
271
+ return result;
272
+ }
273
+ if (ISO2022_MODE_P(sc) && *sc->p == ESC) {
274
+ save = sc->p;
275
+ skip_iso2022jp_string(sc);
276
+ while (save < sc->p) {
277
+ *p++ = *save++;
278
+ if (p >= buf + BUFSIZE) {
279
+ /* flush buffer */
280
+ rb_str_cat(result, buf, BUFSIZE);
281
+ p = buf;
282
+ }
283
+ }
284
+ continue;
285
+ }
286
+
287
+ if (*sc->p == '\\')
288
+ sc->p++; /* discard quoting backslash */
289
+ *p++ = *sc->p++;
290
+ if (p >= buf + BUFSIZE) {
291
+ /* flush buffer */
292
+ rb_str_cat(result, buf, BUFSIZE);
293
+ p = buf;
294
+ }
295
+ }
296
+
297
+ rb_raise(ScanError, "unterminated quoted-word");
298
+ return Qnil;
299
+ }
300
+
301
+ static VALUE
302
+ scan_domain_literal(sc)
303
+ struct scanner *sc;
304
+ {
305
+ char buf[BUFSIZE];
306
+ char *p;
307
+ VALUE result = rb_str_new("", 0);
308
+
309
+ p = buf;
310
+ while (sc->p < sc->pend) {
311
+ if (*sc->p == ']') {
312
+ *p++ = *sc->p++;
313
+ rb_str_cat(result, buf, p - buf);
314
+ return result;
315
+ }
316
+
317
+ if (*sc->p == '\\')
318
+ sc->p++; /* discard backslash */
319
+ *p++ = *sc->p++;
320
+ if (p >= buf + BUFSIZE) {
321
+ /* flush buffer */
322
+ rb_str_cat(result, buf, BUFSIZE);
323
+ p = buf;
324
+ }
325
+ }
326
+
327
+ rb_raise(ScanError, "unterminated domain literal");
328
+ return Qnil;
329
+ }
330
+
331
+
332
+ static VALUE
333
+ scan_comment(sc)
334
+ struct scanner *sc;
335
+ {
336
+ int nest = 1;
337
+ char *p;
338
+ VALUE ret = rb_str_new("", 0);
339
+
340
+ sc->p++;
341
+ p = sc->p;
342
+ while (sc->p < sc->pend) {
343
+ if (ISO2022_MODE_P(sc) && *sc->p == ESC) {
344
+ skip_iso2022jp_string(sc);
345
+ }
346
+ else if (IS_JCHAR(*sc->p)) {
347
+ skip_japanese_string(sc);
348
+ }
349
+ else {
350
+ switch (*sc->p) {
351
+ case '(':
352
+ nest++;
353
+ break;
354
+ case ')':
355
+ nest--;
356
+ if (nest == 0) {
357
+ rb_str_cat(ret, p, sc->p - p);
358
+ sc->p++;
359
+ return ret;
360
+ }
361
+ break;
362
+ case '\\':
363
+ rb_str_cat(ret, p, sc->p - p);
364
+ sc->p++;
365
+ if (sc->p == sc->pend)
366
+ rb_raise(ScanError, "incomplete char quote");
367
+ p = sc->p;
368
+ break;
369
+ default:
370
+ break;
371
+ }
372
+ sc->p++;
373
+ }
374
+ }
375
+
376
+ rb_raise(ScanError, "unterminated comment");
377
+ return Qnil;
378
+ }
379
+
380
+
381
+ static void
382
+ skip_lwsp(sc)
383
+ struct scanner *sc;
384
+ {
385
+ while (sc->p < sc->pend) {
386
+ if (IS_LWSP(*sc->p)) sc->p++;
387
+ else break;
388
+ }
389
+ }
390
+
391
+ static int
392
+ nccmp(a, b)
393
+ char *a, *b;
394
+ {
395
+ while (*a && *b) {
396
+ if ((*a != *b) && (TO_LOWER(*a) != TO_LOWER(*b)))
397
+ return 0;
398
+ a++; b++;
399
+ }
400
+ return (*a == *b);
401
+ }
402
+
403
+ static int
404
+ digit_p(str)
405
+ VALUE str;
406
+ {
407
+ char *p;
408
+ int i;
409
+
410
+ p = RSTRING_PTR(str);
411
+ for (i = 0; i < RSTRING_LEN(str); i++) {
412
+ if (! IS_DIGIT(RSTRING_PTR(str)[i]))
413
+ return 0;
414
+ }
415
+ return 1;
416
+ }
417
+
418
+ static VALUE tok_atom, tok_digit, tok_token, tok_quoted, tok_domlit;
419
+ static VALUE tok_from, tok_by, tok_via, tok_with, tok_id, tok_for;
420
+
421
+ static VALUE
422
+ atomsym(sc, str)
423
+ struct scanner *sc;
424
+ VALUE str;
425
+ {
426
+ if (digit_p(str)) {
427
+ return tok_digit;
428
+ }
429
+ else if (RECV_MODE_P(sc)) {
430
+ char *p = RSTRING_PTR(str);
431
+ if (nccmp(p, "from")) return tok_from;
432
+ else if (nccmp(p, "by")) return tok_by;
433
+ else if (nccmp(p, "via")) return tok_via;
434
+ else if (nccmp(p, "with")) return tok_with;
435
+ else if (nccmp(p, "id")) return tok_id;
436
+ else if (nccmp(p, "for")) return tok_for;
437
+ }
438
+ return tok_atom;
439
+ }
440
+
441
+ static void
442
+ debug_print(sc, sym, val)
443
+ struct scanner *sc;
444
+ VALUE sym, val;
445
+ {
446
+ VALUE s;
447
+
448
+ s = rb_funcall(sym, rb_intern("inspect"), 0),
449
+ printf("%7ld %-10s token=<%s>\n",
450
+ (unsigned long)(sc->pend - sc->p),
451
+ RSTRING_PTR(s),
452
+ RSTRING_PTR(val));
453
+ }
454
+
455
+ #define D(expr) do {\
456
+ if (sc->flags & MODE_DEBUG) {expr;}\
457
+ } while (0)
458
+
459
+ static void
460
+ pass_token(sc, sym, tok, arr)
461
+ struct scanner *sc;
462
+ VALUE sym, tok, arr;
463
+ {
464
+ D(debug_print(sc, sym, tok));
465
+ rb_ary_store(arr, 0, sym);
466
+ rb_ary_store(arr, 1, tok);
467
+ rb_yield(arr);
468
+ }
469
+
470
+ /*
471
+ * Document-method: mails_scan
472
+ *
473
+ * TODO: Documentation needed
474
+ *
475
+ */
476
+ static VALUE
477
+ mails_scan(self)
478
+ VALUE self;
479
+ {
480
+ struct scanner *sc;
481
+ VALUE arr;
482
+
483
+ #define PASS(s,v) pass_token(sc,s,v,arr)
484
+ GET_SCANNER(self, sc);
485
+ if (!sc->p) {
486
+ rb_raise(ScanError, "Mails#scan called before reset");
487
+ }
488
+ arr = rb_assoc_new(Qnil, Qnil);
489
+
490
+ while (sc->p < sc->pend) {
491
+ D(puts("new loop"));
492
+ D(printf("char='%c'\n", *sc->p));
493
+ if (IS_LWSP(*sc->p)) {
494
+ D(puts("lwsp"));
495
+ skip_lwsp(sc);
496
+ if (sc->p >= sc->pend)
497
+ break;
498
+ }
499
+
500
+ if (MIME_MODE_P(sc)) {
501
+ if (IS_TOKENCHAR(*sc->p) ||
502
+ (ISO2022_MODE_P(sc) && (*sc->p == ESC)) ||
503
+ IS_JCHAR(*sc->p)) {
504
+ D(puts("token"));
505
+ PASS(tok_token, scan_token(sc));
506
+ continue;
507
+ }
508
+ }
509
+ else {
510
+ if (IS_ATOMCHAR(*sc->p) ||
511
+ (ISO2022_MODE_P(sc) && (*sc->p == ESC)) ||
512
+ IS_JCHAR(*sc->p)) {
513
+ VALUE tmp;
514
+ D(puts("atom"));
515
+ tmp = scan_atom(sc);
516
+ PASS(atomsym(sc, tmp), tmp);
517
+ continue;
518
+ }
519
+ }
520
+
521
+ if (*sc->p == '"') {
522
+ D(puts("quoted"));
523
+ PASS(tok_quoted, scan_quoted_word(sc));
524
+ D(puts("quoted"));
525
+ }
526
+ else if (*sc->p == '(') {
527
+ VALUE c;
528
+ D(puts("comment"));
529
+ c = scan_comment(sc);
530
+ if (! NIL_P(sc->comments))
531
+ rb_ary_push(sc->comments, c);
532
+ }
533
+ else if (*sc->p == '[') {
534
+ D(puts("domlit"));
535
+ PASS(tok_domlit, scan_domain_literal(sc));
536
+ }
537
+ else {
538
+ VALUE ch;
539
+ D(puts("char"));
540
+ ch = rb_str_new(sc->p, 1);
541
+ sc->p++;
542
+ PASS(ch, ch);
543
+ }
544
+ }
545
+
546
+ PASS(Qfalse, rb_str_new("$", 1));
547
+ return Qnil;
548
+ }
549
+
550
+
551
+ /*
552
+ ------------------------------------------------------------------
553
+ ruby interface
554
+ ------------------------------------------------------------------
555
+ */
556
+
557
+ static VALUE
558
+ cstr2symbol(str)
559
+ char *str;
560
+ {
561
+ ID tmp;
562
+
563
+ tmp = rb_intern(str);
564
+ #ifdef ID2SYM
565
+ return ID2SYM(tmp);
566
+ #else
567
+ return INT2FIX(tmp);
568
+ #endif
569
+ }
570
+
571
+ void
572
+ Init_tmailscanner()
573
+ {
574
+ VALUE TMail;
575
+ VALUE tmp;
576
+
577
+ if (rb_const_defined(rb_cObject, rb_intern("TMail"))) {
578
+ TMail = rb_const_get(rb_cObject, rb_intern("TMail"));
579
+ }
580
+ else {
581
+ TMail = rb_define_module("TMail");
582
+ }
583
+ TMailScanner = rb_define_class_under(TMail, "TMailScanner", rb_cObject);
584
+
585
+ tmp = rb_str_new2(TMAIL_VERSION);
586
+ rb_obj_freeze(tmp);
587
+ rb_define_const(TMailScanner, "Version", tmp);
588
+
589
+ rb_define_singleton_method(TMailScanner, "new", mails_s_new, 3);
590
+ rb_define_method(TMailScanner, "scan", mails_scan, 0);
591
+ rb_define_method(TMailScanner, "debug", mails_debug_get, 0);
592
+ rb_define_method(TMailScanner, "debug=", mails_debug_set, 1);
593
+
594
+ if (rb_const_defined(TMail, rb_intern("SyntaxError"))) {
595
+ ScanError = rb_const_get(rb_cObject, rb_intern("SyntaxError"));
596
+ }
597
+ else {
598
+ ScanError = rb_define_class_under(TMail, "SyntaxError", rb_eStandardError);
599
+ }
600
+
601
+ tok_atom = cstr2symbol("ATOM");
602
+ tok_digit = cstr2symbol("DIGIT");
603
+ tok_token = cstr2symbol("TOKEN");
604
+ tok_quoted = cstr2symbol("QUOTED");
605
+ tok_domlit = cstr2symbol("DOMLIT");
606
+
607
+ tok_from = cstr2symbol("FROM");
608
+ tok_by = cstr2symbol("BY");
609
+ tok_via = cstr2symbol("VIA");
610
+ tok_with = cstr2symbol("WITH");
611
+ tok_id = cstr2symbol("ID");
612
+ tok_for = cstr2symbol("FOR");
613
+ }
614
+