circular-mail 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ Y2VhZjJjMGRiOWIxODNhM2ZkNzVmZWI5NzdhYTYyMmM4NmUwN2EwZg==
5
+ data.tar.gz: !binary |-
6
+ NjY1ZmNhYzMwYmQ3MDNlNzZhNDQ3OTA1YzVmNmI4NzM2ZGE1MTFjYg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ OTRjZDMzYWQ2M2MwZjJkNjgzOGM3ZTk2NzIyMDIxY2ZiMDJhNDE3ZmE4Y2Qz
10
+ MWMyYWZlMmEwZmNmZGVkZTI0NzZjNGExNDE2ZTNmYzQ0YzRhNzQyMzgwZmZi
11
+ ZjBiYWEzYjYwNTU4MmMwYWVmZTUwMGE1YmJkNWQ0ZDJhMWIwODU=
12
+ data.tar.gz: !binary |-
13
+ ZjIxMTRjNmU1M2NkOGQ0YzRlY2EwZjZkMWRmZThjOGNkNzgxMTcyM2E3ODI0
14
+ NGVlZjI0ZTIxYjE5MTExMGViMzJmMjgyMTViZWIzZjgzNDBlMjQ3ODUxNDdi
15
+ MWE2ZGE3YjQ1YWQzMTViN2QzMTk1ZmFjMDljN2M5Mzk1NWI1Yzk=
@@ -0,0 +1,278 @@
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your
12
+ freedom to share and change it. By contrast, the GNU General Public
13
+ License is intended to guarantee your freedom to share and change free
14
+ software--to make sure the software is free for all its users. This
15
+ General Public License applies to most of the Free Software
16
+ Foundation's software and to any other program whose authors commit to
17
+ using it. (Some other Free Software Foundation software is covered by
18
+ the GNU Lesser General Public License instead.) You can apply it to
19
+ your programs, too.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ this service if you wish), that you receive source code or can get it
25
+ if you want it, that you can change the software or use pieces of it
26
+ in new free programs; and that you know you can do these things.
27
+
28
+ To protect your rights, we need to make restrictions that forbid
29
+ anyone to deny you these rights or to ask you to surrender the rights.
30
+ These restrictions translate to certain responsibilities for you if you
31
+ distribute copies of the software, or if you modify it.
32
+
33
+ For example, if you distribute copies of such a program, whether
34
+ gratis or for a fee, you must give the recipients all the rights that
35
+ you have. You must make sure that they, too, receive or can get the
36
+ source code. And you must show them these terms so they know their
37
+ rights.
38
+
39
+ We protect your rights with two steps: (1) copyright the software, and
40
+ (2) offer you this license which gives you legal permission to copy,
41
+ distribute and/or modify the software.
42
+
43
+ Also, for each author's protection and ours, we want to make certain
44
+ that everyone understands that there is no warranty for this free
45
+ software. If the software is modified by someone else and passed on, we
46
+ want its recipients to know that what they have is not the original, so
47
+ that any problems introduced by others will not reflect on the original
48
+ authors' reputations.
49
+
50
+ Finally, any free program is threatened constantly by software
51
+ patents. We wish to avoid the danger that redistributors of a free
52
+ program will individually obtain patent licenses, in effect making the
53
+ program proprietary. To prevent this, we have made it clear that any
54
+ patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+ 0. This License applies to any program or other work which contains
63
+ a notice placed by the copyright holder saying it may be distributed
64
+ under the terms of this General Public License. The "Program", below,
65
+ refers to any such program or work, and a "work based on the Program"
66
+ means either the Program or any derivative work under copyright law:
67
+ that is to say, a work containing the Program or a portion of it,
68
+ either verbatim or with modifications and/or translated into another
69
+ language. (Hereinafter, translation is included without limitation in
70
+ the term "modification".) Each licensee is addressed as "you".
71
+
72
+ Activities other than copying, distribution and modification are not
73
+ covered by this License; they are outside its scope. The act of
74
+ running the Program is not restricted, and the output from the Program
75
+ is covered only if its contents constitute a work based on the
76
+ Program (independent of having been made by running the Program).
77
+ Whether that is true depends on what the Program does.
78
+
79
+ 1. You may copy and distribute verbatim copies of the Program's
80
+ source code as you receive it, in any medium, provided that you
81
+ conspicuously and appropriately publish on each copy an appropriate
82
+ copyright notice and disclaimer of warranty; keep intact all the
83
+ notices that refer to this License and to the absence of any warranty;
84
+ and give any other recipients of the Program a copy of this License
85
+ along with the Program.
86
+
87
+ You may charge a fee for the physical act of transferring a copy, and
88
+ you may at your option offer warranty protection in exchange for a fee.
89
+
90
+ 2. You may modify your copy or copies of the Program or any portion
91
+ of it, thus forming a work based on the Program, and copy and
92
+ distribute such modifications or work under the terms of Section 1
93
+ above, provided that you also meet all of these conditions:
94
+
95
+ a) You must cause the modified files to carry prominent notices
96
+ stating that you changed the files and the date of any change.
97
+
98
+ b) You must cause any work that you distribute or publish, that in
99
+ whole or in part contains or is derived from the Program or any
100
+ part thereof, to be licensed as a whole at no charge to all third
101
+ parties under the terms of this License.
102
+
103
+ c) If the modified program normally reads commands interactively
104
+ when run, you must cause it, when started running for such
105
+ interactive use in the most ordinary way, to print or display an
106
+ announcement including an appropriate copyright notice and a
107
+ notice that there is no warranty (or else, saying that you provide
108
+ a warranty) and that users may redistribute the program under
109
+ these conditions, and telling the user how to view a copy of this
110
+ License. (Exception: if the Program itself is interactive but
111
+ does not normally print such an announcement, your work based on
112
+ the Program is not required to print an announcement.)
113
+
114
+ These requirements apply to the modified work as a whole. If
115
+ identifiable sections of that work are not derived from the Program,
116
+ and can be reasonably considered independent and separate works in
117
+ themselves, then this License, and its terms, do not apply to those
118
+ sections when you distribute them as separate works. But when you
119
+ distribute the same sections as part of a whole which is a work based
120
+ on the Program, the distribution of the whole must be on the terms of
121
+ this License, whose permissions for other licensees extend to the
122
+ entire whole, and thus to each and every part regardless of who wrote it.
123
+
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
195
+ this License.
196
+
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
200
+ otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
+ be similar in spirit to the present version, but may differ in detail to
240
+ address new problems or concerns.
241
+
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
@@ -0,0 +1,614 @@
1
+ # encoding: UTF-8
2
+
3
+ # Circular-Mail Library 0.0.1
4
+ # =================================================================================================
5
+ # Author: gabor.major@csn.hu
6
+ # Github: https://github.com/goobemaster/ruby-not-magic/circular-mail/
7
+ # Rubygems: http://rubygems.org/gems/circular-mail
8
+ # Description: Mass email sending through smtp. Highly configurable, feature rich, robust solution.
9
+ # Follows standards laid out in RFC-2822 (http://tools.ietf.org/html/rfc2822)
10
+ #
11
+ # This program is free software; you can redistribute it and/or modify
12
+ # it under the terms of the GNU General Public License as published by
13
+ # the Free Software Foundation; either version 2 of the License, or
14
+ # (at your option) any later version.
15
+ #
16
+ # This program is distributed in the hope that it will be useful,
17
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ # GNU General Public License for more details.
20
+ #
21
+ # You should have received a copy of the GNU General Public License along
22
+ # with this program; if not, write to the Free Software Foundation, Inc.,
23
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24
+ #
25
+ # =================================================================================================
26
+
27
+ $LOAD_PATH << './'
28
+
29
+ module CircularMail
30
+
31
+ require 'net/smtp'
32
+ require 'yaml'
33
+ require 'digest/md5'
34
+ require 'mime.rb'
35
+ require 'config.rb'
36
+ require 'common.rb'
37
+
38
+ class PostMaster
39
+ public
40
+
41
+ attr_accessor :smtp_server
42
+ attr_accessor :smtp_server_port
43
+ attr_accessor :smtp_server_username
44
+ attr_accessor :smtp_server_password
45
+ attr_accessor :smtp_server_authentication
46
+ attr_accessor :message_format
47
+ attr_accessor :message_character_set
48
+ attr_accessor :message_body
49
+ attr_accessor :message_subject
50
+ attr_reader :attachments
51
+ attr_reader :recipients
52
+ attr_accessor :mail_per_dispatch
53
+ attr_accessor :wait_after_dispatch
54
+ attr_accessor :sender
55
+ attr_accessor :sender_email
56
+
57
+ def smtp_server=(server)
58
+ if CircularMail::config('strictness')
59
+ CircularMail::die "SMTP server name '#{server.to_s}' is invalid!" if /^([\w\-]+\.)+\w{2,}$/.match(server.to_s).nil?
60
+ end
61
+ @smtp_server = server.to_s
62
+ end
63
+
64
+ def smtp_server_port=(port)
65
+ if CircularMail::config('strictness')
66
+ CircularMail::die "SMTP server port '#{port.to_s}' is invalid!" if (port.to_i < 0 || port.to_i > 65535)
67
+ end
68
+ @smtp_server_port = port.to_i
69
+ end
70
+
71
+ def smtp_server_username=(username)
72
+ if CircularMail::config('strictness')
73
+ CircularMail::die "SMTP server username '#{username.to_s}' is invalid!" if /^\S+$/.match(username.to_s).nil?
74
+ end
75
+ @smtp_server_username = username
76
+ end
77
+
78
+ def smtp_server_password=(password)
79
+ if CircularMail::config('strictness')
80
+ CircularMail::die "SMTP server username '#{password.to_s}' is invalid!" if /^\S*$/.match(password.to_s).nil?
81
+ end
82
+ @smtp_server_password = password
83
+ end
84
+
85
+ def smtp_authentication=(auth_type)
86
+ if CircularMail::config('strictness')
87
+ CircularMail::die "Authentication type '#{auth_type}' is not a valid option!" unless CircularMail::config('valid_authentications').include?(auth_type)
88
+ end
89
+ @smtp_server_authentication = auth_type
90
+ end
91
+
92
+ def set_smtp_server(server_and_port, username, password, auth_type)
93
+ self.smtp_server = server_and_port.to_s.split(":")[0]
94
+ self.smtp_server_port = server_and_port.to_s.split(":")[1]
95
+ self.smtp_server_username = username.to_s
96
+ self.smtp_server_password = password.to_s
97
+ self.smtp_server_authentication = auth_type.to_s
98
+ end
99
+
100
+ def set_message(format, subject, message)
101
+ self.message_format = format
102
+ if File.exists?(message.to_s)
103
+ self.message_body = File.read(message.to_s)
104
+ else
105
+ self.message_body = message
106
+ end
107
+ @subject = subject
108
+ end
109
+
110
+ def message_character_set=(charset)
111
+ CircularMail::die "Message character set of '#{charset}' is not supported!" unless CircularMail::config('valid_charsets').has_key?(charset.to_s)
112
+ @message_character_set = charset
113
+ end
114
+
115
+ def message_body=(message_body)
116
+ if CircularMail::config('strictness')
117
+ CircularMail::die "Message must be a non-empty string!" if message_body.to_s.length == 0
118
+ end
119
+ @message_body = message_body.to_s
120
+ end
121
+
122
+ def message_format=(format)
123
+ CircularMail::die "No such message format exists! Expected: #{CircularMail::config('valid_formats')}" unless CircularMail::config('valid_formats').include?(format.to_s)
124
+ @message_format = format
125
+ end
126
+
127
+ def mail_per_dispatch=(secs)
128
+ CircularMail::die 'Mail per dispatch value must be greater than zero!' if secs < 0
129
+ @mail_per_dispatch = secs.to_i
130
+ end
131
+
132
+ def wait_after_dispatch=(secs)
133
+ CircularMail::die 'Wait after dispatch value must be greater than zero!' if secs < 0
134
+ @wait_after_dispatch = secs.to_i
135
+ end
136
+
137
+ def sender_email=(email)
138
+ if CircularMail::config('strictness')
139
+ CircularMail::die "Email address '#{email}' is invalid!" if CircularMail::config('email_validation').match(email).nil?
140
+ end
141
+ @sender_email = email
142
+ end
143
+
144
+ def add_recipient(*args)
145
+ if CircularMail::config('strictness')
146
+ CircularMail::die "Email address '#{args[0]}' already added to recipients list!" if @recipients.include?(args[0])
147
+ CircularMail::die "Email address '#{args[0]}' is invalid!" if CircularMail::config('email_validation').match(args[0]).nil? && CircularMail::config('email_group_validation').match(args[0]).nil?
148
+ end
149
+ message_vars = []
150
+ if args.length > 1
151
+ (2..args.length).each { |var|
152
+ message_vars << args[var - 1]
153
+ }
154
+ end
155
+ @recipients << {args[0] => message_vars}
156
+ end
157
+
158
+ def remove_recipient(email)
159
+ if @recipients.include?(email)
160
+ @recipients.keep_if { |address| address != email}
161
+ elsif CircularMail::config('strictness')
162
+ CircularMail::die "Recipient list does not contain email address '#{email}' !"
163
+ end
164
+ end
165
+
166
+ def set_message_variable(*args)
167
+ # This method will add the email to recipients list if it does not exists yet!
168
+ unless @recipients.include?(args[0]) #TODO: fix me! Need to look for email address INSIDE hash!
169
+ add_recipient(*args)
170
+ else
171
+ # Ok, email exists lets override whatever variables it has
172
+ message_vars = []
173
+ if args.length > 1
174
+ (2..args.length).each { |var|
175
+ message_vars << args[var - 1]
176
+ }
177
+ end
178
+ @recipients[@recipients.index(args[0])] = message_vars
179
+ end
180
+ end
181
+ alias :set_message_variables :set_message_variable
182
+
183
+ def add_attachment(filename)
184
+ if @attachments.include?(filename)
185
+ CircularMail::die "Attachment '#{filename}' already added!" if CircularMail::config('strictness')
186
+ else
187
+ CircularMail::die "Attachment file '#{filename}' does not exists!" if CircularMail::config('strictness') && !File.exists?(filename)
188
+ @attachments << filename
189
+ end
190
+ end
191
+
192
+ def remove_attachment(filename)
193
+ if @attachments.include?(filename)
194
+ @attachments.keep_if { |file| file != filename}
195
+ elsif CircularMail::config('strictness')
196
+ CircularMail::die "Attachment list does not contain file '#{filename}' !"
197
+ end
198
+ end
199
+
200
+ # Start sending to all recipients using the standard process
201
+ def send()
202
+ self.save_as_yaml(Dir.getwd() + "/backup #{CircularMail.file_timestamp()}.yaml") if CircularMail::config('auto_backup_postmaster')
203
+ messages_sent = 0
204
+ messages_dispatch = 0
205
+
206
+ Net::SMTP.start(@smtp_server, @smtp_server_port, 'localhost', @smtp_server_username, @smtp_server_password, @smtp_server_authentication) do |smtp|
207
+ message_index = 0
208
+ message_body_personal = ""
209
+
210
+ @recipients.each { |recipient|
211
+ message_index += 1
212
+ to_email = ""
213
+
214
+ recipient.each { |mail, vars|
215
+ to_email = mail
216
+ var_index = 0
217
+ message_body_personal = @message_body
218
+ if vars.length > 0
219
+ vars.each { |var_value|
220
+ var_index += 1
221
+ message_body_personal = message_body_personal.gsub("@#{var_index.to_s}@", var_value)
222
+ }
223
+ else
224
+ message_body_personal = @message_body
225
+ end
226
+ }
227
+
228
+ message = CircularMail::Message.new(@message_format, @message_character_set, message_body_personal)
229
+ message.attachments = @attachments
230
+ message.header.add_field('From', "#{@sender}<#{@sender_email}>")
231
+ message.header.add_field('Sender', "#{@sender}<#{@sender_email}>")
232
+ message.header.add_field('Reply-To', @sender_email)
233
+ message.header.add_field('To', "<#{to_email}>")
234
+ message.header.add_field('Subject', @subject)
235
+ message.header.add_field('Comments', 'This email was generated and posted by the CircularMail ruby library. Author is not responsible for body content!')
236
+ message.header.add_field('Date', CircularMail::mail_timestamp())
237
+ $message_id = Digest::MD5.hexdigest(message_body_personal)
238
+ message.header.add_field('Message-ID', "<CircularMail@#{$message_id}>")
239
+
240
+ full_message = message.get()
241
+
242
+ smtp.send_message full_message, @sender_email, to_email
243
+
244
+ messages_sent += 1
245
+ messages_dispatch += 1
246
+ if messages_dispatch == @mail_per_dispatch
247
+ sleep @wait_after_dispatch
248
+ messages_dispatch = 0
249
+ end
250
+ }
251
+ end
252
+ return messages_sent
253
+ end
254
+ alias :send_all :send
255
+
256
+ # Send the message to a single recipient
257
+ # Useful if a recipient is complaining that he did not get the message, due to a spam filter or accidentally deleted the email
258
+ def send_to(email)
259
+
260
+ end
261
+
262
+ def save_as_yaml(filename)
263
+ CircularMail::die "Cannot save object because file '#{filename}' already exists!" if File.exists?(filename) && CircularMail::config('strictness')
264
+ filename = Dir.getwd() + "/dump #{CircularMail.file_timestamp()}.yaml" unless File.exists?(filename)
265
+ File.open(filename, 'w') { |f| f.write(YAML.dump(self)) }
266
+ end
267
+
268
+ def save_as_marshal(filename)
269
+ CircularMail::die "Cannot save object because file '#{filename}' already exists!" if File.exists?(filename) && CircularMail::config('strictness')
270
+ filename = Dir.getwd() + "/dump #{CircularMail.file_timestamp()}.marshal" unless File.exists?(filename)
271
+ File.open(filename, 'w') { |f| f.write(Marshal.dump(self)) }
272
+ end
273
+
274
+ def load_from_yaml(filename)
275
+ if File.exists?(filename)
276
+ o = YAML.load(File.read(filename))
277
+ @smtp_server = o.smtp_server
278
+ @smtp_server_port = o.smtp_server_port
279
+ @smtp_server_username = o.smtp_server_username
280
+ @smtp_server_password = o.smtp_server_password
281
+ @smtp_server_authentication = o.smtp_server_password
282
+ @message_format = o.smtp_server_password
283
+ @message_character_set = o.smtp_server_password
284
+ @message_body = o.smtp_server_password
285
+ @message_subject = o.smtp_server_password
286
+ @attachments = o.smtp_server_password
287
+ @recipients = o.smtp_server_password
288
+ @mail_per_dispatch = o.smtp_server_password
289
+ @wait_after_dispatch = o.smtp_server_password
290
+ @sender = o.smtp_server_password
291
+ @sender_email = o.smtp_server_password
292
+ elsif CircularMail::config('strictness')
293
+ CircularMail::die "Cannot load object because file '#{filename}' does not exists!"
294
+ end
295
+ end
296
+
297
+ def load_from_marshal(filename)
298
+ if File.exists?(filename)
299
+ o = File.open(filename, 'rb') {|f| m = Marshal::load(f)}
300
+ @smtp_server = o.smtp_server
301
+ @smtp_server_port = o.smtp_server_port
302
+ @smtp_server_username = o.smtp_server_username
303
+ @smtp_server_password = o.smtp_server_password
304
+ @smtp_server_authentication = o.smtp_server_password
305
+ @message_format = o.smtp_server_password
306
+ @message_character_set = o.smtp_server_password
307
+ @message_body = o.smtp_server_password
308
+ @message_subject = o.smtp_server_password
309
+ @attachments = o.smtp_server_password
310
+ @recipients = o.smtp_server_password
311
+ @mail_per_dispatch = o.smtp_server_password
312
+ @wait_after_dispatch = o.smtp_server_password
313
+ @sender = o.smtp_server_password
314
+ @sender_email = o.smtp_server_password
315
+ elsif CircularMail::config('strictness')
316
+ CircularMail::die "Cannot load object because file '#{filename}' does not exists!"
317
+ end
318
+ end
319
+
320
+ private
321
+
322
+ # Args - server_name:port, server_username, server_password, server_authentication
323
+ def initialize(*args)
324
+ case args.length
325
+ when 1
326
+ set_smtp_server(args[0], CircularMail::config('default_username'), CircularMail::config('default_password'), CircularMail::config('default_authentication'))
327
+ when 2
328
+ set_smtp_server(args[0], args[1], CircularMail::config('default_password'), CircularMail::config('default_authentication'))
329
+ when 3
330
+ set_smtp_server(args[0], args[1], args[2], CircularMail::config('default_authentication'))
331
+ when 4
332
+ set_smtp_server(args[0], args[1], args[2], args[3])
333
+ else
334
+ set_smtp_server("#{CircularMail::config('default_server')}:#{CircularMail::config('default_port').to_s}", CircularMail::config('default_username'), CircularMail::config('default_password'), CircularMail::config('default_authentication'))
335
+ end
336
+ self.message_format = CircularMail::config('default_format')
337
+ self.message_body = CircularMail::config('default_body')
338
+ self.message_character_set = CircularMail::config('default_charset')
339
+ self.mail_per_dispatch = CircularMail::config('default_mail_per_dispatch')
340
+ self.wait_after_dispatch = CircularMail::config('default_wait_after_dispatch')
341
+ self.sender_email = CircularMail::config('default_sender_email')
342
+ @recipients = CircularMail::config('recipients')
343
+ @attachments = CircularMail::config('attachments')
344
+ @sender = CircularMail::config('default_sender')
345
+ @subject = CircularMail::config('default_subject')
346
+ end
347
+ end
348
+
349
+ class Message
350
+ public
351
+
352
+ attr_accessor :header
353
+ attr_accessor :body
354
+ attr_accessor :format
355
+ attr_accessor :character_set
356
+ attr_accessor :attachments
357
+
358
+ def format=(format)
359
+ if CircularMail::config('valid_formats').include?(format.to_s)
360
+ @format = format
361
+ else
362
+ @format = CircularMail::config('default_format')
363
+ end
364
+ end
365
+
366
+ def character_set=(charset)
367
+ if CircularMail::config('valid_charsets').has_key?(charset.to_s)
368
+ @character_set = charset
369
+ else
370
+ @character_set = CircularMail::config('default_charset')
371
+ end
372
+ end
373
+
374
+ def body=(body)
375
+ if CircularMail::config('strictness')
376
+ unless body.empty?
377
+ if @format == 'text'
378
+ char_limit = CircularMail::config('character_limit_text')
379
+ elsif @format == 'html'
380
+ char_limit = CircularMail::config('character_limit')
381
+ end
382
+ body.each_line { |line|
383
+ CircularMail::die("Each line of body text *should not* be longer than #{char_limit} characters!") if line.length > char_limit
384
+ }
385
+ end
386
+ end
387
+ unless CircularMail::check_charset(body, @character_set)
388
+ CircularMail::die("Message body contains one or more characters which are not part of '#{@character_set}' !") if CircularMail::config('strictness')
389
+ end
390
+ @body = body
391
+ end
392
+
393
+ def attachments=(file_list)
394
+ CircularMail::die("Attachment list must be composed of filenames in an array!") if file_list.class.to_s != "Array"
395
+ @attachments = file_list
396
+ end
397
+
398
+ def get()
399
+ if @header.fields.length > 0
400
+ CircularMail::die("Date and From header fields must be present in the message as per RFC-2822!") if !@header.present?('Date') || !@header.present?('From')
401
+ @header.add_field('Content-Transfer-Encoding', 'base64') unless header.present?('Content-Transfer-Encoding')
402
+ message_body = CircularMail::encode(@body, @header.get_field('Content-Transfer-Encoding'))
403
+
404
+ if @format == 'text'
405
+ content_type = 'text/plain'
406
+ else
407
+ content_type = 'text/html'
408
+ end
409
+
410
+ if @attachments.length == 0
411
+ @header.add_field('Content-Type', "#{content_type};charset=#{@character_set}")
412
+ return "#{@header.get()}\r\n#{message_body}"
413
+ else
414
+ @header.add_field('MIME-Version', '1.0')
415
+ @header.add_field('Content-Type', "multipart/mixed; boundary=#{$message_id}")
416
+ message_body = "Content-Type:#{content_type}\r\nContent-Transfer-Encoding:base64\r\n\r\n#{message_body}--#{$message_id}"
417
+ return "#{@header.get()}\r\n--#{$message_id}\r\n#{message_body}\r\n#{attachments_body()}"
418
+ end
419
+ else
420
+ CircularMail::die("Cannot generate message, because lack of header fields!") if CircularMail::config('strictness')
421
+ return nil
422
+ end
423
+ end
424
+
425
+ private
426
+
427
+ def initialize(*args)
428
+ case args.length
429
+ when 1
430
+ self.format = args[0]
431
+ self.character_set = CircularMail::config('default_charset')
432
+ @body = CircularMail::config('default_body')
433
+ when 2
434
+ self.format = args[0]
435
+ self.character_set = args[1]
436
+ @body = CircularMail::config('default_body')
437
+ when 3
438
+ self.format = args[0]
439
+ self.character_set = args[1]
440
+ @body = args[2]
441
+ else
442
+ self.format = CircularMail::config('default_format')
443
+ self.character_set = CircularMail::config('default_charset')
444
+ @body = CircularMail::config('default_body')
445
+ end
446
+
447
+ @header = CircularMail::Header.new()
448
+ @attachments = []
449
+ end
450
+
451
+ def attachments_body()
452
+ attachment_body = ""
453
+ index = 0
454
+ @attachments.each { |filename|
455
+ if File.exists?(filename)
456
+ index += 1
457
+ a_body = CircularMail::encode(CircularMail::file_get_contents(filename), 'base64')
458
+ a_header = CircularMail::Header.new()
459
+ a_header.add_field('Content-Type', "#{CircularMail::file_content_type?(filename)};charset=#{@character_set}")
460
+ a_header.add_field('Content-Transfer-Encoding', 'base64')
461
+ a_header.add_field('Content-Disposition', "attachment;filename=\"#{File.basename(filename)}\"")
462
+ attachment_body << "#{a_header.get()}\r\n#{a_body}"
463
+ if index != @attachments.length
464
+ attachment_body << "--#{$message_id}\r\n"
465
+ else
466
+ attachment_body << "--#{$message_id}--"
467
+ end
468
+ end
469
+ }
470
+ return attachment_body
471
+ end
472
+
473
+ end
474
+
475
+ # Description: This object can store 16 selected header fields, which are mandatory for CircularMail.
476
+ # Validation of field values is happening in this class, rather than in Header. This is due to keep Header clean.
477
+ class HeaderField
478
+ public
479
+
480
+ attr_reader :name
481
+ attr_reader :body
482
+
483
+ def set(name, body)
484
+ case name
485
+ when 'From' # from
486
+ CircularMail::die("Inappropriate value for 'From' header field!") if CircularMail::config('strictness') && CircularMail::config('header_address_validation').match(body).nil?
487
+ when 'Sender' # sender
488
+ CircularMail::die("Inappropriate value for 'Sender' header field!") if CircularMail::config('strictness') && CircularMail::config('header_address_validation').match(body).nil?
489
+ when 'Reply-To' # reply-to
490
+ CircularMail::die("Inappropriate value for 'Reply-To' header field!") if CircularMail::config('strictness') && CircularMail::config('email_validation').match(body).nil?
491
+ when 'To' # to
492
+ CircularMail::die("Inappropriate value for 'To' header field!") if CircularMail::config('strictness') && CircularMail::config('header_address_validation').match(body).nil?
493
+ when 'Cc' # cc
494
+ CircularMail::die("Inappropriate value for 'Cc' header field!") if CircularMail::config('strictness') && CircularMail::config('header_address_validation').match(body).nil?
495
+ when 'Bcc' # bcc
496
+ CircularMail::die("Inappropriate value for 'Bcc' header field!") if CircularMail::config('strictness') && CircularMail::config('header_address_validation').match(body).nil?
497
+ when 'Message-ID' # message-id
498
+ CircularMail::die("Inappropriate value for 'Message-ID' header field!") if CircularMail::config('strictness') && CircularMail::config('header_msgid_validation').match(body).nil?
499
+ when 'Subject' # subject unstructured
500
+ CircularMail::die("Inappropriate value for 'Subject' header field!") if CircularMail::config('strictness') && CircularMail::config('header_unstructured_validation').match(body).nil?
501
+ when 'Comments' # comments unstructured
502
+ CircularMail::die("Inappropriate value for 'Comments' header field!") if CircularMail::config('strictness') && CircularMail::config('header_unstructured_validation').match(body).nil?
503
+ when 'Date' # orig-date
504
+ CircularMail::die("Inappropriate value for 'Message-ID' header field!") if CircularMail::config('strictness') && CircularMail::config('header_date_validation').match(body).nil?
505
+ when 'MIME-Version'
506
+ CircularMail::die("Only MIME 1.0 is supported in CircularMail!") if CircularMail::config('strictness') && body != '1.0'
507
+ when 'Content-Type'
508
+ CircularMail::die("Inappropriate value for 'Content-Type' header field!") if CircularMail::config('strictness') && CircularMail::config('header_content_type_validation').match(body).nil?
509
+ when 'Content-Transfer-Encoding'
510
+ CircularMail::die("Inappropriate value for 'Content-Transfer-Encoding' header field!") if CircularMail::config('strictness') && CircularMail::config('header_content_encoding_validation').match(body).nil?
511
+ when 'Content-ID'
512
+ CircularMail::die("Inappropriate value for 'Content-ID' header field!") if CircularMail::config('strictness') && CircularMail::config('header_msgid_validation').match(body).nil?
513
+ when 'Content-Description'
514
+ CircularMail::die("Inappropriate value for 'Content-Description' header field!") if CircularMail::config('strictness') && !CircularMail::check_charset(body, 'us-ascii')
515
+ when 'Content-Disposition'
516
+ CircularMail::die("Inappropriate value for 'Content-Disposition' header field!") if CircularMail::config('strictness') && !CircularMail::check_charset(body, 'us-ascii')
517
+ else
518
+ if CircularMail::config('strictness')
519
+ CircularMail::die("Unsupported header field! Expected: #{CircularMail::config('valid_header_fields')}") unless CircularMail::config('valid_header_fields').include?(name)
520
+ else
521
+ name = CircularMail::config('fallback_header_field')
522
+ body = CircularMail::config('fallback_header_body')
523
+ end
524
+ end
525
+
526
+ if CircularMail::config('strictness')
527
+ CircularMail::die("Header field body cannot contain CR, LF characters! (Don't worry, it will be appended automatically)") if body.include?("\r") || body.include?("\n")
528
+ else
529
+ body.gsub!("\r", "")
530
+ body.gsub!("\n", "")
531
+ end
532
+
533
+ @name = name
534
+ @body = body
535
+ end
536
+
537
+ def get()
538
+ return "#{@name}:#{@body}\r\n"
539
+ end
540
+
541
+ private
542
+
543
+ def initialize(name = 'Comments', body = ' ')
544
+ set(name, body)
545
+ end
546
+ end
547
+
548
+ # Description: Basically holds an array of HeaderField objects.
549
+ # You can add, modify, remove fields, then get the whole header as a string by calling to_s (alias: get)
550
+ class Header
551
+ public
552
+
553
+ attr_reader :fields
554
+
555
+ def add_field(name, body)
556
+ CircularMail.die("Although RFC-2822 allows multiple header fields of the same type, it *should* be avoided!") if duplicate_header?(name) && CircularMail::config('strictness')
557
+ field = CircularMail::HeaderField.new(name, body)
558
+ @fields.push(field)
559
+ end
560
+
561
+ def modify_field(name, body)
562
+ if @fields.length > 0
563
+ index = @fields.index{ |field| field.name == name}
564
+ @fields[index] = CircularMail::HeaderField.new(name, body) if index > -1 && index < @fields.size
565
+ end
566
+ end
567
+
568
+ def remove_field(name)
569
+ if @fields.length > 0
570
+ @fields.keep_if { |field| field.name != name}
571
+ end
572
+ end
573
+
574
+ def remove_all_fields()
575
+ @fields = []
576
+ end
577
+
578
+ def get()
579
+ head = ""
580
+ if @fields.length > 0
581
+ @fields.each { |field|
582
+ head << field.get()
583
+ }
584
+ end
585
+ return head
586
+ end
587
+
588
+ def get_field(name)
589
+ if @fields.length > 0
590
+ @fields.each { |field|
591
+ return field.body if field.name == name
592
+ }
593
+ end
594
+ return nil
595
+ end
596
+
597
+ def duplicate_header?(name)
598
+ if @fields.length > 0
599
+ @fields.each { |field|
600
+ return true if field.name == name
601
+ }
602
+ end
603
+ false
604
+ end
605
+ alias :present? :duplicate_header?
606
+
607
+ private
608
+
609
+ def initialize()
610
+ @fields = []
611
+ end
612
+ end
613
+
614
+ end
@@ -0,0 +1,90 @@
1
+ # encoding: UTF-8
2
+
3
+ module CircularMail
4
+
5
+ def self.postmaster_from_yaml(filename)
6
+ if File.exists?(filename)
7
+ o = YAML.load(File.read(filename))
8
+ return o
9
+ elsif config('strictness')
10
+ die "Cannot load object because file '#{filename}' does not exists!"
11
+ end
12
+ end
13
+
14
+ def self.postmaster_from_marshal(filename)
15
+ if File.exists?(filename)
16
+ o = File.open(filename, 'rb') {|f| m = Marshal::load(f)}
17
+ return o
18
+ elsif config('strictness')
19
+ die "Cannot load object because file '#{filename}' does not exists!"
20
+ end
21
+ end
22
+
23
+ def self.file_timestamp()
24
+ return Time.now.to_s[0..18].gsub(":", "-")
25
+ end
26
+
27
+ def self.mail_timestamp()
28
+ # ex. Thu, 13 Feb 1969 23:32:54 -0330
29
+ return Time.now.strftime('%a, %d %b %Y %H:%M:%S %z')
30
+ end
31
+
32
+ def self.encode(what, how)
33
+ case how
34
+ when '7bit'
35
+ body = ''
36
+ when '8bit'
37
+ body = ''
38
+ when 'binary'
39
+ return [what].pack('A*')
40
+ when 'quoted-printable'
41
+ return [what].pack('M*')
42
+ when 'base64'
43
+ return [what].pack('m*')
44
+ when 'ietf-token'
45
+ body = ''
46
+ when 'x-token'
47
+ body = ''
48
+ end
49
+ end
50
+
51
+ def self.check_charset(what, charset)
52
+ case charset
53
+ when 'us-ascii', 'ascii'
54
+ what.scan(/./).map(&:ord).each { |byte|
55
+ return false unless config('valid_charsets')[charset].include?(byte)
56
+ }
57
+ return true
58
+ when 'utf-8'
59
+ return what.force_encoding("UTF-8").valid_encoding?
60
+ else
61
+ die "Cannot check this kind of character set on target string!" if config('strictness')
62
+ return nil
63
+ end
64
+ end
65
+
66
+ def self.file_get_contents(filename)
67
+ c = ""
68
+ if File.exists?(filename)
69
+ File.open(filename, 'rb') { |io| c += io.read }
70
+ return c
71
+ else
72
+ return nil
73
+ end
74
+ end
75
+
76
+ def self.file_content_type?(filename)
77
+ ext = File.extname(filename).gsub!(".", "").downcase
78
+ if @@mime.has_key?(ext)
79
+ return @@mime[ext]
80
+ else
81
+ return 'application/octet-stream'
82
+ end
83
+ end
84
+
85
+ def self.die(message)
86
+ raise message << "
87
+ For more info please visit: https://github.com/goobemaster/ruby-not-magic/circular-mail/"
88
+ end
89
+
90
+ end
@@ -0,0 +1,60 @@
1
+ module CircularMail
2
+
3
+ @@config = {'strictness' => true,
4
+ 'default_server' => 'mail.server.com',
5
+ 'default_port' => 25,
6
+ 'default_username' => 'guest',
7
+ 'default_password' => '',
8
+ 'default_authentication' => 'plain',
9
+ 'valid_authentications' => ['plain', 'login', 'cram_md5'],
10
+ 'valid_formats' => ['text', 'html'],
11
+ 'valid_charsets' => {'us-ascii' => 33..126, 'ascii' => 1..255, 'utf-8' => 1..1114111},
12
+ 'default_charset' => 'us-ascii',
13
+ 'default_format' => 'text',
14
+ 'character_limit' => 998,
15
+ 'character_limit_text' => 78,
16
+ 'default_body' => "Dear @1@,\n\nPlease be informed that...\nYour custom string is: '@2@'\n\nKind Regards,\nAnonymous",
17
+ 'default_subject' => 'Your unique string',
18
+ 'default_sender' => '',
19
+ 'default_sender_email' => 'mail@default.com',
20
+ 'email_validation' => /^[a-z0-9!#\$%&'\*\+\/=\?\^_`\{\|\}~\-]+(?:\.[a-z0-9!#\$%&'\*\+\/=\?\^_`\{\|\}~\-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/,
21
+ 'email_group_validation' => /^<[a-z0-9!#\$%&'\*\+\/=\?\^_`\{\|\}~\-]+>$/,
22
+ 'recipients' => [],
23
+ 'attachments' => [],
24
+ 'undefined_variable' => '(?!)',
25
+ 'default_mail_per_dispatch' => 3,
26
+ 'default_wait_after_dispatch' => 3,
27
+ 'auto_backup_postmaster' => true,
28
+ 'cr' => 13,
29
+ 'lf' => 10,
30
+ 'header_date_validation' => /^(Mon|Tue|Wed|Thu|Fri|Sat|Sun), [0-9]{2} (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [0-9]{4} [0-9]{2}:[0-9]{2}:[0-9]{2} (\+|\-)[0-9]{4}$/,
31
+ 'valid_header_fields' => ['From', 'Sender', 'Reply-To', 'To', 'Cc', 'Bcc', 'Message-ID', 'Subject', 'Comments', 'Date'],
32
+ 'header_address_validation' => /^[a-zA-Z ]*<[a-z0-9!#\$%&'\*\+\/=\?\^_`\{\|\}~\-]+(?:\.[a-z0-9!#\$%&'\*\+\/=\?\^_`\{\|\}~\-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?>$/,
33
+ 'header_msgid_validation' => /^<([a-zA-Z0-9!#\$%&'\*\+\-\/=\?\^_`\{\}\|~]+\.?)+@([a-zA-Z0-9!#\$%&'\*\+\-\/=\?\^_`\{\}\|~]+\.?)+>$/,
34
+ 'header_unstructured_validation' => /^[a-zA-Z0-9!#\$%&'\*\+\-\/=\?\^_`\{\}\|~ \.]+$/,
35
+ 'header_content_type_validation' => /^[a-z0-9\-]+\/[a-z0-9\-]+;[ ]*(charset|boundary)=("[a-z0-9\-]+"|[a-z0-9\-]+)$/i,
36
+ 'header_content_encoding_validation' => /^7bit|8bit|binary|quoted-printable|base64|ietf-token|x-token$/i,
37
+ 'fallback_header_field' => 'comments',
38
+ 'fallback_header_body' => ''}
39
+
40
+ def self.config_has_key?(key)
41
+ @@config.has_key?(key)
42
+ end
43
+
44
+ def self.config(key)
45
+ if @@config.has_key?(key)
46
+ return @@config[key]
47
+ else
48
+ return nil
49
+ end
50
+ end
51
+
52
+ def self.set_config(key, value)
53
+ if @@config.has_key?(key)
54
+ return @@config[key] = value
55
+ else
56
+ return nil
57
+ end
58
+ end
59
+
60
+ end
@@ -0,0 +1,197 @@
1
+ # encoding: UTF-8
2
+
3
+ module CircularMail
4
+
5
+ @@mime = {'evy' => 'application/envoy',
6
+ 'fif' => 'application/fractals',
7
+ 'spl' => 'application/futuresplash',
8
+ 'hta' => 'application/hta',
9
+ 'acx' => 'application/internet-property-stream',
10
+ 'hqx' => 'application/mac-binhex40',
11
+ 'doc' => 'application/msword',
12
+ 'dot' => 'application/msword',
13
+ 'bin' => 'application/octet-stream',
14
+ 'class' => 'application/octet-stream',
15
+ 'dms' => 'application/octet-stream',
16
+ 'exe' => 'application/octet-stream',
17
+ 'lha' => 'application/octet-stream',
18
+ 'lzh' => 'application/octet-stream',
19
+ 'oda' => 'application/oda',
20
+ 'axs' => 'application/olescript',
21
+ 'pdf' => 'application/pdf',
22
+ 'prf' => 'application/pics-rules',
23
+ 'p10' => 'application/pkcs10',
24
+ 'crl' => 'application/pkix-crl',
25
+ 'ai' => 'application/postscript',
26
+ 'eps' => 'application/postscript',
27
+ 'ps' => 'application/postscript',
28
+ 'rtf' => 'application/rtf',
29
+ 'setpay' => 'application/set-payment-initiation',
30
+ 'setreg' => 'application/set-registration-initiation',
31
+ 'xla' => 'application/vnd.ms-excel',
32
+ 'xlc' => 'application/vnd.ms-excel',
33
+ 'xlm' => 'application/vnd.ms-excel',
34
+ 'xls' => 'application/vnd.ms-excel',
35
+ 'xlt' => 'application/vnd.ms-excel',
36
+ 'xlw' => 'application/vnd.ms-excel',
37
+ 'msg' => 'application/vnd.ms-outlook',
38
+ 'sst' => 'application/vnd.ms-pkicertstore',
39
+ 'cat' => 'application/vnd.ms-pkiseccat',
40
+ 'stl' => 'application/vnd.ms-pkistl',
41
+ 'pot' => 'application/vnd.ms-powerpoint',
42
+ 'pps' => 'application/vnd.ms-powerpoint',
43
+ 'ppt' => 'application/vnd.ms-powerpoint',
44
+ 'mpp' => 'application/vnd.ms-project',
45
+ 'wcm' => 'application/vnd.ms-works',
46
+ 'wdb' => 'application/vnd.ms-works',
47
+ 'wks' => 'application/vnd.ms-works',
48
+ 'wps' => 'application/vnd.ms-works',
49
+ 'hlp' => 'application/winhlp',
50
+ 'bcpio' => 'application/x-bcpio',
51
+ 'cdf' => 'application/x-cdf',
52
+ 'z' => 'application/x-compress',
53
+ 'tgz' => 'application/x-compressed',
54
+ 'cpio' => 'application/x-cpio',
55
+ 'csh' => 'application/x-csh',
56
+ 'dcr' => 'application/x-director',
57
+ 'dir' => 'application/x-director',
58
+ 'dxr' => 'application/x-director',
59
+ 'dvi' => 'application/x-dvi',
60
+ 'gtar' => 'application/x-gtar',
61
+ 'gz' => 'application/x-gzip',
62
+ 'hdf' => 'application/x-hdf',
63
+ 'ins' => 'application/x-internet-signup',
64
+ 'isp' => 'application/x-internet-signup',
65
+ 'iii' => 'application/x-iphone',
66
+ 'js' => 'application/x-javascript',
67
+ 'latex' => 'application/x-latex',
68
+ 'mdb' => 'application/x-msaccess',
69
+ 'crd' => 'application/x-mscardfile',
70
+ 'clp' => 'application/x-msclip',
71
+ 'dll' => 'application/x-msdownload',
72
+ 'm13' => 'application/x-msmediaview',
73
+ 'm14' => 'application/x-msmediaview',
74
+ 'mvb' => 'application/x-msmediaview',
75
+ 'wmf' => 'application/x-msmetafile',
76
+ 'mny' => 'application/x-msmoney',
77
+ 'pub' => 'application/x-mspublisher',
78
+ 'scd' => 'application/x-msschedule',
79
+ 'trm' => 'application/x-msterminal',
80
+ 'wri' => 'application/x-mswrite',
81
+ 'cdf' => 'application/x-netcdf',
82
+ 'nc' => 'application/x-netcdf',
83
+ 'pma' => 'application/x-perfmon',
84
+ 'pmc' => 'application/x-perfmon',
85
+ 'pml' => 'application/x-perfmon',
86
+ 'pmr' => 'application/x-perfmon',
87
+ 'pmw' => 'application/x-perfmon',
88
+ 'p12' => 'application/x-pkcs12',
89
+ 'pfx' => 'application/x-pkcs12',
90
+ 'p7b' => 'application/x-pkcs7-certificates',
91
+ 'spc' => 'application/x-pkcs7-certificates',
92
+ 'p7r' => 'application/x-pkcs7-certreqresp',
93
+ 'p7c' => 'application/x-pkcs7-mime',
94
+ 'p7m' => 'application/x-pkcs7-mime',
95
+ 'p7s' => 'application/x-pkcs7-signature',
96
+ 'sh' => 'application/x-sh',
97
+ 'shar' => 'application/x-shar',
98
+ 'swf' => 'application/x-shockwave-flash',
99
+ 'sit' => 'application/x-stuffit',
100
+ 'sv4cpio' => 'application/x-sv4cpio',
101
+ 'sv4crc' => 'application/x-sv4crc',
102
+ 'tar' => 'application/x-tar',
103
+ 'tcl' => 'application/x-tcl',
104
+ 'tex' => 'application/x-tex',
105
+ 'texi' => 'application/x-texinfo',
106
+ 'texinfo' => 'application/x-texinfo',
107
+ 'roff' => 'application/x-troff',
108
+ 't' => 'application/x-troff',
109
+ 'tr' => 'application/x-troff',
110
+ 'man' => 'application/x-troff-man',
111
+ 'me' => 'application/x-troff-me',
112
+ 'ms' => 'application/x-troff-ms',
113
+ 'ustar' => 'application/x-ustar',
114
+ 'src' => 'application/x-wais-source',
115
+ 'cer' => 'application/x-x509-ca-cert',
116
+ 'crt' => 'application/x-x509-ca-cert',
117
+ 'der' => 'application/x-x509-ca-cert',
118
+ 'pko' => 'application/ynd.ms-pkipko',
119
+ 'zip' => 'application/zip',
120
+ 'au' => 'audio/basic',
121
+ 'snd' => 'audio/basic',
122
+ 'mid' => 'audio/mid',
123
+ 'rmi' => 'audio/mid',
124
+ 'mp3' => 'audio/mpeg',
125
+ 'aif' => 'audio/x-aiff',
126
+ 'aifc' => 'audio/x-aiff',
127
+ 'aiff' => 'audio/x-aiff',
128
+ 'm3u' => 'audio/x-mpegurl',
129
+ 'ra' => 'audio/x-pn-realaudio',
130
+ 'ram' => 'audio/x-pn-realaudio',
131
+ 'wav' => 'audio/x-wav',
132
+ 'bmp' => 'image/bmp',
133
+ 'cod' => 'image/cis-cod',
134
+ 'gif' => 'image/gif',
135
+ 'ief' => 'image/ief',
136
+ 'jpe' => 'image/jpeg',
137
+ 'jpeg' => 'image/jpeg',
138
+ 'jpg' => 'image/jpeg',
139
+ 'jfif' => 'image/pipeg',
140
+ 'svg' => 'image/svg+xml',
141
+ 'png' => 'image/png',
142
+ 'tif' => 'image/tiff',
143
+ 'tiff' => 'image/tiff',
144
+ 'ras' => 'image/x-cmu-raster',
145
+ 'cmx' => 'image/x-cmx',
146
+ 'ico' => 'image/x-icon',
147
+ 'pnm' => 'image/x-portable-anymap',
148
+ 'pbm' => 'image/x-portable-bitmap',
149
+ 'pgm' => 'image/x-portable-graymap',
150
+ 'ppm' => 'image/x-portable-pixmap',
151
+ 'rgb' => 'image/x-rgb',
152
+ 'xbm' => 'image/x-xbitmap',
153
+ 'xpm' => 'image/x-xpixmap',
154
+ 'xwd' => 'image/x-xwindowdump',
155
+ 'mht' => 'message/rfc822',
156
+ 'mhtml' => 'message/rfc822',
157
+ 'nws' => 'message/rfc822',
158
+ 'css' => 'text/css',
159
+ '323' => 'text/h323',
160
+ 'htm' => 'text/html',
161
+ 'html' => 'text/html',
162
+ 'stm' => 'text/html',
163
+ 'uls' => 'text/iuls',
164
+ 'bas' => 'text/plain',
165
+ 'c' => 'text/plain',
166
+ 'h' => 'text/plain',
167
+ 'txt' => 'text/plain',
168
+ 'rtx' => 'text/richtext',
169
+ 'sct' => 'text/scriptlet',
170
+ 'tsv' => 'text/tab-separated-values',
171
+ 'htt' => 'text/webviewhtml',
172
+ 'htc' => 'text/x-component',
173
+ 'etx' => 'text/x-setext',
174
+ 'vcf' => 'text/x-vcard',
175
+ 'mp2' => 'video/mpeg',
176
+ 'mpa' => 'video/mpeg',
177
+ 'mpe' => 'video/mpeg',
178
+ 'mpeg' => 'video/mpeg',
179
+ 'mpg' => 'video/mpeg',
180
+ 'mpv2' => 'video/mpeg',
181
+ 'mov' => 'video/quicktime',
182
+ 'qt' => 'video/quicktime',
183
+ 'lsf' => 'video/x-la-asf',
184
+ 'lsx' => 'video/x-la-asf',
185
+ 'asf' => 'video/x-ms-asf',
186
+ 'asr' => 'video/x-ms-asf',
187
+ 'asx' => 'video/x-ms-asf',
188
+ 'avi' => 'video/x-msvideo',
189
+ 'movie' => 'video/x-sgi-movie',
190
+ 'flr' => 'x-world/x-vrml',
191
+ 'vrml' => 'x-world/x-vrml',
192
+ 'wrl' => 'x-world/x-vrml',
193
+ 'wrz' => 'x-world/x-vrml',
194
+ 'xaf' => 'x-world/x-vrml',
195
+ 'xof' => 'x-world/x-vrml'}
196
+
197
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: circular-mail
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gabor Major
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-24 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: ! 'Mass email sending through smtp, rfc-2822 standard. Highly configurable,
14
+ and feature rich solution: attachments, message variables, text or html messages
15
+ etc...'
16
+ email: gabor.major@csn.hu
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/circular-mail.rb
22
+ - lib/common.rb
23
+ - lib/config.rb
24
+ - lib/mime.rb
25
+ - gpl-2.0.txt
26
+ homepage: http://rubygems.org/gems/circular-mail
27
+ licenses:
28
+ - GPL-2
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: 1.9.3
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 2.0.3
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: Versatile mass email sender
50
+ test_files: []