send 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/send +51 -24
  3. metadata +3 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9101a3b191750a71e4f1cd319b8e6bad57feaae
4
- data.tar.gz: cbf2a74084c94718cfd06d903789ad27cb203cfd
3
+ metadata.gz: 332584d658789e426d4b0465522d12c0a66be5fe
4
+ data.tar.gz: f4650323611b761496e26b1f033f3b6ea9097792
5
5
  SHA512:
6
- metadata.gz: 71f47464390a7cb188738b2d01d215ead2ce5b0a2e702330896685d7decf7815d981fa519f522097f12819e581c6d0be367d2cde27f04d41e458ab1cb3a61387
7
- data.tar.gz: 04cfc9f5ddbdd13ce507557fa2cb95f902961f6e98957a009dacf9c3e25ca3a28f0129292cb36d19ebecc3de5db70e7adec63872901947050bafcc7c0686ee5b
6
+ metadata.gz: b1f2996c493bf0b1b1b58c9409fc195b2474137c03558e088ebd593a81ae09ce8765d4a5d3f5bd90156c1ef029c62f54687ed18195fe5fa9d173cf3835690e8f
7
+ data.tar.gz: fb0d185124fd57ae31184572b9226b1169c6189647af39d6f2b5d173861ad52aee8c2d65a9776fa189d23390a872cdb1402d33f9c8c796c56d8a982018fc62df
data/bin/send CHANGED
@@ -1,24 +1,56 @@
1
- #!/usr/bin/ruby
1
+ #!/usr/bin/env ruby
2
2
 
3
3
  require 'mail'
4
4
  require 'optparse'
5
5
  require 'ostruct'
6
+ require 'io/console'
7
+ require 'base64'
6
8
 
7
9
  # Send mail via Command line
8
- # This will save your defaults as environment variables so that you do
10
+ # This will save your defaults as environment variables so that you do
9
11
  # not have to constantly add them
10
12
  # I mainly use this for testing email on different browsers
11
13
 
14
+ OPTIONS = OpenStruct.new
15
+ CONFIG_FNAME = "#{ENV['HOME']}/.send"
16
+
17
+ def read_config
18
+ if File.file? CONFIG_FNAME
19
+ f = open(CONFIG_FNAME)
20
+ contents = Base64.decode64(f.read)
21
+ OPTIONS.from = contents.match(/^from=(.*)$/)[1]
22
+ OPTIONS.to = contents.match(/^to=(.*)$/)[1]
23
+ OPTIONS.password = contents.match(/^password=(.*)$/)[1]
24
+ f.close
25
+ end
26
+ end
27
+
28
+ def write_config
29
+ contents = ''
30
+ contents << "from=#{OPTIONS.from}\n"
31
+ contents << "to=#{OPTIONS.to}\n"
32
+ contents << "password=#{OPTIONS.password}"
33
+ f = open(CONFIG_FNAME, 'w')
34
+ f.write(Base64.encode64(contents))
35
+ f.close
36
+ end
37
+
38
+ def export
39
+ puts "What is your gmail email? "
40
+ OPTIONS.from = gets.chomp
41
+ puts "What is your gmail password? "
42
+ OPTIONS.password = STDIN.noecho(&:gets).chomp
43
+ puts "Who should we send the email to by default? "
44
+ OPTIONS.to = gets.chomp
45
+ write_config
46
+ end
12
47
 
13
- options = OpenStruct.new
14
48
  ran = rand(1000)
15
- options.subject = "This is a test email - #{ran}"
49
+ OPTIONS.subject = "This is a test email - #{ran}"
16
50
 
17
51
  # Get following defaults from environment variables
18
52
  # You can set them with EXPORT
19
- options.from = ENV['send_from']
20
- options.to = ENV['send_to']
21
- options.password = ENV['send_password']
53
+ read_config
22
54
 
23
55
  opt_parser = OptionParser.new do |opt|
24
56
  opt.banner = "Usage: send FILE TO"
@@ -26,25 +58,20 @@ opt_parser = OptionParser.new do |opt|
26
58
  opt.separator "Options"
27
59
 
28
60
  opt.on("-x","--export","Export Environment Virables") do
29
- puts "What is your gmail email? "
30
- system "export send_from=" + gets.chomp
31
- puts "What is your gmail password? "
32
- system "export send_password=" + gets.chomp
33
- puts "Who should we send the email to by default? "
34
- system "export send_to=" + gets.chomp
61
+ export
35
62
  exit 0
36
63
  end
37
64
 
38
65
  opt.on("-f","--from","Your email address") do |from|
39
- options.from = from
66
+ OPTIONS.from = from
40
67
  end
41
68
 
42
69
  opt.on("-s","--subject","Email Subject") do |subject|
43
- options.subject = subject
70
+ OPTIONS.subject = subject
44
71
  end
45
72
 
46
73
  opt.on("-t","--to","Email address to send to") do |to|
47
- options.from = from
74
+ OPTIONS.from = from
48
75
  end
49
76
 
50
77
  opt.on("-h","--help","help") do
@@ -64,30 +91,30 @@ rescue
64
91
  exit 1
65
92
  end
66
93
  if ARGV[1] != nil
67
- options.to = ARGV[1]
94
+ OPTIONS.to = ARGV[1]
68
95
  end
69
96
 
70
97
  # Lets see if environment variable are set
71
- if options.from == nil || options.to == nil || options.password == nil
98
+ if OPTIONS.from == nil || OPTIONS.to == nil || OPTIONS.password == nil
72
99
  puts "Envronment Variables are not set. Please run send -x to set them"
73
100
  exit 1
74
101
  end
75
102
 
76
103
  Mail.defaults do
77
- delivery_method :smtp, {
104
+ delivery_method :smtp, {
78
105
  :address => 'smtp.gmail.com',
79
106
  :port => '587',
80
- :user_name => options.from,
81
- :password => options.password,
107
+ :user_name => OPTIONS.from,
108
+ :password => OPTIONS.password,
82
109
  :authentication => :plain,
83
110
  :enable_starttls_auto => true
84
111
  }
85
112
  end
86
113
 
87
114
  mail = Mail.new do
88
- from options.from
89
- to options.to
90
- subject options.subject
115
+ from OPTIONS.from
116
+ to OPTIONS.to
117
+ subject OPTIONS.subject
91
118
  end
92
119
 
93
120
 
metadata CHANGED
@@ -1,29 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: send
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Revell
8
+ - Emanuel Evans
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
12
  date: 2013-06-08 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: mail
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - '>='
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - '>='
25
- - !ruby/object:Gem::Version
26
- version: '0'
13
+ dependencies: []
27
14
  description: Send mail via cli
28
15
  email: mikearevell@gmail.com
29
16
  executables: