Class: Hermeneutics::Cli::SMTP
Defined Under Namespace
Classes: Error, NotOk, NotReadyForData, Response, ServerNotReady, Uncaught, UnspecError, Unused
Constant Summary
collapse
- CRLF =
true
Instance Attribute Summary collapse
Attributes inherited from Protocol
#timeout
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Protocol
#done?, #read, #readline, #trace!, #write, #writeline
Constructor Details
#initialize(*args) ⇒ SMTP
Returns a new instance of SMTP.
37
38
39
40
|
# File 'lib/hermeneutics/cli/smtp.rb', line 37
def initialize *args
super
get_response.ok? or raise ServerNotReady, @last_response.msg
end
|
Instance Attribute Details
#advertised ⇒ Object
Returns the value of attribute advertised.
34
35
36
|
# File 'lib/hermeneutics/cli/smtp.rb', line 34
def advertised
@advertised
end
|
#domain ⇒ Object
Returns the value of attribute domain.
33
34
35
|
# File 'lib/hermeneutics/cli/smtp.rb', line 33
def domain
@domain
end
|
#greet ⇒ Object
Returns the value of attribute greet.
33
34
35
|
# File 'lib/hermeneutics/cli/smtp.rb', line 33
def greet
@greet
end
|
#last_response ⇒ Object
Returns the value of attribute last_response.
35
36
37
|
# File 'lib/hermeneutics/cli/smtp.rb', line 35
def last_response
@last_response
end
|
Class Method Details
.open(host, port = nil, timeout: nil, ssl: false) ⇒ Object
27
28
29
30
|
# File 'lib/hermeneutics/cli/smtp.rb', line 27
def open host, port = nil, timeout: nil, ssl: false
port ||= ssl ? PORT_SSL : PORT
super host, port, timeout: timeout, ssl: ssl
end
|
Instance Method Details
#auth ⇒ Object
46
47
48
|
# File 'lib/hermeneutics/cli/smtp.rb', line 46
def auth
@advertised && @advertised[ :AUTH]
end
|
#bdat(data) ⇒ Object
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/hermeneutics/cli/smtp.rb', line 97
def bdat data
data.each { |d|
write_cmd "BDAT", d.bytesize
write d
get_response_ok
}
write_cmd "BDAT", 0, "LAST"
get_response_ok do |code,msg|
yield msg if block_given?
end
end
|
#data(reader) ⇒ Object
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/hermeneutics/cli/smtp.rb', line 86
def data reader
write_cmd "DATA"
get_response.waiting? or raise NotReadyForData, @last_response.msg
reader.each_line { |l|
l =~ /\A\./ and l = ".#{l}"
writeline l
}
writeline "."
get_response_ok
end
|
#ehlo(host = nil) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/hermeneutics/cli/smtp.rb', line 60
def ehlo host = nil
@advertised = {}
cmd_hello "EHLO", host do |code,msg|
unless @domain then
@domain, @greet = msg.split nil, 2
next
end
keyword, param = msg.split nil, 2
keyword.upcase!
keyword = keyword.to_sym
case keyword
when :SIZE then param = Integer param
when :AUTH then param = param.split.map { |p| p.upcase! ; p.to_sym }
end
@advertised[ keyword] = param || true
end
end
|
#has_auth?(meth) ⇒ Boolean
50
51
52
53
|
# File 'lib/hermeneutics/cli/smtp.rb', line 50
def has_auth? meth
a = auth
a and a.include? meth
end
|
#helo(host = nil) ⇒ Object
56
57
58
|
# File 'lib/hermeneutics/cli/smtp.rb', line 56
def helo host = nil
cmd_hello "HELO", host
end
|
#help(str = nil, &block) ⇒ Object
113
114
115
|
# File 'lib/hermeneutics/cli/smtp.rb', line 113
def help str = nil, &block
cmd "HELP", str, &block
end
|
#login(user, password) ⇒ Object
135
136
137
138
139
140
141
142
|
# File 'lib/hermeneutics/cli/smtp.rb', line 135
def login user, password
write_cmd "AUTH", "LOGIN"
get_response.waiting? or raise NotReadyForData, @last_response.msg
writeline [user].pack "m0"
get_response.waiting? or raise NotReadyForData, @last_response.msg
writeline [password].pack "m0"
get_response_ok
end
|
#mail_from(from) ⇒ Object
78
79
80
|
# File 'lib/hermeneutics/cli/smtp.rb', line 78
def mail_from from
cmd "MAIL", "FROM:<#{from}>"
end
|
#noop(str = nil) ⇒ Object
117
118
119
|
# File 'lib/hermeneutics/cli/smtp.rb', line 117
def noop str = nil
cmd "NOOP"
end
|
#plain(user, password) ⇒ Object
126
127
128
129
130
131
132
|
# File 'lib/hermeneutics/cli/smtp.rb', line 126
def plain user, password
write_cmd "AUTH", "PLAIN"
get_response.waiting? or raise NotReadyForData, @last_response.msg
l = ["\0#{user}\0#{password}"].pack "m0"
writeline l
get_response_ok
end
|
#quit ⇒ Object
121
122
123
|
# File 'lib/hermeneutics/cli/smtp.rb', line 121
def quit
cmd "QUIT"
end
|
#rcpt_to(to) ⇒ Object
82
83
84
|
# File 'lib/hermeneutics/cli/smtp.rb', line 82
def rcpt_to to
cmd "RCPT", "TO:<#{to}>"
end
|
#rset ⇒ Object
109
110
111
|
# File 'lib/hermeneutics/cli/smtp.rb', line 109
def rset
cmd "RSET"
end
|
#size ⇒ Object
42
43
44
|
# File 'lib/hermeneutics/cli/smtp.rb', line 42
def size
@advertised && @advertised[ :SIZE]
end
|