raw_smtp 0.1.0.test

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b4bab05e57ccbc3dc65140a633d9755f2e983114
4
+ data.tar.gz: 77079197c46a3dec4f1c9f7bcf451e43f56a2555
5
+ SHA512:
6
+ metadata.gz: 9cef5fe9530f822384addb2cb5f5e409dccf2e726f5ed7f887a3a628d2fc09957b617421644a7860444309d3b012d36eae827f8bb5ad94dd15d60fc79cfcd739
7
+ data.tar.gz: 9ec39d4952460a42466046cb2c81c8bd50e1f216b7bc31d4aa8ae62852b22b1623e3d7d4acb5f224b2babd644e684e675756d4c3967f86e76d9703d6fbe2cafd
@@ -0,0 +1,18 @@
1
+ # Editor/OS-specific
2
+ .DS_Store
3
+ .swp
4
+
5
+ # Bundler/Rubygems
6
+ *.gem
7
+ .bundle
8
+ pkg/*
9
+ tags
10
+ Gemfile.lock
11
+
12
+ # RDoc
13
+ /doc
14
+ /html
15
+
16
+ # Vagrant
17
+ .vagrant
18
+ /Vagrantfile*
@@ -0,0 +1,5 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ # Disable string literals cop
4
+ Style/StringLiterals:
5
+ Enabled: false
@@ -0,0 +1,40 @@
1
+ # This configuration was generated by `rubocop --auto-gen-config`
2
+ # on 2015-07-03 10:01:10 +0200 using RuboCop version 0.32.1.
3
+ # The point is for the user to remove these configuration records
4
+ # one by one as the offenses are removed from the code base.
5
+ # Note that changes in the inspected code, or installation of new
6
+ # versions of RuboCop, may require this file to be generated again.
7
+
8
+ # Offense count: 1
9
+ # Configuration parameters: AllowSafeAssignment.
10
+ Lint/AssignmentInCondition:
11
+ Enabled: false
12
+
13
+ # Offense count: 7
14
+ # Configuration parameters: AllowURI, URISchemes.
15
+ Metrics/LineLength:
16
+ Max: 132
17
+
18
+ # Offense count: 2
19
+ # Configuration parameters: CountComments.
20
+ Metrics/MethodLength:
21
+ Max: 25
22
+
23
+ # Offense count: 1
24
+ # Configuration parameters: CountKeywordArgs.
25
+ Metrics/ParameterLists:
26
+ Max: 7
27
+
28
+ # Offense count: 1
29
+ # Cop supports --auto-correct.
30
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
31
+ Style/EmptyElse:
32
+ Enabled: false
33
+
34
+ # Offense count: 1
35
+ Style/UnlessElse:
36
+ Enabled: false
37
+
38
+ # Turnining
39
+ Documentation:
40
+ Enabled: false
@@ -0,0 +1 @@
1
+ 2.1.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ gem 'raw_smtp', path: '.'
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Artem Yakimenko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,2 @@
1
+ # raw_smtp
2
+ Simple SMTP client. An experiment in raw sockets in Ruby.
@@ -0,0 +1,5 @@
1
+ = \Raw_smtp - Simple SMTP client.
2
+
3
+ == Description
4
+
5
+ This is an experiment in raw sockets in Ruby to eventually produce an SMTP debugger.
@@ -0,0 +1,17 @@
1
+ require 'bundler/setup'
2
+
3
+ # Immediately sync all stdout so that tools like buildbot can
4
+ # immediately load in the output.
5
+ $stdout.sync = true
6
+ $stderr.sync = true
7
+
8
+ # Load all the rake tasks from the "tasks" folder. This folder
9
+ # allows us to nicely separate rake tasks into individual files
10
+ # based on their role, which makes development and debugging easier
11
+ # than one monolithic file.
12
+ task_dir = File.expand_path("../tasks", __FILE__)
13
+ Dir["#{task_dir}/**/*.rake"].each do |task_file|
14
+ load task_file
15
+ end
16
+
17
+ task default: "test:unit"
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "raw_smtp"
5
+
6
+ require "pry"
7
+ Pry.start
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'trollop'
4
+ require 'raw_smtp'
5
+ require 'raw_smtp/smtp'
6
+ require 'raw_smtp/validator'
7
+
8
+ opts = Trollop.options do
9
+ version "raw_smtp #{RawSmtp::VERSION} (c) 2015 Artem Yakimenko"
10
+ banner <<-EOS
11
+ Simple SMTP client for Ruby using raw sockets.
12
+ Usage:
13
+ raw_smtp [options]
14
+ where [options] are:
15
+ EOS
16
+
17
+ opt :server, "Smtp server hostname or IP address", type: String
18
+ opt :sending_server, "Sending server name for EHLO", type: String
19
+ opt :mail_rcpt_to, "Message recepient in RCPT_TO", type: String
20
+ opt :mail_subject, "Message subject", type: String
21
+ end
22
+
23
+ Trollop.die :server, "Server and recepient must be specified" unless opts[:server]
24
+ Trollop.die :mail_rcpt_to, "Server and recepient must be specified" unless opts[:mail_rcpt_to]
25
+ Trollop.die :server, "Server must be a valid IP address or hostname" unless validate_address(opts[:server]) if opts[:server]
26
+
27
+ m = SMTP.new(server: opts[:server],
28
+ mail_rcpt_to: opts[:mail_rcpt_to],
29
+ mail_subject: opts[:mail_subject]
30
+ )
31
+ m.connect!
@@ -0,0 +1,7 @@
1
+ require 'raw_smtp/version'
2
+
3
+ # Main module stub
4
+ module RawSmtp
5
+ require 'raw_smtp/validator'
6
+ require 'raw_smtp/smtp'
7
+ end
@@ -0,0 +1,76 @@
1
+ require 'socket'
2
+ require 'uri'
3
+ require 'digest/sha2'
4
+
5
+ # The program uses raw TCP sockets to send a sequence of
6
+ # SMTP messages to a mail server.
7
+ #
8
+ # Author:: Artem Yakimenko (mailto:dave@x.y)
9
+ # Copyright:: Copyright (c) 2015 Artem Yakimenko
10
+ # License:: MIT
11
+
12
+ # This is the main class that performs the connection.
13
+ class SMTP
14
+ # * server: server to attempt an SMTP connection to.
15
+ # * mail_from: sender, what to populate MAIL_FROM headers with.
16
+ # * mail_rcpt_to: recepient, what to populate RCPT_TO headers with.
17
+ # * mail_headers: custom headers. Need to be specified fully in a tabulated
18
+ # string format. Overrides all header parameters!
19
+ # * mail_subject: email subject to be inserted into headers.
20
+ # * mail_body: email body in a tabulated string format.
21
+ def initialize(server:,
22
+ sending_server: "mail.example.com",
23
+ mail_from: "user@example.com",
24
+ mail_rcpt_to:,
25
+ mail_headers: nil,
26
+ mail_subject: "This is a test message",
27
+ mail_body: "This is a test message.\nRegards,\nraw_smtp"
28
+ )
29
+ @server = server
30
+ @sending_server = sending_server
31
+ @mail_from = mail_from
32
+ @mail_rcpt_to = mail_rcpt_to
33
+ @mail_subject = mail_subject
34
+ @mail_body = mail_body
35
+
36
+ unless mail_headers
37
+ @mail_headers = <<-EOH.gsub(/^\s+/, "")
38
+ \tMIME-Version: 1.0
39
+ \tMessage-ID: #{Digest::SHA2.hexdigest(Time.now.to_i.to_s)}@#{@sending_server}
40
+ \tDate: #{DateTime.now.rfc822.to_s}
41
+ \tSubject: #{@mail_subject}
42
+ \tFrom: #{@mail_from}
43
+ \tTo: #{@mail_rcpt_to}
44
+ \t
45
+ EOH
46
+ else
47
+ @mail_headers = mail_headers
48
+ end
49
+ end
50
+
51
+ def connect!
52
+ puts "Trying to open an SMTP session..."
53
+ connection = TCPSocket.new @server, 25
54
+
55
+ mail_data_chunk = @mail_headers + @mail_body + "\n."
56
+
57
+ protocol_queue = [
58
+ "EHLO #{@sending_server}",
59
+ "MAIL FROM:<#{@mail_from}>",
60
+ "RCPT TO:<#{@mail_rcpt_to}>",
61
+ "DATA",
62
+ "#{mail_data_chunk}",
63
+ "QUIT"
64
+ ]
65
+
66
+ while message = protocol_queue.shift
67
+ connection.puts(message)
68
+ puts message
69
+ sleep 1
70
+ puts connection.recv(2048)
71
+ end
72
+
73
+ puts "Session closed."
74
+ connection.close
75
+ end
76
+ end
@@ -0,0 +1,12 @@
1
+ require 'resolv'
2
+
3
+ # Regex to verify a valid hostname per RFC 1123.
4
+ VALID_HOSTNAME_REGEX = "^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$"
5
+
6
+ def validate_address(input)
7
+ if input.match(VALID_HOSTNAME_REGEX) || input.match(Resolv::IPv4::Regex)
8
+ input
9
+ else
10
+ nil
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ # Standard versioning stub
2
+ module RawSmtp
3
+ VERSION = "0.1.0.test"
4
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'raw_smtp/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'raw_smtp'
8
+ s.version = RawSmtp::VERSION
9
+ s.authors = ["Artem Yakimenko"]
10
+ s.email = ["code@temik.me"]
11
+ s.homepage = "http://rubygems.org/gems/raw-smtp"
12
+ s.license = "MIT"
13
+
14
+ s.summary = "SMTP using raw sockets"
15
+ s.description = "A simple experimental SMTP client"
16
+
17
+ s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ s.bindir = "exe"
19
+ s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_runtime_dependency 'trollop', '~> 2.1'
23
+
24
+ s.add_development_dependency 'pry', '~> 0'
25
+ s.add_development_dependency 'pry-byebug', '~> 3.1'
26
+ s.add_development_dependency 'rubocop', '~> 0.32.1'
27
+ s.add_development_dependency 'rake', '~> 10.4'
28
+ s.add_development_dependency 'bundler', '~> 1.10'
29
+ s.add_development_dependency 'rdoc', '~> 4.2'
30
+ end
@@ -0,0 +1,3 @@
1
+ # This installs the tasks that help with gem creation and
2
+ # publishing.
3
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,3 @@
1
+ require 'rubocop/rake_task'
2
+
3
+ RuboCop::RakeTask.new(:lint)
@@ -0,0 +1,6 @@
1
+ require 'rdoc/task'
2
+
3
+ RDoc::Task.new do |rd|
4
+ rd.main = "README.rdoc"
5
+ rd.rdoc_files.include("README.rdoc", "lib/**/*.rb")
6
+ end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: raw_smtp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.test
5
+ platform: ruby
6
+ authors:
7
+ - Artem Yakimenko
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: trollop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.32.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.32.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.10'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.10'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rdoc
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '4.2'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '4.2'
111
+ description: A simple experimental SMTP client
112
+ email:
113
+ - code@temik.me
114
+ executables:
115
+ - raw_smtp
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rubocop.yml"
121
+ - ".rubocop_todo.yml"
122
+ - ".ruby-version"
123
+ - Gemfile
124
+ - Gemfile.lock
125
+ - LICENSE
126
+ - README.md
127
+ - README.rdoc
128
+ - Rakefile
129
+ - bin/console
130
+ - exe/raw_smtp
131
+ - lib/raw_smtp.rb
132
+ - lib/raw_smtp/smtp.rb
133
+ - lib/raw_smtp/validator.rb
134
+ - lib/raw_smtp/version.rb
135
+ - raw_smtp.gemspec
136
+ - tasks/bundler.rake
137
+ - tasks/lint.rake
138
+ - tasks/rdoc.rake
139
+ homepage: http://rubygems.org/gems/raw-smtp
140
+ licenses:
141
+ - MIT
142
+ metadata: {}
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">"
155
+ - !ruby/object:Gem::Version
156
+ version: 1.3.1
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 2.2.2
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: SMTP using raw sockets
163
+ test_files: []