fcoury-gmail_sender 0.1.0 → 0.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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/bin/gmail ADDED
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.join(File.dirname(__FILE__), "..", "lib")
4
+
5
+ require 'rubygems'
6
+ require 'lib/gmail_sender'
7
+ require 'choice'
8
+
9
+ Choice.options do
10
+ header ''
11
+ header 'options:'
12
+
13
+ option :to, :required => true do
14
+ short '-t'
15
+ long '--to=RECEIVER'
16
+ desc 'Receiver of the email'
17
+ end
18
+
19
+ option :subject, :required => true do
20
+ short '-s'
21
+ long '--subject=SUBJECT'
22
+ desc 'Subject of the email'
23
+ end
24
+
25
+ option :content do
26
+ short '-c'
27
+ long '--content=MAIL_CONTENTS'
28
+ desc 'Body of the email, uses STDIN of omitted'
29
+ end
30
+ end
31
+
32
+ def read_config
33
+ config = {}
34
+ group = nil
35
+ File.foreach("#{ENV['HOME']}/.gmail") do |line|
36
+ line.strip!
37
+ if line[0] != ?# and line =~ /\S/
38
+ if line =~ /^\[(.*)\]$/
39
+ group = $1
40
+ else
41
+ key, value = line.split("=")
42
+ value ||= ''
43
+ (config[group]||={})[key.strip] = value.strip
44
+ end
45
+ end
46
+ end
47
+ config
48
+ end
49
+
50
+ config = read_config['account']
51
+ mailer = Gmail::Emailer.new(config['user'], config['password'], config['domain'])
52
+ mailer.send(Choice.choices[:to], Choice.choices[:subject], Choice.choices[:content] || STDIN.read)
data/gmail_sender.gemspec CHANGED
@@ -2,12 +2,13 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{gmail_sender}
5
- s.version = "0.1.0"
5
+ s.version = "0.1.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Daniel Cadenas"]
8
+ s.authors = ["Daniel Cadenas", "Felipe Coury"]
9
9
  s.date = %q{2009-05-25}
10
- s.email = %q{dcadenas@gmail.com}
10
+ s.email = %q{dcadenas@gmail.com felipe.coury@gmail.com}
11
+ s.executables = ["gmail"]
11
12
  s.extra_rdoc_files = [
12
13
  "LICENSE",
13
14
  "README.rdoc"
@@ -20,6 +21,7 @@ Gem::Specification.new do |s|
20
21
  "Rakefile",
21
22
  "VERSION",
22
23
  "gmail_sender.gemspec",
24
+ "bin/gmail",
23
25
  "lib/gmail_sender.rb",
24
26
  "lib/tls_smtp_patch.rb",
25
27
  "test/gmail_sender_test.rb",
@@ -40,6 +42,7 @@ Gem::Specification.new do |s|
40
42
  s.specification_version = 3
41
43
 
42
44
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
45
+ s.add_runtime_dependency(%q<choice>, [">= 0"])
43
46
  else
44
47
  end
45
48
  else
data/lib/gmail_sender.rb CHANGED
@@ -1,21 +1,23 @@
1
1
  require "tls_smtp_patch"
2
2
 
3
- class GmailSender
4
- def initialize(gmail_user, gmail_password)
5
- @gmail_user = "#{gmail_user}@gmail.com"
6
- @gmail_password = gmail_password
7
- @net_smtp = Net::SMTP.new("smtp.gmail.com", 587)
8
- @net_smtp.enable_starttls
9
- end
3
+ module Gmail
4
+ class Emailer
5
+ def initialize(user, password, domain="gmail.com")
6
+ @domain = domain
7
+ @password = password
8
+ @user = "#{user}@#{domain}"
9
+ @net_smtp = Net::SMTP.new("smtp.gmail.com", 587)
10
+ @net_smtp.enable_starttls
11
+ end
10
12
 
11
- def send(to, subject, content)
12
- @net_smtp.start("gmail.com", @gmail_user, @gmail_password, :plain) do |smtp|
13
- msg = create_message(to, subject, content)
14
- smtp.send_message(msg, @gmail_user, to)
13
+ def send(to, subject, content)
14
+ @net_smtp.start(@domain, @user, @password, :plain) do |smtp|
15
+ msg = create_message(to, subject, content)
16
+ smtp.send_message(msg, @user, to)
17
+ end
15
18
  end
16
- end
17
19
 
18
- def create_message(to, subject, content)
20
+ def create_message(to, subject, content)
19
21
  <<MSG
20
22
  From: #@gmail_user
21
23
  To: #{to}
@@ -23,6 +25,6 @@ Subject: #{subject}
23
25
 
24
26
  #{content}
25
27
  MSG
28
+ end
26
29
  end
27
30
  end
28
-
@@ -1,6 +1,6 @@
1
1
  require "net/smtp"
2
2
 
3
- if !Net::SMTP.instance_methods.include?(:enable_starttls)
3
+ unless Net::SMTP.instance_methods.include?(:enable_starttls)
4
4
  require "tlsmail"
5
5
  class Net::SMTP
6
6
  def enable_starttls
metadata CHANGED
@@ -1,22 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fcoury-gmail_sender
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Cadenas
8
+ - Felipe Coury
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
12
 
12
13
  date: 2009-05-25 00:00:00 -07:00
13
14
  default_executable:
14
- dependencies: []
15
-
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: choice
18
+ type: :runtime
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ version:
16
26
  description:
17
- email: dcadenas@gmail.com
18
- executables: []
19
-
27
+ email: dcadenas@gmail.com felipe.coury@gmail.com
28
+ executables:
29
+ - gmail
20
30
  extensions: []
21
31
 
22
32
  extra_rdoc_files:
@@ -30,6 +40,7 @@ files:
30
40
  - Rakefile
31
41
  - VERSION
32
42
  - gmail_sender.gemspec
43
+ - bin/gmail
33
44
  - lib/gmail_sender.rb
34
45
  - lib/tls_smtp_patch.rb
35
46
  - test/gmail_sender_test.rb