kurotoshiro-simpleMailer 0.1.2

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/.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,22 @@
1
+ = simpleMailer
2
+
3
+ SimpleMailer is a very simple wrapper for Ruby's net::smtp
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but
13
+ bump version in a commit by itself I can ignore when I pull)
14
+ * Send me a pull request. Bonus points for topic branches.
15
+
16
+ == Thanks
17
+
18
+ Thanks to *technicalpickles* for his awesome gem *Jeweler*
19
+
20
+ == Copyright
21
+
22
+ Copyright (c) 2009 Yoann LE TOUCHE. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
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_development_dependency "thoughtbot-shoulda"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ require 'rake/testtask'
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'lib' << 'test'
23
+ test.pattern = 'test/**/*_test.rb'
24
+ test.verbose = true
25
+ end
26
+
27
+ begin
28
+ require 'rcov/rcovtask'
29
+ Rcov::RcovTask.new do |test|
30
+ test.libs << 'test'
31
+ test.pattern = 'test/**/*_test.rb'
32
+ test.verbose = true
33
+ end
34
+ rescue LoadError
35
+ task :rcov do
36
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
+ end
38
+ end
39
+
40
+ task :test => :check_dependencies
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ if File.exist?('VERSION')
47
+ version = File.read('VERSION')
48
+ else
49
+ version = ""
50
+ end
51
+
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "simpleMailer #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.2
@@ -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,54 @@
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.2"
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-12}
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.has_rdoc = true
32
+ s.homepage = %q{http://github.com/Kurotoshiro/simpleMailer}
33
+ s.rdoc_options = ["--charset=UTF-8"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.1}
36
+ s.summary = %q{A simple mailer gem}
37
+ s.test_files = [
38
+ "test/test_helper.rb",
39
+ "test/simpleMailer_test.rb"
40
+ ]
41
+
42
+ if s.respond_to? :specification_version then
43
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
+ s.specification_version = 2
45
+
46
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
47
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
48
+ else
49
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
50
+ end
51
+ else
52
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
53
+ end
54
+ 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,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kurotoshiro-simpleMailer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Yoann LE TOUCHE
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-12 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thoughtbot-shoulda
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: SimpleMailer is a simple wrapper for net::smtp that let you attach files
26
+ email: kurotoshiro@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION
41
+ - lib/simpleMailer.rb
42
+ - simpleMailer.gemspec
43
+ - test/simpleMailer_test.rb
44
+ - test/test_helper.rb
45
+ has_rdoc: true
46
+ homepage: http://github.com/Kurotoshiro/simpleMailer
47
+ licenses:
48
+ post_install_message:
49
+ rdoc_options:
50
+ - --charset=UTF-8
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ requirements: []
66
+
67
+ rubyforge_project:
68
+ rubygems_version: 1.3.5
69
+ signing_key:
70
+ specification_version: 2
71
+ summary: A simple mailer gem
72
+ test_files:
73
+ - test/test_helper.rb
74
+ - test/simpleMailer_test.rb