sgmailer 1.0.1 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/bin/sgmailer +13 -5
  2. data/lib/sgmailer.rb +119 -11
  3. metadata +2 -2
@@ -3,15 +3,23 @@ first_rg = ARGV[0]
3
3
 
4
4
  if (first_rg == "generate")
5
5
  puts SGmailer.generate(ARGV[1], ARGV[2], ARGV)
6
+ elsif (first_rg == "cleanup")
7
+ puts SGmailer.cleanup
6
8
  elsif (first_rg == "--help")
7
9
  puts "Commands:"
8
- puts "sgmailer generate [username] [password] ([flags])"
10
+ puts "sgmailer generate [username] [password] ([args]) ([flags])"
9
11
  puts "\tusername: your gmail username"
10
12
  puts "\tpassword: your gmail password"
11
- puts "\tflags:\n\t\t--no-plain: Do not include plain-text template in email"
12
- puts "\n\t\t--no-html: Do not include HTML template in email"
13
- puts "\n\t\t--no-message: Do not include a message field, but rather a default template"
14
- puts "\n\n\tTo send an email, in your controller use: SGmailer.send_email(to-address, subject, email-message)"
13
+ puts "\t[args] - name for arguments to pass in that will be viewed on the email message. Optional. If not included, will only have 'message' parameter"
14
+ puts "\n\tflags:\n\t\t--no-plain: Do not include plain-text template in email"
15
+ puts "\t\t--no-html: Do not include HTML template in email"
16
+ puts "\t\t--no-message: Do not include a message field, but rather a default template"
17
+ puts "\t\t--isolate-password: Put the password file in a seperate file and add it to .gitignore"
18
+
19
+ puts "\n\n\sgmailer cleanup"
20
+ puts "\tDeletes all your mail files for you so you can re-generate the code"
21
+ puts "\tWARNING: This will permanetly delete your mailer files. Any saved changes will be deleted"
22
+ puts "\n\n\tTo send an email, in your controller use: SGmailer.send_email(to-address, subject, parameters[..])"
15
23
  else
16
24
  puts "Error, unrecognized command. Please type in 'sgmailer --help' for help."
17
25
  end
@@ -1,3 +1,5 @@
1
+ require 'fileutils'
2
+
1
3
  class SGmailer
2
4
  def self.generate username, password, args
3
5
 
@@ -21,6 +23,32 @@ class SGmailer
21
23
 
22
24
  puts "\tModified config/environment.rb"
23
25
 
26
+ #Check to see if we want to put the password in a seperate file
27
+ if (helper.arg_exists? "--isolate-password")
28
+ file = File.open("config/password.psw", "w")
29
+ file.puts password
30
+ file.close
31
+ puts "\tWrote password to seperate file"
32
+
33
+ ex = false
34
+ if (File.exists? ".gitignore")
35
+ file = File.open(".gitignore", "r")
36
+ file.each do |line|
37
+ if line.include? "*.psw"
38
+ ex = true
39
+ end
40
+ end
41
+
42
+ if (ex == false)
43
+ file = File.open(".gitignore", "a")
44
+ file.puts "\n\n# Ignore email password file"
45
+ file.puts "/config/*.psw"
46
+ file.close
47
+ puts "\tUpdated gitignore file to not include password file"
48
+ end
49
+ end
50
+ end
51
+
24
52
  #Generate file for mailer
25
53
  if (!File.directory? "app/mailers")
26
54
  Dir.mkdir("app/mailers", 755)
@@ -56,15 +84,48 @@ class SGmailer
56
84
  puts "\nComplete! Edit the email scaffolds with your email (and dynamic text)."
57
85
  extra = ""
58
86
  if !helper.arg_exists?("--no-message")
59
- extra = ", [message]"
87
+ helper.get_params.each do |a|
88
+ extra = extra + ", [" + a + "]"
89
+ end
60
90
  end
61
91
  puts "To send an email, in the controller use: SGmailer.send_email([to address], [subject]" + extra + ")"
92
+ if (helper.arg_exists?("--isolate-password"))
93
+ puts "IMPORTANT! You MUST copy over config/password.psw to any development or production instance, otherwise errors will occur. This file will not be included in your git repository."
94
+ end
62
95
 
63
96
  else
64
97
  puts "\tError. Please put your gmail username and password."
65
98
  end
99
+ end
100
+
101
+ def self.cleanup
102
+ #Environment
103
+ if !File.exists? "config/environment.rb"
104
+ puts "Please create a rails project that has an environment.rb file"
105
+ end
106
+
107
+ if File.exists? "config/password.psw"
108
+ File.delete "config/password.psw"
109
+ end
110
+
66
111
 
112
+ #Check for directory
113
+ if File.directory? "app/mailers"
114
+ if File.exists? "app/mailers/s_gmailer.rb"
115
+ File.delete "app/mailers/s_gmailer.rb"
116
+ puts "Deleted app/mailers/s_gmailer.rb"
117
+ end
118
+ end
119
+
120
+ #Check for templates
121
+ if ((File.exists? "app/views/s_gmailer/email_plain.html.erb") || (File.exists? "app/views/s_gmailer/email_html.html.erb"))
122
+ FileUtils.rm_rf('app/views/s_gmailer')
123
+ puts "Delted mailer views"
124
+ end
125
+
126
+ puts "Please check your config/environment.rb file and delete all SMTP and ActionMailer lines manually, if they exist."
67
127
  end
