otherinbox-mail 2.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. data/CHANGELOG.rdoc +607 -0
  2. data/CONTRIBUTING.md +45 -0
  3. data/Dependencies.txt +3 -0
  4. data/Gemfile +26 -0
  5. data/Gemfile.lock +44 -0
  6. data/README.md +663 -0
  7. data/Rakefile +40 -0
  8. data/TODO.rdoc +9 -0
  9. data/lib/VERSION +4 -0
  10. data/lib/mail.rb +101 -0
  11. data/lib/mail/attachments_list.rb +104 -0
  12. data/lib/mail/body.rb +291 -0
  13. data/lib/mail/configuration.rb +75 -0
  14. data/lib/mail/core_extensions/nil.rb +17 -0
  15. data/lib/mail/core_extensions/object.rb +13 -0
  16. data/lib/mail/core_extensions/shell_escape.rb +56 -0
  17. data/lib/mail/core_extensions/smtp.rb +25 -0
  18. data/lib/mail/core_extensions/string.rb +33 -0
  19. data/lib/mail/core_extensions/string/access.rb +145 -0
  20. data/lib/mail/core_extensions/string/multibyte.rb +78 -0
  21. data/lib/mail/elements.rb +14 -0
  22. data/lib/mail/elements/address.rb +306 -0
  23. data/lib/mail/elements/address_list.rb +74 -0
  24. data/lib/mail/elements/content_disposition_element.rb +30 -0
  25. data/lib/mail/elements/content_location_element.rb +25 -0
  26. data/lib/mail/elements/content_transfer_encoding_element.rb +24 -0
  27. data/lib/mail/elements/content_type_element.rb +35 -0
  28. data/lib/mail/elements/date_time_element.rb +26 -0
  29. data/lib/mail/elements/envelope_from_element.rb +34 -0
  30. data/lib/mail/elements/message_ids_element.rb +29 -0
  31. data/lib/mail/elements/mime_version_element.rb +26 -0
  32. data/lib/mail/elements/phrase_list.rb +21 -0
  33. data/lib/mail/elements/received_element.rb +30 -0
  34. data/lib/mail/encodings.rb +274 -0
  35. data/lib/mail/encodings/7bit.rb +31 -0
  36. data/lib/mail/encodings/8bit.rb +31 -0
  37. data/lib/mail/encodings/base64.rb +33 -0
  38. data/lib/mail/encodings/binary.rb +31 -0
  39. data/lib/mail/encodings/quoted_printable.rb +38 -0
  40. data/lib/mail/encodings/transfer_encoding.rb +58 -0
  41. data/lib/mail/envelope.rb +35 -0
  42. data/lib/mail/field.rb +234 -0
  43. data/lib/mail/field_list.rb +33 -0
  44. data/lib/mail/fields.rb +35 -0
  45. data/lib/mail/fields/bcc_field.rb +56 -0
  46. data/lib/mail/fields/cc_field.rb +55 -0
  47. data/lib/mail/fields/comments_field.rb +41 -0
  48. data/lib/mail/fields/common/address_container.rb +16 -0
  49. data/lib/mail/fields/common/common_address.rb +125 -0
  50. data/lib/mail/fields/common/common_date.rb +42 -0
  51. data/lib/mail/fields/common/common_field.rb +51 -0
  52. data/lib/mail/fields/common/common_message_id.rb +44 -0
  53. data/lib/mail/fields/common/parameter_hash.rb +58 -0
  54. data/lib/mail/fields/content_description_field.rb +19 -0
  55. data/lib/mail/fields/content_disposition_field.rb +69 -0
  56. data/lib/mail/fields/content_id_field.rb +63 -0
  57. data/lib/mail/fields/content_location_field.rb +42 -0
  58. data/lib/mail/fields/content_transfer_encoding_field.rb +50 -0
  59. data/lib/mail/fields/content_type_field.rb +198 -0
  60. data/lib/mail/fields/date_field.rb +57 -0
  61. data/lib/mail/fields/from_field.rb +55 -0
  62. data/lib/mail/fields/in_reply_to_field.rb +55 -0
  63. data/lib/mail/fields/keywords_field.rb +44 -0
  64. data/lib/mail/fields/message_id_field.rb +83 -0
  65. data/lib/mail/fields/mime_version_field.rb +53 -0
  66. data/lib/mail/fields/optional_field.rb +13 -0
  67. data/lib/mail/fields/received_field.rb +75 -0
  68. data/lib/mail/fields/references_field.rb +55 -0
  69. data/lib/mail/fields/reply_to_field.rb +55 -0
  70. data/lib/mail/fields/resent_bcc_field.rb +55 -0
  71. data/lib/mail/fields/resent_cc_field.rb +55 -0
  72. data/lib/mail/fields/resent_date_field.rb +35 -0
  73. data/lib/mail/fields/resent_from_field.rb +55 -0
  74. data/lib/mail/fields/resent_message_id_field.rb +34 -0
  75. data/lib/mail/fields/resent_sender_field.rb +62 -0
  76. data/lib/mail/fields/resent_to_field.rb +55 -0
  77. data/lib/mail/fields/return_path_field.rb +65 -0
  78. data/lib/mail/fields/sender_field.rb +67 -0
  79. data/lib/mail/fields/structured_field.rb +51 -0
  80. data/lib/mail/fields/subject_field.rb +16 -0
  81. data/lib/mail/fields/to_field.rb +55 -0
  82. data/lib/mail/fields/unstructured_field.rb +191 -0
  83. data/lib/mail/header.rb +265 -0
  84. data/lib/mail/indifferent_hash.rb +146 -0
  85. data/lib/mail/mail.rb +255 -0
  86. data/lib/mail/matchers/has_sent_mail.rb +124 -0
  87. data/lib/mail/message.rb +2059 -0
  88. data/lib/mail/multibyte.rb +42 -0
  89. data/lib/mail/multibyte/chars.rb +474 -0
  90. data/lib/mail/multibyte/exceptions.rb +8 -0
  91. data/lib/mail/multibyte/unicode.rb +392 -0
  92. data/lib/mail/multibyte/utils.rb +60 -0
  93. data/lib/mail/network.rb +14 -0
  94. data/lib/mail/network/delivery_methods/exim.rb +53 -0
  95. data/lib/mail/network/delivery_methods/file_delivery.rb +40 -0
  96. data/lib/mail/network/delivery_methods/sendmail.rb +62 -0
  97. data/lib/mail/network/delivery_methods/smtp.rb +153 -0
  98. data/lib/mail/network/delivery_methods/smtp_connection.rb +74 -0
  99. data/lib/mail/network/delivery_methods/test_mailer.rb +40 -0
  100. data/lib/mail/network/retriever_methods/base.rb +63 -0
  101. data/lib/mail/network/retriever_methods/imap.rb +168 -0
  102. data/lib/mail/network/retriever_methods/pop3.rb +140 -0
  103. data/lib/mail/network/retriever_methods/test_retriever.rb +47 -0
  104. data/lib/mail/parsers/address_lists.rb +64 -0
  105. data/lib/mail/parsers/address_lists.treetop +19 -0
  106. data/lib/mail/parsers/content_disposition.rb +535 -0
  107. data/lib/mail/parsers/content_disposition.treetop +46 -0
  108. data/lib/mail/parsers/content_location.rb +139 -0
  109. data/lib/mail/parsers/content_location.treetop +20 -0
  110. data/lib/mail/parsers/content_transfer_encoding.rb +162 -0
  111. data/lib/mail/parsers/content_transfer_encoding.treetop +20 -0
  112. data/lib/mail/parsers/content_type.rb +967 -0
  113. data/lib/mail/parsers/content_type.treetop +68 -0
  114. data/lib/mail/parsers/date_time.rb +114 -0
  115. data/lib/mail/parsers/date_time.treetop +11 -0
  116. data/lib/mail/parsers/envelope_from.rb +194 -0
  117. data/lib/mail/parsers/envelope_from.treetop +32 -0
  118. data/lib/mail/parsers/message_ids.rb +45 -0
  119. data/lib/mail/parsers/message_ids.treetop +15 -0
  120. data/lib/mail/parsers/mime_version.rb +144 -0
  121. data/lib/mail/parsers/mime_version.treetop +19 -0
  122. data/lib/mail/parsers/phrase_lists.rb +45 -0
  123. data/lib/mail/parsers/phrase_lists.treetop +15 -0
  124. data/lib/mail/parsers/received.rb +71 -0
  125. data/lib/mail/parsers/received.treetop +11 -0
  126. data/lib/mail/parsers/rfc2045.rb +464 -0
  127. data/lib/mail/parsers/rfc2045.treetop +36 -0
  128. data/lib/mail/parsers/rfc2822.rb +5341 -0
  129. data/lib/mail/parsers/rfc2822.treetop +410 -0
  130. data/lib/mail/parsers/rfc2822_obsolete.rb +3768 -0
  131. data/lib/mail/parsers/rfc2822_obsolete.treetop +241 -0
  132. data/lib/mail/part.rb +116 -0
  133. data/lib/mail/parts_list.rb +55 -0
  134. data/lib/mail/patterns.rb +34 -0
  135. data/lib/mail/utilities.rb +215 -0
  136. data/lib/mail/version.rb +24 -0
  137. data/lib/mail/version_specific/ruby_1_8.rb +98 -0
  138. data/lib/mail/version_specific/ruby_1_9.rb +113 -0
  139. data/lib/tasks/corpus.rake +125 -0
  140. data/lib/tasks/treetop.rake +10 -0
  141. metadata +253 -0
