simpleMailer 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ Copyright (c) 2009 Yoann LE TOUCHE
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ Except as contained in this notice, the name(s) of the above copyright
15
+ holders shall not be used in advertising or otherwise to promote the
16
+ sale, use or other dealings in this Software without prior written
17
+ authorization.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,43 @@
1
+ = simpleMailer
2
+
3
+ SimpleMailer is a very simple wrapper for Ruby's net::smtp
4
+
5
+ == Usage
6
+
7
+ require "rubygems"
8
+ require "simpleMailer"
9
+
10
+ mail=SimpleMailer.new("some.smtp.com",port=25)
11
+ mail.to("foo@bar.com")
12
+ mail.from("simple@mailer.com")
13
+ mail.with_title("That's some title for you")
14
+ mail.message("Later you will be able to use HTML")
15
+ mail.with_files(["/tmp/awesome.file","~/archive.tbz2"])
16
+ mail.send # Nothing is really done before this point
17
+
18
+ But you could have :
19
+
20
+ mail.to("foo@bar").from("foo@bar").with_title("title").message("message").send
21
+
22
+ == Testing
23
+
24
+ No testing right now, but I will work on it for a future version
25
+
26
+ == Note on Patches/Pull Requests
27
+
28
+ * Fork the project.
29
+ * Make your feature addition or bug fix.
30
+ * Add tests for it. This is important so I don't break it in a
31
+ future version unintentionally.
32
+ * Commit, do not mess with rakefile, version, or history.
33
+ (if you want to have your own version, that is fine but
34
+ bump version in a commit by itself I can ignore when I pull)
35
+ * Send me a pull request. Bonus points for topic branches.
36
+
37
+ == Thanks
38
+
39
+ Thanks to *technicalpickles* for his awesome gem *Jeweler*
40
+
41
+ == Copyright
42
+
43
+ Copyright (c) 2009 Yoann LE TOUCHE. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,57 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "simpleMailer"
8
+ gem.summary = %Q{A simple mailer gem}
9
+ gem.description = %Q{SimpleMailer is a simple wrapper for net::smtp that let you attach files}
10
+ gem.email = "kurotoshiro@gmail.com"
11
+ gem.homepage = "http://github.com/Kurotoshiro/simpleMailer"
12
+ gem.authors = ["Yoann LE TOUCHE"]
13
+ gem.add_dependency "shared-mime-info"
14
+ gem.add_development_dependency "thoughtbot-shoulda"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/*_test.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/*_test.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ if File.exist?('VERSION')
48
+ version = File.read('VERSION')
49
+ else
50
+ version = ""
51
+ end
52
+
53
+ rdoc.rdoc_dir = 'rdoc'
54
+ rdoc.title = "simpleMailer #{version}"
55
+ rdoc.rdoc_files.include('README*')
56
+ rdoc.rdoc_files.include('lib/**/*.rb')
57
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.5
@@ -0,0 +1,111 @@
1
+ class SimpleMailer
2
+ require 'base64'
3
+ require 'net/smtp'
4
+ require 'shared-mime-info'
5
+
6
+ attr_accessor :host, :port
7
+ attr_accessor :from, :to
8
+ attr_accessor :title, :message
9
+ attr_accessor :files
10
+
11
+ MARKER="THATSMAMARKER"
12
+
13
+ def initialize(host="",port=25)
14
+ @host=host
15
+ @port=port
16
+ @from=""
17
+ @to=""
18
+ @title=""
19
+ @message=""
20
+ @files=Array.new
21
+ @body=""
22
+ end
23
+
24
+ def to(to)
25
+ raise "Not a proper email address" unless to.match(/.+@.+\..+/)
26
+ @to=to
27
+ self
28
+ end
29
+
30
+ def from(from)
31
+ raise "Not a proper email address" unless from.match(/.+@.+\..+/)
32
+ @from=from
33
+ self
34
+ end
35
+
36
+ def with_title(title)
37
+ @title=title
38
+ self
39
+ end
40
+
41
+ def message(message)
42
+ @message=message
43
+ self
44
+ end
45
+
46
+ # WARNING : with_files clear @files before adding new ones
47
+ def with_files(files)
48
+ @files=Array.new
49
+ files.each do |file|
50
+ raise "File #{file} doesn't exist" unless File.exists?(file)
51
+ raise "Can't read file #{file}" unless File.readable?(file)
52
+ @files<<file
53
+ end
54
+ self
55
+ end
56
+
57
+ def generate_file_part(file)
58
+ b64file=String.new
59
+ filename=File.basename(file)
60
+ part=String.new
61
+ File.open(file) do |f|
62
+ b64file=Base64.b64encode(f.read)
63
+ end
64
+ part =<<EOF
65
+ --#{MARKER}
66
+ Content-Disposition: attachment; filename="#{filename}"
67
+ Content-Type: #{MIME::check(file).to_s}; name="#{filename}"
68
+ Content-Transfer-Encoding: base64
69
+
70
+ #{b64file}
71
+
72
+
73
+ EOF
74
+ end
75
+
76
+ # TODO: Get information and format them to create a multipart message
77
+ def generate_body
78
+ @body =<<EOF
79
+ From: #{@from}
80
+ To: #{@to}
81
+ Subject: #{@title}
82
+ MIME-Version: 1.0
83
+ Content-Type: multipart/mixed; boundary=#{MARKER}
84
+ --#{MARKER}
85
+ Content-Type: text/plain
86
+ Content-Transfer-Encoding:8bit
87
+
88
+ #{@message}
89
+
90
+ EOF
91
+ # Time to process our files
92
+ @files.each do |file|
93
+ @body+=generate_file_part(file)
94
+ end
95
+ @body+="--#{MARKER}--"
96
+ return true
97
+ end
98
+
99
+ def send()
100
+ Net::SMTP.start(@host,@port) do |smtp|
101
+ begin
102
+ generate_body
103
+ smtp.send_message(@body,@from,@to)
104
+ return true
105
+ rescue => e
106
+ e
107
+ end
108
+ end
109
+ end
110
+
111
+ end
@@ -0,0 +1,56 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{simpleMailer}
8
+ s.version = "0.1.5"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Yoann LE TOUCHE"]
12
+ s.date = %q{2009-08-18}
13
+ s.description = %q{SimpleMailer is a simple wrapper for net::smtp that let you attach files}
14
+ s.email = %q{kurotoshiro@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/simpleMailer.rb",
27
+ "simpleMailer.gemspec",
28
+ "test/simpleMailer_test.rb",
29
+ "test/test_helper.rb"
30
+ ]
31
+ s.homepage = %q{http://github.com/Kurotoshiro/simpleMailer}
32
+ s.rdoc_options = ["--charset=UTF-8"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.4}
35
+ s.summary = %q{A simple mailer gem}
36
+ s.test_files = [
37
+ "test/simpleMailer_test.rb",
38
+ "test/test_helper.rb"
39
+ ]
40
+
41
+ if s.respond_to? :specification_version then
42
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
46
+ s.add_runtime_dependency(%q<shared-mime-info>, [">= 0"])
47
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
48
+ else
49
+ s.add_dependency(%q<shared-mime-info>, [">= 0"])
50
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
51
+ end
52
+ else
53
+ s.add_dependency(%q<shared-mime-info>, [">= 0"])
54
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
55
+ end
56
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class SimplemailerTest < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'simpleMailer'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simpleMailer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.5
5
+ platform: ruby
6
+ authors:
7
+ - Yoann LE TOUCHE
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-18 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: shared-mime-info
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: thoughtbot-shoulda
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: SimpleMailer is a simple wrapper for net::smtp that let you attach files
36
+ email: kurotoshiro@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.rdoc
49
+ - Rakefile
50
+ - VERSION
51
+ - lib/simpleMailer.rb
52
+ - simpleMailer.gemspec
53
+ - test/simpleMailer_test.rb
54
+ - test/test_helper.rb
55
+ has_rdoc: true
56
+ homepage: http://github.com/Kurotoshiro/simpleMailer
57
+ licenses: []
58
+
59
+ post_install_message:
60
+ rdoc_options:
61
+ - --charset=UTF-8
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ version:
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: "0"
75
+ version:
76
+ requirements: []
77
+
78
+ rubyforge_project:
79
+ rubygems_version: 1.3.4
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: A simple mailer gem
83
+ test_files:
84
+ - test/simpleMailer_test.rb
85
+ - test/test_helper.rb