128
+
68
129
  end
69
130
 
70
131
  class SGmailer::Thingies
@@ -72,7 +133,19 @@ class SGmailer::Thingies
72
133
  def initialize(username, password, args)
73
134
  @username = username
74
135
  @password = password
75
- @args = args
136
+ @all_args = args
137
+
138
+ i = 3
139
+ a = args[i]
140
+ @args = []
141
+ while (a != nil && !a.include?("--"))
142
+ @args << a
143
+ i = i + 1
144
+ a = args[i]
145
+ end
146
+ if (@args.count == 0)
147
+ @args << "message"
148
+ end
76
149
  end
77
150
 
78
151
  def check_files?
@@ -93,6 +166,10 @@ class SGmailer::Thingies
93
166
  return false
94
167
  end
95
168
 
169
+ if File.exists? "config/password.psw"
170
+ return false
171
+ end
172
+
96
173
  #Check for directory
97
174
  if File.directory? "app/mailers"
98
175
  if File.exists? "app/mailers/s_gmailer.rb"
@@ -112,6 +189,10 @@ class SGmailer::Thingies
112
189
 
113
190
  def get_text(text)
114
191
  if (text == :environment)
192
+ psw = "\"" + @password + "\""
193
+ if (arg_exists? "--isolate-password")
194
+ psw = "psw"
195
+ end
115
196
  "
116
197
 
117
198
  ActionMailer::Base.delivery_method = :smtp
@@ -119,27 +200,38 @@ ActionMailer::Base.delivery_method = :smtp
119
200
  ActionMailer::Base.raise_delivery_errors = true
120
201
  ActionMailer::Base.perform_deliveries = true
121
202
 
203
+ psw = \"\"
204
+ if File.exists?(\"config/password.psw\")
205
+ file = File.open(\"config/password.psw\", \"r\")
206
+ psw = file.gets
207
+ file.close
208
+ end
209
+
122
210
  ActionMailer::Base.smtp_settings = {
123
211
  :address => \"smtp.gmail.com\",
124
212
  :port => 587,
125
213
  :authentication => :plain,
126
214
  :user_name => \"" + @username + "\",
127
- :password => \"" + @password + "\",
215
+ :password => " + psw + ",
128
216
  :enable_starttls_auto => true,
129
217
  :openssl_verify_mode => \"none\"
130
218
  }"
131
-
219
+
132
220
  elsif (text == :emailer)
133
221
  rt = "class SGmailer < ActionMailer::Base
134
222
  default :from => \"#{@username}\"
135
223
  def email(recipient, subject"
136
224
  if !arg_exists? "--no-message"
137
- rt = rt + ", message"
225
+ @args.each do |a|
226
+ rt = rt + ", " + a
227
+ end
138
228
  end
139
229
  rt = rt + ")
140
230
  "
141
231
  if !arg_exists? "--no-message"
142
- rt = rt + "@message = message\n"
232
+ @args.each do |a|
233
+ rt = rt + "\t@" + a + " = " + a + "\n"
234
+ end
143
235
  end
144
236
  rt = rt + " mail(:to => recipient, :subject => subject) do |format|
145
237
  "
@@ -154,12 +246,16 @@ ActionMailer::Base.smtp_settings = {
154
246
 
155
247
  def send_email(recipient, subject"
156
248
  if !arg_exists?("--no-message")
157
- rt = rt + ", message"
249
+ @args.each do |a|
250
+ rt = rt + ", " + a
251
+ end
158
252
  end
159
253
  rt = rt +")
160
254
  self.email(recipient, subject"
161
255
  if !arg_exists?("--no-message")
162
- rt = rt + ", message"
256
+ @args.each do |a|
257
+ rt = rt + ", " + a
258
+ end
163
259
  end
164
260
  rt = rt + ").deliver
165
261
  end
@@ -174,7 +270,11 @@ end"
174
270
 
175
271
  YIPPEEE!!!!"
176
272
  else
177
- "<%= @message %>"
273
+ rtn = ""
274
+ @args.each do |a|
275
+ rtn = rtn + a + ":\n<%= @" + a + " %>\n\n"
276
+ end
277
+ return rtn
178
278
  end
179
279
 
180
280
  elsif (text == :html)
@@ -184,18 +284,26 @@ end"
184
284
 
185
285
  YIPEEEEE!!!!"
186
286
  else
187
- "<pre><%= @message %></pre>"
287
+ rtn = ""
288
+ @args.each do |a|
289
+ rtn = rtn + "<b>" + a + ":</b><br/>\n<pre><%= @" + a + " %></pre><br/><br/>\n\n"
290
+ end
291
+ return rtn
188
292
  end
189
293
  end
190
294
  end
191
295
 
192
296
 
193
297
  def arg_exists? cmd
194
- @args.each do |a|
298
+ @all_args.each do |a|
195
299
  if a == cmd
196
300
  return true
197
301
  end
198
302
  end
199
303
  false
200
304
  end
305
+
306
+ def get_params
307
+ @args
308
+ end
201
309
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sgmailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-02 00:00:00.000000000 Z
12
+ date: 2012-11-09 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Allows developers to send simple emails through GMail in Ruby on Rails
15
15
  email: nolanblew@hotmail.com