@@ -0,0 +1,168 @@
1
+ # encoding: utf-8
2
+
3
+ module Mail
4
+ # The IMAP retriever allows to get the last, first or all emails from a IMAP server.
5
+ # Each email retrieved (RFC2822) is given as an instance of +Message+.
6
+ #
7
+ # While being retrieved, emails can be yielded if a block is given.
8
+ #
9
+ # === Example of retrieving Emails from GMail:
10
+ #
11
+ # Mail.defaults do
12
+ # retriever_method :imap, { :address => "imap.googlemail.com",
13
+ # :port => 993,
14
+ # :user_name => '<username>',
15
+ # :password => '<password>',
16
+ # :enable_ssl => true }
17
+ # end
18
+ #
19
+ # Mail.all #=> Returns an array of all emails
20
+ # Mail.first #=> Returns the first unread email
21
+ # Mail.last #=> Returns the first unread email
22
+ #
23
+ # You can also pass options into Mail.find to locate an email in your imap mailbox
24
+ # with the following options:
25
+ #
26
+ # mailbox: name of the mailbox used for email retrieval. The default is 'INBOX'.
27
+ # what: last or first emails. The default is :first.
28
+ # order: order of emails returned. Possible values are :asc or :desc. Default value is :asc.
29
+ # count: number of emails to retrieve. The default value is 10. A value of 1 returns an
30
+ # instance of Message, not an array of Message instances.
31
+ # keys: are passed as criteria to the SEARCH command. They can either be a string holding the entire search string,
32
+ # or a single-dimension array of search keywords and arguments. Refer to [IMAP] section 6.4.4 for a full list
33
+ # The default is 'ALL'
34
+ #
35
+ # Mail.find(:what => :first, :count => 10, :order => :asc, :keys=>'ALL')
36
+ # #=> Returns the first 10 emails in ascending order
37
+ #
38
+ class IMAP < Retriever
39
+ require 'net/imap'
40
+
41
+ def initialize(values)
42
+ self.settings = { :address => "localhost",
43
+ :port => 143,
44
+ :user_name => nil,
45
+ :password => nil,
46
+ :authentication => nil,
47
+ :enable_ssl => false }.merge!(values)
48
+ end
49
+
50
+ attr_accessor :settings
51
+
52
+ # Find emails in a IMAP mailbox. Without any options, the 10 last received emails are returned.
53
+ #
54
+ # Possible options:
55
+ # mailbox: mailbox to search the email(s) in. The default is 'INBOX'.
56
+ # what: last or first emails. The default is :first.
57
+ # order: order of emails returned. Possible values are :asc or :desc. Default value is :asc.
58
+ # count: number of emails to retrieve. The default value is 10. A value of 1 returns an
59
+ # instance of Message, not an array of Message instances.
60
+ # read_only: will ensure that no writes are made to the inbox during the session. Specifically, if this is
61
+ # set to true, the code will use the EXAMINE command to retrieve the mail. If set to false, which
62
+ # is the default, a SELECT command will be used to retrieve the mail
63
+ # This is helpful when you don't want your messages to be set to read automatically. Default is false.
64
+ # delete_after_find: flag for whether to delete each retreived email after find. Default
65
+ # is false. Use #find_and_delete if you would like this to default to true.
66
+ # keys: are passed as criteria to the SEARCH command. They can either be a string holding the entire search string,
67
+ # or a single-dimension array of search keywords and arguments. Refer to [IMAP] section 6.4.4 for a full list
68
+ # The default is 'ALL'
69
+ #
70
+ def find(options={}, &block)
71
+ options = validate_options(options)
72
+
73
+ start do |imap|
74
+ options[:read_only] ? imap.examine(options[:mailbox]) : imap.select(options[:mailbox])
75
+
76
+ message_ids = imap.uid_search(options[:keys])
77
+ message_ids.reverse! if options[:what].to_sym == :last
78
+ message_ids = message_ids.first(options[:count]) if options[:count].is_a?(Integer)
79
+ message_ids.reverse! if (options[:what].to_sym == :last && options[:order].to_sym == :asc) ||
80
+ (options[:what].to_sym != :last && options[:order].to_sym == :desc)
81
+
82
+ if block_given?
83
+ message_ids.each do |message_id|
84
+ fetchdata = imap.uid_fetch(message_id, ['RFC822'])[0]
85
+ new_message = Mail.new(fetchdata.attr['RFC822'])
86
+ new_message.mark_for_delete = true if options[:delete_after_find]
87
+ if block.arity == 3
88
+ yield new_message, imap, message_id
89
+ else
90
+ yield new_message
91
+ end
92
+ imap.uid_store(message_id, "+FLAGS", [Net::IMAP::DELETED]) if options[:delete_after_find] && new_message.is_marked_for_delete?
93
+ end
94
+ imap.expunge if options[:delete_after_find]
95
+ else
96
+ emails = []
97
+ message_ids.each do |message_id|
98
+ fetchdata = imap.uid_fetch(message_id, ['RFC822'])[0]
99
+ emails << Mail.new(fetchdata.attr['RFC822'])
100
+ imap.uid_store(message_id, "+FLAGS", [Net::IMAP::DELETED]) if options[:delete_after_find]
101
+ end
102
+ imap.expunge if options[:delete_after_find]
103
+ emails.size == 1 && options[:count] == 1 ? emails.first : emails
104
+ end
105
+ end
106
+ end
107
+
108
+ # Delete all emails from a IMAP mailbox
109
+ def delete_all(mailbox='INBOX')
110
+ mailbox ||= 'INBOX'
111
+ mailbox = Net::IMAP.encode_utf7(mailbox)
112
+
113
+ start do |imap|
114
+ imap.uid_search(['ALL']).each do |message_id|
115
+ imap.uid_store(message_id, "+FLAGS", [Net::IMAP::DELETED])
116
+ end
117
+ imap.expunge
118
+ end
119
+ end
120
+
121
+ # Returns the connection object of the retrievable (IMAP or POP3)
122
+ def connection(&block)
123
+ raise ArgumentError.new('Mail::Retrievable#connection takes a block') unless block_given?
124
+
125
+ start do |imap|
126
+ yield imap
127
+ end
128
+ end
129
+
130
+ private
131
+
132
+ # Set default options
133
+ def validate_options(options)
134
+ options ||= {}
135
+ options[:mailbox] ||= 'INBOX'
136
+ options[:count] ||= 10
137
+ options[:order] ||= :asc
138
+ options[:what] ||= :first
139
+ options[:keys] ||= 'ALL'
140
+ options[:delete_after_find] ||= false
141
+ options[:mailbox] = Net::IMAP.encode_utf7(options[:mailbox])
142
+ options[:read_only] ||= false
143
+
144
+ options
145
+ end
146
+
147
+ # Start an IMAP session and ensures that it will be closed in any case.
148
+ def start(config=Mail::Configuration.instance, &block)
149
+ raise ArgumentError.new("Mail::Retrievable#imap_start takes a block") unless block_given?
150
+
151
+ imap = Net::IMAP.new(settings[:address], settings[:port], settings[:enable_ssl], nil, false)
152
+ if settings[:authentication].nil?
153
+ imap.login(settings[:user_name], settings[:password])
154
+ else
155
+ # Note that Net::IMAP#authenticate('LOGIN', ...) is not equal with Net::IMAP#login(...)!
156
+ # (see also http://www.ensta.fr/~diam/ruby/online/ruby-doc-stdlib/libdoc/net/imap/rdoc/classes/Net/IMAP.html#M000718)
157
+ imap.authenticate(settings[:authentication], settings[:user_name], settings[:password])
158
+ end
159
+
160
+ yield imap
161
+ ensure
162
+ if defined?(imap) && imap && !imap.disconnected?
163
+ imap.disconnect
164
+ end
165
+ end
166
+
167
+ end
168
+ end
@@ -0,0 +1,140 @@
1
+ # encoding: utf-8
2
+
3
+ module Mail
4
+ # The Pop3 retriever allows to get the last, first or all emails from a POP3 server.
5
+ # Each email retrieved (RFC2822) is given as an instance of +Message+.
6
+ #
7
+ # While being retrieved, emails can be yielded if a block is given.
8
+ #
9
+ # === Example of retrieving Emails from GMail:
10
+ #
11
+ # Mail.defaults do
12
+ # retriever_method :pop3, { :address => "pop.gmail.com",
13
+ # :port => 995,
14
+ # :user_name => '<username>',
15
+ # :password => '<password>',
16
+ # :enable_ssl => true }
17
+ # end
18
+ #
19
+ # Mail.all #=> Returns an array of all emails
20
+ # Mail.first #=> Returns the first unread email
21
+ # Mail.last #=> Returns the first unread email
22
+ #
23
+ # You can also pass options into Mail.find to locate an email in your pop mailbox
24
+ # with the following options:
25
+ #
26
+ # what: last or first emails. The default is :first.
27
+ # order: order of emails returned. Possible values are :asc or :desc. Default value is :asc.
28
+ # count: number of emails to retrieve. The default value is 10. A value of 1 returns an
29
+ # instance of Message, not an array of Message instances.
30
+ #
31
+ # Mail.find(:what => :first, :count => 10, :order => :asc)
32
+ # #=> Returns the first 10 emails in ascending order
33
+ #
34
+ class POP3 < Retriever
35
+ require 'net/pop'
36
+
37
+ def initialize(values)
38
+ self.settings = { :address => "localhost",
39
+ :port => 110,
40
+ :user_name => nil,
41
+ :password => nil,
42
+ :authentication => nil,
43
+ :enable_ssl => false }.merge!(values)
44
+ end
45
+
46
+ attr_accessor :settings
47
+
48
+ # Find emails in a POP3 mailbox. Without any options, the 5 last received emails are returned.
49
+ #
50
+ # Possible options:
51
+ # what: last or first emails. The default is :first.
52
+ # order: order of emails returned. Possible values are :asc or :desc. Default value is :asc.
53
+ # count: number of emails to retrieve. The default value is 10. A value of 1 returns an
54
+ # instance of Message, not an array of Message instances.
55
+ # delete_after_find: flag for whether to delete each retreived email after find. Default
56
+ # is false. Use #find_and_delete if you would like this to default to true.
57
+ #
58
+ def find(options = {}, &block)
59
+ options = validate_options(options)
60
+
61
+ start do |pop3|
62
+ mails = pop3.mails
63
+ pop3.reset # Clears all "deleted" marks. This prevents non-explicit/accidental deletions due to server settings.
64
+ mails.sort! { |m1, m2| m2.number <=> m1.number } if options[:what] == :last
65
+ mails = mails.first(options[:count]) if options[:count].is_a? Integer
66
+
67
+ if options[:what].to_sym == :last && options[:order].to_sym == :desc ||
68
+ options[:what].to_sym == :first && options[:order].to_sym == :asc ||
69
+ mails.reverse!
70
+ end
71
+
72
+ if block_given?
73
+ mails.each do |mail|
74
+ new_message = Mail.new(mail.pop)
75
+ new_message.mark_for_delete = true if options[:delete_after_find]
76
+ yield new_message
77
+ mail.delete if options[:delete_after_find] && new_message.is_marked_for_delete? # Delete if still marked for delete
78
+ end
79
+ else
80
+ emails = []
81
+ mails.each do |mail|
82
+ emails << Mail.new(mail.pop)
83
+ mail.delete if options[:delete_after_find]
84
+ end
85
+ emails.size == 1 && options[:count] == 1 ? emails.first : emails
86
+ end
87
+
88
+ end
89
+ end
90
+
91
+ # Delete all emails from a POP3 server
92
+ def delete_all
93
+ start do |pop3|
94
+ unless pop3.mails.empty?
95
+ pop3.delete_all
96
+ pop3.finish
97
+ end
98
+ end
99
+ end
100
+
101
+ # Returns the connection object of the retrievable (IMAP or POP3)
102
+ def connection(&block)
103
+ raise ArgumentError.new('Mail::Retrievable#connection takes a block') unless block_given?
104
+
105
+ start do |pop3|
106
+ yield pop3
107
+ end
108
+ end
109
+
110
+ private
111
+
112
+ # Set default options
113
+ def validate_options(options)
114
+ options ||= {}
115
+ options[:count] ||= 10
116
+ options[:order] ||= :asc
117
+ options[:what] ||= :first
118
+ options[:delete_after_find] ||= false
119
+ options
120
+ end
121
+
122
+ # Start a POP3 session and ensure that it will be closed in any case. Any messages
123
+ # marked for deletion via #find_and_delete or with the :delete_after_find option
124
+ # will be deleted when the session is closed.
125
+ def start(config = Configuration.instance, &block)
126
+ raise ArgumentError.new("Mail::Retrievable#pop3_start takes a block") unless block_given?
127
+
128
+ pop3 = Net::POP3.new(settings[:address], settings[:port], false)
129
+ pop3.enable_ssl(OpenSSL::SSL::VERIFY_NONE) if settings[:enable_ssl]
130
+ pop3.start(settings[:user_name], settings[:password])
131
+
132
+ yield pop3
133
+ ensure
134
+ if defined?(pop3) && pop3 && pop3.started?
135
+ pop3.finish
136
+ end
137
+ end
138
+
139
+ end
140
+ end
@@ -0,0 +1,47 @@
1
+ # encoding: utf-8
2
+
3
+ module Mail
4
+
5
+ class TestRetriever < Retriever
6
+
7
+ def self.emails
8
+ @@emails
9
+ end
10
+
11
+ def self.emails=(val)
12
+ @@emails = val
13
+ end
14
+
15
+ def initialize(values)
16
+ @@emails = []
17
+ end
18
+
19
+ def find(options = {}, &block)
20
+ options[:count] ||= :all
21
+ options[:order] ||= :asc
22
+ options[:what] ||= :first
23
+ emails = @@emails.dup
24
+ emails.reverse! if options[:what] == :last
25
+ emails = case count = options[:count]
26
+ when :all then emails
27
+ when 1 then emails.first
28
+ when Fixnum then emails[0, count]
29
+ else
30
+ raise 'Invalid count option value: ' + count.inspect
31
+ end
32
+ if options[:what] == :last && options[:order] == :asc || options[:what] == :first && options[:order] == :desc
33
+ emails.reverse!
34
+ end
35
+ emails.each { |email| email.mark_for_delete = true } if options[:delete_after_find]
36
+ if block_given?
37
+ emails.each { |email| yield email }
38
+ else
39
+ emails
40
+ end.tap do |results|
41
+ emails.each { |email| @@emails.delete(email) if email.is_marked_for_delete? } if options[:delete_after_find]
42
+ end
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -0,0 +1,64 @@
1
+ # Autogenerated from a Treetop grammar. Edits may be lost.
2
+
3
+
4
+ module Mail
5
+ module AddressLists
6
+ include Treetop::Runtime
7
+
8
+ def root
9
+ @root ||= :primary_address
10
+ end
11
+
12
+ include RFC2822
13
+
14
+ module PrimaryAddress0
15
+ def addresses
16
+ ([first_addr] + other_addr.elements.map { |o| o.addr_value }).reject { |e| e.empty? }
17
+ end
18
+ end
19
+
20
+ module PrimaryAddress1
21
+ def addresses
22
+ [first_addr] + other_addr.elements.map { |o| o.addr_value }
23
+ end
24
+ end
25
+
26
+ def _nt_primary_address
27
+ start_index = index
28
+ if node_cache[:primary_address].has_key?(index)
29
+ cached = node_cache[:primary_address][index]
30
+ if cached
31
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
32
+ @index = cached.interval.end
33
+ end
34
+ return cached
35
+ end
36
+
37
+ i0 = index
38
+ r1 = _nt_address_list
39
+ r1.extend(PrimaryAddress0)
40
+ if r1
41
+ r0 = r1
42
+ else
43
+ r2 = _nt_obs_addr_list
44
+ r2.extend(PrimaryAddress1)
45
+ if r2
46
+ r0 = r2
47
+ else
48
+ @index = i0
49
+ r0 = nil
50
+ end
51
+ end
52
+
53
+ node_cache[:primary_address][start_index] = r0
54
+
55
+ r0
56
+ end
57
+
58
+ end
59
+
60
+ class AddressListsParser < Treetop::Runtime::CompiledParser
61
+ include AddressLists
62
+ end
63
+
64
+ end
@@ -0,0 +1,19 @@
1
+ module Mail
2
+ grammar AddressLists
3
+
4
+ include RFC2822
5
+
6
+ rule primary_address
7
+ address_list {
8
+ def addresses
9
+ ([first_addr] + other_addr.elements.map { |o| o.addr_value }).reject { |e| e.empty? }
10
+ end
11
+ } / obs_addr_list {
12
+ def addresses
13
+ [first_addr] + other_addr.elements.map { |o| o.addr_value }
14
+ end
15
+ }
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,535 @@
1
+ # Autogenerated from a Treetop grammar. Edits may be lost.
2
+
3
+
4
+ module Mail
5
+ module ContentDisposition
6
+ include Treetop::Runtime
7
+
8
+ def root
9
+ @root ||= :content_disposition
10
+ end
11
+
12
+ include RFC2822
13
+
14
+ include RFC2045
15
+
16
+ module ContentDisposition0
17
+ def CFWS1
18
+ elements[0]
19
+ end
20
+
21
+ def parameter
22
+ elements[2]
23
+ end
24
+
25
+ def CFWS2
26
+ elements[3]
27
+ end
28
+ end
29
+
30
+ module ContentDisposition1
31
+ def disposition_type
32
+ elements[0]
33
+ end
34
+
35
+ def param_hashes
36
+ elements[1]
37
+ end
38
+ end
39
+
40
+ module ContentDisposition2
41
+ def parameters
42
+ param_hashes.elements.map do |param|
43
+ param.parameter.param_hash
44
+ end
45
+ end
46
+ end
47
+
48
+ def _nt_content_disposition
49
+ start_index = index
50
+ if node_cache[:content_disposition].has_key?(index)
51
+ cached = node_cache[:content_disposition][index]
52
+ if cached
53
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
54
+ @index = cached.interval.end
55
+ end
56
+ return cached
57
+ end
58
+
59
+ i0, s0 = index, []
60
+ r1 = _nt_disposition_type
61
+ s0 << r1
62
+ if r1
63
+ s2, i2 = [], index
64
+ loop do
65
+ i3, s3 = index, []
66
+ r4 = _nt_CFWS
67
+ s3 << r4
68
+ if r4
69
+ if has_terminal?(";", false, index)
70
+ r5 = instantiate_node(SyntaxNode,input, index...(index + 1))
71
+ @index += 1
72
+ else
73
+ terminal_parse_failure(";")
74
+ r5 = nil
75
+ end
76
+ s3 << r5
77
+ if r5
78
+ r6 = _nt_parameter
79
+ s3 << r6
80
+ if r6
81
+ r7 = _nt_CFWS
82
+ s3 << r7
83
+ end
84
+ end
85
+ end
86
+ if s3.last
87
+ r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
88
+ r3.extend(ContentDisposition0)
89
+ else
90
+ @index = i3
91
+ r3 = nil
92
+ end
93
+ if r3
94
+ s2 << r3
95
+ else
96
+ break
97
+ end
98
+ end
99
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
100
+ s0 << r2
101
+ end
102
+ if s0.last
103
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
104
+ r0.extend(ContentDisposition1)
105
+ r0.extend(ContentDisposition2)
106
+ else
107
+ @index = i0
108
+ r0 = nil
109
+ end
110
+
111
+ node_cache[:content_disposition][start_index] = r0
112
+
113
+ r0
114
+ end
115
+
116
+ module DispositionType0
117
+ end
118
+
119
+ module DispositionType1
120
+ end
121
+
122
+ def _nt_disposition_type
123
+ start_index = index
124
+ if node_cache[:disposition_type].has_key?(index)
125
+ cached = node_cache[:disposition_type][index]
126
+ if cached
127
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
128
+ @index = cached.interval.end
129
+ end
130
+ return cached
131
+ end
132
+
133
+ i0 = index
134
+ i1, s1 = index, []
135
+ if has_terminal?('\G[iI]', true, index)
136
+ r2 = true
137
+ @index += 1
138
+ else
139
+ r2 = nil
140
+ end
141
+ s1 << r2
142
+ if r2
143
+ if has_terminal?('\G[nN]', true, index)
144
+ r3 = true
145
+ @index += 1
146
+ else
147
+ r3 = nil
148
+ end
149
+ s1 << r3
150
+ if r3
151
+ if has_terminal?('\G[lL]', true, index)
152
+ r4 = true
153
+ @index += 1
154
+ else
155
+ r4 = nil
156
+ end
157
+ s1 << r4
158
+ if r4
159
+ if has_terminal?('\G[iI]', true, index)
160
+ r5 = true
161
+ @index += 1
162
+ else
163
+ r5 = nil
164
+ end
165
+ s1 << r5
166
+ if r5
167
+ if has_terminal?('\G[nN]', true, index)
168
+ r6 = true
169
+ @index += 1
170
+ else
171
+ r6 = nil
172
+ end
173
+ s1 << r6
174
+ if r6
175
+ if has_terminal?('\G[eE]', true, index)
176
+ r7 = true
177
+ @index += 1
178
+ else
179
+ r7 = nil
180
+ end
181
+ s1 << r7
182
+ end
183
+ end
184
+ end
185
+ end
186
+ end
187
+ if s1.last
188
+ r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
189
+ r1.extend(DispositionType0)
190
+ else
191
+ @index = i1
192
+ r1 = nil
193
+ end
194
+ if r1
195
+ r0 = r1
196
+ else
197
+ i8, s8 = index, []
198
+ if has_terminal?('\G[aA]', true, index)
199
+ r9 = true
200
+ @index += 1
201
+ else
202
+ r9 = nil
203
+ end
204
+ s8 << r9
205
+ if r9
206
+ if has_terminal?('\G[tT]', true, index)
207
+ r10 = true
208
+ @index += 1
209
+ else
210
+ r10 = nil
211
+ end
212
+ s8 << r10
213
+ if r10
214
+ if has_terminal?('\G[tT]', true, index)
215
+ r11 = true
216
+ @index += 1
217
+ else
218
+ r11 = nil
219
+ end
220
+ s8 << r11
221
+ if r11
222
+ if has_terminal?('\G[aA]', true, index)
223
+ r12 = true
224
+ @index += 1
225
+ else
226
+ r12 = nil
227
+ end
228
+ s8 << r12
229
+ if r12
230
+ if has_terminal?('\G[cC]', true, index)
231
+ r13 = true
232
+ @index += 1
233
+ else
234
+ r13 = nil
235
+ end
236
+ s8 << r13
237
+ if r13
238
+ if has_terminal?('\G[hH]', true, index)
239
+ r14 = true
240
+ @index += 1
241
+ else
242
+ r14 = nil
243
+ end
244
+ s8 << r14
245
+ if r14
246
+ if has_terminal?('\G[mM]', true, index)
247
+ r15 = true
248
+ @index += 1
249
+ else
250
+ r15 = nil
251
+ end
252
+ s8 << r15
253
+ if r15
254
+ if has_terminal?('\G[eE]', true, index)
255
+ r16 = true
256
+ @index += 1
257
+ else
258
+ r16 = nil
259
+ end
260
+ s8 << r16
261
+ if r16
262
+ if has_terminal?('\G[nN]', true, index)
263
+ r17 = true
264
+ @index += 1
265
+ else
266
+ r17 = nil
267
+ end
268
+ s8 << r17
269
+ if r17
270
+ if has_terminal?('\G[tT]', true, index)
271
+ r18 = true
272
+ @index += 1
273
+ else
274
+ r18 = nil
275
+ end
276
+ s8 << r18
277
+ end
278
+ end
279
+ end
280
+ end
281
+ end
282
+ end
283
+ end
284
+ end
285
+ end
286
+ if s8.last
287
+ r8 = instantiate_node(SyntaxNode,input, i8...index, s8)
288
+ r8.extend(DispositionType1)
289
+ else
290
+ @index = i8
291
+ r8 = nil
292
+ end
293
+ if r8
294
+ r0 = r8
295
+ else
296
+ r19 = _nt_extension_token
297
+ if r19
298
+ r0 = r19
299
+ else
300
+ if has_terminal?('', false, index)
301
+ r20 = instantiate_node(SyntaxNode,input, index...(index + 0))
302
+ @index += 0
303
+ else
304
+ terminal_parse_failure('')
305
+ r20 = nil
306
+ end
307
+ if r20
308
+ r0 = r20
309
+ else
310
+ @index = i0
311
+ r0 = nil
312
+ end
313
+ end
314
+ end
315
+ end
316
+
317
+ node_cache[:disposition_type][start_index] = r0
318
+
319
+ r0
320
+ end
321
+
322
+ def _nt_extension_token
323
+ start_index = index
324
+ if node_cache[:extension_token].has_key?(index)
325
+ cached = node_cache[:extension_token][index]
326
+ if cached
327
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
328
+ @index = cached.interval.end
329
+ end
330
+ return cached
331
+ end
332
+
333
+ i0 = index
334
+ r1 = _nt_ietf_token
335
+ if r1
336
+ r0 = r1
337
+ else
338
+ r2 = _nt_custom_x_token
339
+ if r2
340
+ r0 = r2
341
+ else
342
+ @index = i0
343
+ r0 = nil
344
+ end
345
+ end
346
+
347
+ node_cache[:extension_token][start_index] = r0
348
+
349
+ r0
350
+ end
351
+
352
+ module Parameter0
353
+ def attr
354
+ elements[1]
355
+ end
356
+
357
+ def val
358
+ elements[3]
359
+ end
360
+
361
+ end
362
+
363
+ module Parameter1
364
+ def param_hash
365
+ {attr.text_value => val.text_value}
366
+ end
367
+ end
368
+
369
+ def _nt_parameter
370
+ start_index = index
371
+ if node_cache[:parameter].has_key?(index)
372
+ cached = node_cache[:parameter][index]
373
+ if cached
374
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
375
+ @index = cached.interval.end
376
+ end
377
+ return cached
378
+ end
379
+
380
+ i0, s0 = index, []
381
+ r2 = _nt_CFWS
382
+ if r2
383
+ r1 = r2
384
+ else
385
+ r1 = instantiate_node(SyntaxNode,input, index...index)
386
+ end
387
+ s0 << r1
388
+ if r1
389
+ r3 = _nt_attribute
390
+ s0 << r3
391
+ if r3
392
+ if has_terminal?("=", false, index)
393
+ r4 = instantiate_node(SyntaxNode,input, index...(index + 1))
394
+ @index += 1
395
+ else
396
+ terminal_parse_failure("=")
397
+ r4 = nil
398
+ end
399
+ s0 << r4
400
+ if r4
401
+ r5 = _nt_value
402
+ s0 << r5
403
+ if r5
404
+ r7 = _nt_CFWS
405
+ if r7
406
+ r6 = r7
407
+ else
408
+ r6 = instantiate_node(SyntaxNode,input, index...index)
409
+ end
410
+ s0 << r6
411
+ end
412
+ end
413
+ end
414
+ end
415
+ if s0.last
416
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
417
+ r0.extend(Parameter0)
418
+ r0.extend(Parameter1)
419
+ else
420
+ @index = i0
421
+ r0 = nil
422
+ end
423
+
424
+ node_cache[:parameter][start_index] = r0
425
+
426
+ r0
427
+ end
428
+
429
+ def _nt_attribute
430
+ start_index = index
431
+ if node_cache[:attribute].has_key?(index)
432
+ cached = node_cache[:attribute][index]
433
+ if cached
434
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
435
+ @index = cached.interval.end
436
+ end
437
+ return cached
438
+ end
439
+
440
+ s0, i0 = [], index
441
+ loop do
442
+ r1 = _nt_token
443
+ if r1
444
+ s0 << r1
445
+ else
446
+ break
447
+ end
448
+ end
449
+ if s0.empty?
450
+ @index = i0
451
+ r0 = nil
452
+ else
453
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
454
+ end
455
+
456
+ node_cache[:attribute][start_index] = r0
457
+
458
+ r0
459
+ end
460
+
461
+ module Value0
462
+ def text_value
463
+ quoted_content.text_value
464
+ end
465
+ end
466
+
467
+ def _nt_value
468
+ start_index = index
469
+ if node_cache[:value].has_key?(index)
470
+ cached = node_cache[:value][index]
471
+ if cached
472
+ cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
473
+ @index = cached.interval.end
474
+ end
475
+ return cached
476
+ end
477
+
478
+ i0 = index
479
+ r1 = _nt_quoted_string
480
+ r1.extend(Value0)
481
+ if r1
482
+ r0 = r1
483
+ else
484
+ s2, i2 = [], index
485
+ loop do
486
+ i3 = index
487
+ r4 = _nt_token
488
+ if r4
489
+ r3 = r4
490
+ else
491
+ if has_terminal?('\G[\\x3d]', true, index)
492
+ r5 = true
493
+ @index += 1
494
+ else
495
+ r5 = nil
496
+ end
497
+ if r5
498
+ r3 = r5
499
+ else
500
+ @index = i3
501
+ r3 = nil
502
+ end
503
+ end
504
+ if r3
505
+ s2 << r3
506
+ else
507
+ break
508
+ end
509
+ end
510
+ if s2.empty?
511
+ @index = i2
512
+ r2 = nil
513
+ else
514
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
515
+ end
516
+ if r2
517
+ r0 = r2
518
+ else
519
+ @index = i0
520
+ r0 = nil
521
+ end
522
+ end
523
+
524
+ node_cache[:value][start_index] = r0
525
+
526
+ r0
527
+ end
528
+
529
+ end
530
+
531
+ class ContentDispositionParser < Treetop::Runtime::CompiledParser
532
+ include ContentDisposition
533
+ end
534
+
535
+ end