whotowho 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,5 @@
1
+ == 0.1.0 / 2007-11-16
2
+
3
+ * 1 major enhancement
4
+ * First Release
5
+
data/Manifest.txt ADDED
@@ -0,0 +1,16 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bin/whotowho
6
+ conf.yaml
7
+ conf/conf.yaml.example
8
+ conf/data.yaml.example
9
+ conf/mail-example.txt
10
+ data.yaml
11
+ lib/whotowho.rb
12
+ lib/whotowho/link.rb
13
+ lib/whotowho/parseargs.rb
14
+ lib/whotowho/sendmail.rb
15
+ lib/whotowho/smtp_tls.rb
16
+ test/test_whotowho.rb
data/README.txt ADDED
@@ -0,0 +1,264 @@
1
+ WhoToWho
2
+
3
+ * http://dev.shingara.fr/projects/show/4
4
+ * mailto:cyril.mougel@gmail.com
5
+
6
+ == HISTORY:
7
+
8
+ WhoToWho made in first for my friend group. For Christmas, we decide to
9
+ group us and we offer one present for only one other personne. The price is
10
+ define in first for this present.
11
+
12
+ Before WhoToWho, we made a group before the Christmas night and we made a
13
+ random choice of who must offer to who. The choice is made with little paper
14
+ in hat.
15
+
16
+ Now we are in different place and we can't see every week. So, like we have
17
+ all an email, I created WhoToWho. So I can't know who must be offer to who and
18
+ it's a total random.
19
+
20
+ Yes, WhoToWho is useless. But What is really usefull?
21
+
22
+ == DESCRIPTION:
23
+
24
+ WhoToWho is a simple script to define a name randomly in list of name. And
25
+ send this name by email. With WhoToWho you can define several thing:
26
+
27
+ * Subject of Mail
28
+ * Format of Mail with 2 parameters (who and towho)
29
+ * The configuration of smtp connection
30
+ * Add options for SSL if your smtp connection is a Gmail account
31
+
32
+
33
+ == FEATURES:
34
+
35
+ * Randomize a list and choice one persone for another
36
+ * Send an email where the personne know who is define to it
37
+ * Define the subject and the content of mail with 2 places for define word
38
+ * who and to who
39
+
40
+ == SYNOPSIS:
41
+
42
+ Usage: ./whotowho.rb [options]
43
+ -v, --verbose Run verbosely
44
+ -f, --file FILE File where is all data
45
+ -c, --config FILE File where is all config
46
+ -g, --gmail Define option if use a Gmail account for SMTP
47
+ -s, --subject SUBJECT Define the subject to send by email
48
+ -m, --mail MAIL Send a file where the content is with 2 params #{who} and #{towho}
49
+
50
+ == REQUIREMENT:
51
+
52
+ * ActionMailer from Ruby On Rails project : gem install actionmailer
53
+
54
+ == INSTALL:
55
+
56
+ = Archive *.tar.gz
57
+
58
+ * Install actionmailer before
59
+ * Untar the archive
60
+ * Go to bin directory
61
+ * Start command whotowho
62
+
63
+ = Gem
64
+
65
+ * gem install whotowho
66
+
67
+ == Example of command
68
+
69
+ ruby whotowho -m mail-example.txt -s 'a good subject' -f ../data.yaml -c conf.yaml -g
70
+
71
+ == Example of File configuration
72
+
73
+ = File data example
74
+
75
+ This file define the list of name and email. The format of this file is YAML. It's the serialization of an Array of an Array in Ruby. A example of format is :
76
+
77
+ - - name
78
+ - email
79
+ - - name2
80
+ - email2
81
+ - - name3
82
+ - email3
83
+
84
+ = File of mail configuration
85
+
86
+ It's the same of actionmailer. But I have add a configuration of from. You need had :from:
87
+
88
+ :address: Allows you to use a remote mail server. Just change it from its default "localhost" setting.
89
+ :port: On the off chance that your mail server doesn‘t run on port 25, you can change it.
90
+ :domain: If you need to specify a HELO domain, you can do it here.
91
+ :user_name: If your mail server requires authentication, set the username in this setting.
92
+ :password: If your mail server requires authentication, set the password in this setting.
93
+ :authentication: If your mail server requires authentication, you need to specify the authentication type here. This is a symbol and one of :plain, :login, :cram_md5
94
+ :from: Define the email who send all mail in from header
95
+
96
+ = File of mail content
97
+
98
+ This file is a simple text file. You have two patterns who change before the send.
99
+
100
+ * #{who} : it's the name of person who receiv the mail
101
+ * #{towho} : the name of person assign to personne who receiv this mail
102
+
103
+ == LICENSE:
104
+
105
+ (The GPLv3 License)
106
+
107
+ GNU GENERAL PUBLIC LICENSE
108
+
109
+ Version 3, 29 June 2007
110
+
111
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
112
+
113
+ Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
114
+ Preamble
115
+
116
+ The GNU General Public License is a free, copyleft license for software and other kinds of works.
117
+
118
+ The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too.
119
+
120
+ When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.
121
+
122
+ To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others.
123
+
124
+ For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
125
+
126
+ Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it.
127
+
128
+ For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions.
129
+
130
+ Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users.
131
+
132
+ Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free.
133
+
134
+ The precise terms and conditions for copying, distribution and modification follow.
135
+ TERMS AND CONDITIONS
136
+ 0. Definitions.
137
+
138
+ “This License” refers to version 3 of the GNU General Public License.
139
+
140
+ “Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
141
+
142
+ “The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations.
143
+
144
+ To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work.
145
+
146
+ A “covered work” means either the unmodified Program or a work based on the Program.
147
+
148
+ To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
149
+
150
+ To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
151
+
152
+ An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
153
+ 1. Source Code.
154
+
155
+ The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work.
156
+
157
+ A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
158
+
159
+ The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
160
+
161
+ The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work.
162
+
163
+ The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
164
+
165
+ The Corresponding Source for a work in source code form is that same work.
166
+ 2. Basic Permissions.
167
+
168
+ All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
169
+
170
+ You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
171
+
172
+ Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
173
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
174
+
175
+ No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
176
+
177
+ When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
178
+ 4. Conveying Verbatim Copies.
179
+
180
+ You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
181
+
182
+ You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
183
+ 5. Conveying Modified Source Versions.
184
+
185
+ You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
186
+
187
+ * a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
188
+ * b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”.
189
+ * c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
190
+ * d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
191
+
192
+ A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
193
+ 6. Conveying Non-Source Forms.
194
+
195
+ You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
196
+
197
+ * a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
198
+ * b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corre through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
199
+
200
+ If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
201
+
202
+ A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
203
+
204
+ Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
205
+ 12. No Surrender of Others' Freedom.
206
+
207
+ If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
208
+ 13. Use with the GNU Affero General Public License.
209
+
210
+ Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such.
211
+ 14. Revised Versions of this License.
212
+
213
+ The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
214
+
215
+ Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by authorizes you to choose that version for the Program.
216
+
217
+ Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
218
+ 15. Disclaimer of Warranty.
219
+
220
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
221
+ 16. Limitation of Liability.
222
+
223
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
224
+ 17. Interpretation of Sections 15 and 16.
225
+
226
+ If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
227
+
228
+ END OF TERMS AND CONDITIONS
229
+ How to Apply These Terms to Your New Programs
230
+
231
+ If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
232
+
233
+ To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found.
234
+
235
+ <one line to give the program's name and a brief idea of what it does.>
236
+ Copyright (C) <year> <name of author>
237
+
238
+ This program is free software: you can redistribute it and/or modify
239
+ it under the terms of the GNU General Public License as published by
240
+ the Free Software Foundation, either version 3 of the License, or
241
+ (at your option) any later version.
242
+
243
+ This program is distributed in the hope that it will be useful,
244
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
245
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
246
+ GNU General Public License for more details.
247
+
248
+ You should have received a copy of the GNU General Public License
249
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
250
+
251
+ Also add information on how to contact you by electronic and paper mail.
252
+
253
+ If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode:
254
+
255
+ <program> Copyright (C) <year> <name of author>
256
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
257
+ This is free software, and you are welcome to redistribute it
258
+ under certain conditions; type `show c' for details.
259
+
260
+ The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an “about box”.
261
+
262
+ You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information ow to apply and follow the GNU GPL, see <http://www.gnu.org/licenses/>.
263
+
264
+ The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read <http://www.gnu.org/philosophy/why-not-lgpl.html>.
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/whotowho.rb'
6
+
7
+ Hoe.new('whotowho', Whotowho::VERSION) do |p|
8
+ p.rubyforge_name = 'whotowho'
9
+ p.author = 'cyril mougel'
10
+ p.email = 'cyril.mougel@gmail.com'
11
+ p.summary = 'Define a person for another person and send by email Who to Who'
12
+ # p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
13
+ p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
14
+ p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
15
+ p.extra_deps << ['actionmailer', '>= 1.3.5']
16
+ end
17
+
18
+ # vim: syntax=Ruby
data/bin/whotowho ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'whotowho'
4
+
5
+ args = ParseArgs.new
6
+ args.parse ARGV, $0
7
+ Whotowho.new(args).send
@@ -0,0 +1,7 @@
1
+ :address: Allows you to use a remote mail server. Just change it from its default "localhost" setting.
2
+ :port: On the off chance that your mail server doesn‘t run on port 25, you can change it.
3
+ :domain: If you need to specify a HELO domain, you can do it here.
4
+ :user_name: If your mail server requires authentication, set the username in this setting.
5
+ :password: If your mail server requires authentication, set the password in this setting.
6
+ :authentication: If your mail server requires authentication, you need to specify the authentication type here. This is a symbol and one of :plain, :login, :cram_md5
7
+ :from: Define the email who send all mail in from header
@@ -0,0 +1,8 @@
1
+ - - un
2
+ - email_un
3
+ - - deux
4
+ - email_deux
5
+ - - trois
6
+ - email_trois
7
+ - - quatre
8
+ - email_quatre
@@ -0,0 +1,5 @@
1
+
2
+ This mail is send by WhoToWho. So
3
+
4
+ #{who} who is the name of receiv email. So he need made something to #{towho}
5
+ the name of other person.
data/conf.yaml ADDED
@@ -0,0 +1,7 @@
1
+ :address: "smtp.gmail.com"
2
+ :port: 587
3
+ :user_name: "cyril.mougel@gmail.com"
4
+ :password: "c03m13e05"
5
+ :authentication: :plain
6
+ :from: "shingara@gmail.com"
7
+
data/data.yaml ADDED
@@ -0,0 +1,8 @@
1
+ - - un
2
+ - cyril.mougel@gmail.com
3
+ - - deux
4
+ - shingara@gmail.com
5
+ - - trois
6
+ - cyril.mougel@gmail.com
7
+ - - quatre
8
+ - shingara@gmail.com
@@ -0,0 +1,12 @@
1
+
2
+ # Class for link an email to a name
3
+ class Link
4
+
5
+ attr_reader :name
6
+ attr_reader :email
7
+
8
+ def initialize(name, email)
9
+ @name = name
10
+ @email = email
11
+ end
12
+ end
@@ -0,0 +1,118 @@
1
+ require 'yaml'
2
+ require 'optparse'
3
+
4
+ # Class for parse Args and save all into
5
+ class ParseArgs
6
+
7
+ attr_reader :verbose
8
+ attr_reader :subject
9
+ attr_reader :content
10
+ attr_reader :from
11
+
12
+ # Parse all argument and check if required is define
13
+ def parse(args, prog)
14
+ options = OptionParser.new do |opts|
15
+
16
+ opts.banner = "Usage: #{prog} [options]"
17
+
18
+ opts.on("-v", "--verbose", "Run verbosely") do |v|
19
+ @verbose = true
20
+ end
21
+ opts.on( '-f', '--file REQUIRED', :REQUIRED, 'File where is all data') do |f|
22
+ load_file f
23
+ end
24
+ opts.on('-c', '--config FILE', :REQUIRED, 'File where is all config') do |f|
25
+ load_config f
26
+ end
27
+ opts.on('-g', '--gmail', 'Define option if use a Gmail account for SMTP') do |g|
28
+ require_dependency('whotowho/smtp_tls') if g
29
+ end
30
+ opts.on('-s', '--subject SUBJECT', :REQUIRED, 'Define the subject to send by email') do |s|
31
+ @subject = s
32
+ end
33
+ opts.on('-m FILE', '--mail MAIL', :REQUIRED, 'Send a file where the content is with 2 params #{who} and #{towho}') do |c|
34
+ @content = File.open(c).read
35
+ end
36
+
37
+ @full_print = opts
38
+
39
+ end.parse!
40
+ test_required
41
+ end
42
+
43
+
44
+ # Send a random Link objet from list_link save into
45
+ def put_random
46
+ rand_index = rand(@list_link.size)
47
+ @list_link.slice!(rand_index)
48
+ end
49
+
50
+ # Size of list_link in args
51
+ def size
52
+ @list_link.size
53
+ end
54
+
55
+
56
+ # Send a random Link objet from list_link save into
57
+ def put_random
58
+ rand_index = rand(@list_link.size)
59
+ @list_link.slice!(rand_index)
60
+ end
61
+
62
+ # Size of list_link in args
63
+ def size
64
+ @list_link.size
65
+ end
66
+
67
+ private
68
+
69
+ # Load the file with format to YAML in list_link attribute
70
+ def load_file(f)
71
+ @list_link = []
72
+ YAML.load_file(f).each { |e|
73
+ @list_link << Link.new(e[0], e[1])
74
+ }
75
+ end
76
+
77
+ # Load the file like a smtp config for actionMailer
78
+ def load_config(f)
79
+ conf_hash = YAML.load_file f
80
+ ActionMailer::Base.smtp_settings = conf_hash
81
+ @from = conf_hash[:from]
82
+ end
83
+
84
+ # Test if all argument required is define
85
+ def test_required
86
+ required = true
87
+ if @subject.nil? || @subject.empty?
88
+ puts 'you need define a subject'
89
+ required = false
90
+ end
91
+
92
+ if @content.nil? || @content.empty?
93
+ puts 'you need define a file or a file not empty for you mail template'
94
+ required = false
95
+ end
96
+
97
+ if @list_link.nil? || @list_link.empty? || @list_link.size < 2
98
+ puts 'The list of data need define by a file. This file can\'t be empty or only one data'
99
+ required = false
100
+ end
101
+
102
+ if ActionMailer::Base.smtp_settings.empty?
103
+ puts 'The configuration of your SMTP account can\'t be empty'
104
+ required = false
105
+ end
106
+
107
+ if @from.nil? || @from.empty?
108
+ puts 'You need define a from in your mail settings.'
109
+ required = false
110
+ end
111
+
112
+ unless required
113
+ puts @full_print
114
+ exit
115
+ end
116
+ end
117
+
118
+ end
@@ -0,0 +1,15 @@
1
+ require 'action_mailer'
2
+
3
+ # Made the send mail
4
+ class SendMail < ActionMailer::Base
5
+
6
+ # Send a mail with information send by args
7
+ # args is a ParseArgs Object
8
+ def send_mail(name, email, name_receiv, args)
9
+ recipients email
10
+ from args.from
11
+ subject args.subject
12
+ body(args.content.gsub(/\#\{who\}/, name_receiv).gsub(/\#\{towho\}/, name))
13
+ end
14
+
15
+ end
@@ -0,0 +1,69 @@
1
+ # This code is done by
2
+ # http://www.stephenchu.com/2006/06/how-to-use-gmail-smtp-server-to-send.html
3
+ # This file is required for a gmail account in smtp
4
+
5
+ require "openssl"
6
+ require "net/smtp"
7
+
8
+ Net::SMTP.class_eval do
9
+ private
10
+ def do_start(helodomain, user, secret, authtype)
11
+ raise IOError, 'SMTP session already started' if @started
12
+ check_auth_args user, secret, authtype if user or secret
13
+
14
+ sock = timeout(@open_timeout) { TCPSocket.open(@address, @port) }
15
+ @socket = Net::InternetMessageIO.new(sock)
16
+ @socket.read_timeout = 60 #@read_timeout
17
+ @socket.debug_output = STDERR #@debug_output
18
+
19
+ check_response(critical { recv_response() })
20
+ do_helo(helodomain)
21
+
22
+ raise 'openssl library not installed' unless defined?(OpenSSL)
23
+ starttls
24
+ ssl = OpenSSL::SSL::SSLSocket.new(sock)
25
+ ssl.sync_close = true
26
+ ssl.connect
27
+ @socket = Net::InternetMessageIO.new(ssl)
28
+ @socket.read_timeout = 60 #@read_timeout
29
+ @socket.debug_output = STDERR #@debug_output
30
+ do_helo(helodomain)
31
+
32
+ authenticate user, secret, authtype if user
33
+ @started = true
34
+ ensure
35
+ unless @started
36
+ # authentication failed, cancel connection.
37
+ @socket.close if not @started and @socket and not @socket.closed?
38
+ @socket = nil
39
+ end
40
+ end
41
+
42
+ def do_helo(helodomain)
43
+ begin
44
+ if @esmtp
45
+ ehlo helodomain
46
+ else
47
+ helo helodomain
48
+ end
49
+ rescue Net::ProtocolError
50
+ if @esmtp
51
+ @esmtp = false
52
+ @error_occured = false
53
+ retry
54
+ end
55
+ raise
56
+ end
57
+ end
58
+
59
+ def starttls
60
+ getok('STARTTLS')
61
+ end
62
+
63
+ def quit
64
+ begin
65
+ getok('QUIT')
66
+ rescue EOFError
67
+ end
68
+ end
69
+ end
data/lib/whotowho.rb ADDED
@@ -0,0 +1,31 @@
1
+ require 'whotowho/sendmail'
2
+ require 'whotowho/link'
3
+ require 'whotowho/parseargs'
4
+
5
+ # Manage the separation and assign all who to who
6
+ class Whotowho
7
+
8
+ VERSION = "0.1.0"
9
+ # init with an ParseArgs Object
10
+ def initialize(args)
11
+ @args = args
12
+ end
13
+
14
+ # made the random in list of Link and
15
+ # send a mail to all person
16
+ def send
17
+ first = @args.put_random
18
+ first_name = first.name
19
+ email = first.email
20
+ name_receiv = first.name
21
+ list_mail = []
22
+ while @args.size > 0 do
23
+ tmp = @args.put_random
24
+ SendMail.deliver_send_mail(tmp.name, email, name_receiv, @args)
25
+ email = tmp.email
26
+ name_receiv = tmp.name
27
+ end
28
+
29
+ SendMail.deliver_send_mail(first_name, email, name_receiv, @args)
30
+ end
31
+ end
File without changes
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.4
3
+ specification_version: 1
4
+ name: whotowho
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.1.0
7
+ date: 2007-11-22 00:00:00 +01:00
8
+ summary: Define a person for another person and send by email Who to Who
9
+ require_paths:
10
+ - lib
11
+ email: cyril.mougel@gmail.com
12
+ homepage:
13
+ rubyforge_project: whotowho
14
+ description: The author was too lazy to write a description
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - cyril mougel
31
+ files:
32
+ - History.txt
33
+ - Manifest.txt
34
+ - README.txt
35
+ - Rakefile
36
+ - bin/whotowho
37
+ - conf.yaml
38
+ - conf/conf.yaml.example
39
+ - conf/data.yaml.example
40
+ - conf/mail-example.txt
41
+ - data.yaml
42
+ - lib/whotowho.rb
43
+ - lib/whotowho/link.rb
44
+ - lib/whotowho/parseargs.rb
45
+ - lib/whotowho/sendmail.rb
46
+ - lib/whotowho/smtp_tls.rb
47
+ - test/test_whotowho.rb
48
+ test_files:
49
+ - test/test_whotowho.rb
50
+ rdoc_options:
51
+ - --main
52
+ - README.txt
53
+ extra_rdoc_files:
54
+ - History.txt
55
+ - Manifest.txt
56
+ - README.txt
57
+ - conf/mail-example.txt
58
+ executables:
59
+ - whotowho
60
+ extensions: []
61
+
62
+ requirements: []
63
+
64
+ dependencies:
65
+ - !ruby/object:Gem::Dependency
66
+ name: actionmailer
67
+ version_requirement:
68
+ version_requirements: !ruby/object:Gem::Version::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 1.3.5
73
+ version:
74
+ - !ruby/object:Gem::Dependency
75
+ name: hoe
76
+ version_requirement:
77
+ version_requirements: !ruby/object:Gem::Version::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: 1.2.2
82
+ version: