@@ -241,11 +241,12 @@ def POP3.APOP(isapop)
241
241
242
242
# Starts a POP3 session and iterates over each POPMail object,
243
243
# yielding it to the +block+.
244
- # This method is equivalent to:
245
244
#
246
- # Net::POP3.start(address, port, account, password) do |pop|
247
- # pop.each_mail do |m|
248
- # yield m
245
+ # All other arguments are forwarded to Net::POP3.start, equivalent to:
246
+ #
247
+ # Net::POP3.start(*args, **kwargs) do |pop|
248
+ # pop.each_mail do |mail|
249
+ # yield mail
249
250
# end
250
251
# end
251
252
#
@@ -259,36 +260,33 @@ def POP3.APOP(isapop)
259
260
# m.delete if $DELETE
260
261
# end
261
262
#
262
- def POP3 . foreach ( address , port = nil ,
263
- account = nil , password = nil ,
264
- isapop = false , &block ) # :yields: message
265
- start ( address , port , account , password , isapop ) { |pop |
263
+ def POP3 . foreach ( *args , **kwargs , &block ) # :yields: message
264
+ start ( *args , **kwargs ) { |pop |
266
265
pop . each_mail ( &block )
267
266
}
268
267
end
269
268
270
269
# Starts a POP3 session and deletes all messages on the server.
271
270
# If a block is given, each POPMail object is yielded to it before
272
- # being deleted.
271
+ # being deleted. All other arguments are forwarded to Net::POP3.start.
273
272
#
274
273
# This method raises a POPAuthenticationError if authentication fails.
275
274
#
276
275
# === Example
277
276
#
278
277
# Net::POP3.delete_all('pop.example.com', 110,
279
- # 'YourAccount', 'YourPassword') do |m |
280
- # file.write m .pop
278
+ # 'YourAccount', 'YourPassword') do |mail |
279
+ # file.write mail .pop
281
280
# end
282
281
#
283
- def POP3 . delete_all ( address , port = nil ,
284
- account = nil , password = nil ,
285
- isapop = false , &block )
286
- start ( address , port , account , password , isapop ) { |pop |
282
+ def POP3 . delete_all ( *args , **kwargs , &block ) # :yields: message
283
+ start ( *args , **kwargs ) { |pop |
287
284
pop . delete_all ( &block )
288
285
}
289
286
end
290
287
291
288
# Opens a POP3 session, attempts authentication, and quits.
289
+ # All arguments are forwarded to ::start.
292
290
#
293
291
# This method raises POPAuthenticationError if authentication fails.
294
292
#
@@ -302,20 +300,18 @@ def POP3.delete_all(address, port = nil,
302
300
# Net::POP3.auth_only('pop.example.com', 110,
303
301
# 'YourAccount', 'YourPassword', true)
304
302
#
305
- def POP3 . auth_only ( address , port = nil ,
306
- account = nil , password = nil ,
307
- isapop = false )
308
- new ( address , port , isapop ) . auth_only account , password
303
+ def POP3 . auth_only ( *args , **kwargs )
304
+ start ( *args , **kwargs ) { true }
309
305
end
310
306
311
307
# Starts a pop3 session, attempts authentication, and quits.
312
308
# This method must not be called while POP3 session is opened.
313
309
# This method raises POPAuthenticationError if authentication fails.
314
- def auth_only ( account , password )
310
+ #
311
+ # All arguments are forwarded to #start. See that method for details.
312
+ def auth_only ( *args , **kwargs )
315
313
raise IOError , 'opening previously opened POP session' if started?
316
- start ( account , password ) {
317
- ;
318
- }
314
+ start ( *args , **kwargs ) { true }
319
315
end
320
316
321
317
#
@@ -333,8 +329,7 @@ def POP3.enable_ssl(*args)
333
329
@ssl_params = create_ssl_params ( *args )
334
330
end
335
331
336
- # Constructs proper parameters from arguments
337
- def POP3 . create_ssl_params ( verify_or_params = { } , certs = nil )
332
+ def POP3 . create_ssl_params ( verify_or_params = { } , certs = nil ) # :nodoc:
338
333
begin
339
334
params = verify_or_params . to_hash
340
335
rescue NoMethodError
@@ -382,9 +377,16 @@ def POP3.certs
382
377
# Session management
383
378
#
384
379
380
+ # :call-seq:
381
+ # Net::POP3.start(address, port = nil, user = nil, pass = nil, auth: {}, **opts) -> pop
382
+ # Net::POP3.start(address, port: nil, user: nil, pass: nil, auth: {}, **opts) -> pop
383
+ # Net::POP3.start(address, port = nil, user = nil, pass = nil, auth: {}, **opts) {|pop| }
384
+ # Net::POP3.start(address, port: nil, user: nil, pass: nil, auth: {}, **opts) {|pop| }
385
+ #
385
386
# Creates a new POP3 object and open the connection. Equivalent to
386
387
#
387
- # Net::POP3.new(address, port, isapop).start(account, password)
388
+ # Net::POP3.new(address, port, **opts)
389
+ # .start(user, pass, **auth, &block)
388
390
#
389
391
# If +block+ is provided, yields the newly-opened POP3 object to it,
390
392
# and automatically closes it at the end of the session.
@@ -400,32 +402,63 @@ def POP3.certs
400
402
#
401
403
def POP3 . start ( address , port = nil ,
402
404
account = nil , password = nil ,
403
- isapop = false , &block ) # :yield: pop
404
- new ( address , port , isapop ) . start ( account , password , &block )
405
+ isapop = false ,
406
+ user : nil , pass : nil , auth : { } ,
407
+ **kwargs , &block ) # :yield: pop
408
+ new ( address , port , isapop , **kwargs )
409
+ . start ( user || account , pass || password , **auth , &block )
405
410
end
406
411
412
+ # :call-seq:
413
+ # new(addr, port = nil, **options)
414
+ # new(addr, port: nil, ssl: POP3.ssl_params, apop: false,
415
+ # read_timeout: 60, open_timeout: 30, debug_output: nil)
416
+ #
407
417
# Creates a new POP3 object.
408
418
#
409
419
# +address+ is the hostname or ip address of your POP3 server.
410
420
#
411
- # The optional +port+ is the port to connect to.
412
- #
413
- # The optional +isapop+ specifies whether this connection is going
414
- # to use APOP authentication; it defaults to +false+.
415
- #
416
- # This method does *not* open the TCP connection.
417
- def initialize ( addr , port = nil , isapop = false )
421
+ # The optional +port+ is the port to connect to. The default port will be
422
+ # chosen based on whether or not +ssl+ is used.
423
+ #
424
+ # The optional +ssl+ should be true to connect using TLS. When +tls+ is a
425
+ # hash, it is used to set parameters with
426
+ # {OpenSSL::SSL::SSLContext#set_params}[https://docs.ruby-lang.org/en/master/OpenSSL/SSL/SSLContext.html#method-i-set_params].
427
+ #
428
+ # The +open_timeout+ and +read_timeout+ options will set their
429
+ # respective IO timeouts on the socket.
430
+ #
431
+ # See #set_debug_output for the use of +debug_output.
432
+ #
433
+ # The optional +apop+ specifies whether this connection is going
434
+ # to use APOP authentication; it defaults to +false+. <em>Warning: APOP is
435
+ # based on MD5 and it is insecure, obsolete, and should be avoided.</em>
436
+ #
437
+ # This method does *not* open the TCP connection. See #start.
438
+ def initialize ( addr , port_ = nil , isapop = false ,
439
+ port : nil ,
440
+ ssl : POP3 . ssl_params ,
441
+ apop : false ,
442
+ read_timeout : 60 ,
443
+ open_timeout : 30 ,
444
+ debug_output : nil )
445
+ if port_ . respond_to? ( :to_hash )
446
+ return initialize nil , false , **port_
447
+ elsif isapop . respond_to? ( :to_hash )
448
+ return initialize port_ , false , **isapop
449
+ end
418
450
@address = addr
419
- @ssl_params = POP3 . ssl_params
420
- @port = port
421
- @apop = isapop
451
+ @ssl_params = Hash . try_convert ( ssl ) . dup
452
+ @ssl_params ||= { } if ssl
453
+ @port = port || port_
454
+ @apop = apop || isapop
455
+ @open_timeout = open_timeout
456
+ @read_timeout = read_timeout
457
+ @debug_output = debug_output
422
458
423
459
@command = nil
424
460
@socket = nil
425
461
@started = false
426
- @open_timeout = 30
427
- @read_timeout = 60
428
- @debug_output = nil
429
462
430
463
@mails = nil
431
464
@n_mails = nil
@@ -459,7 +492,7 @@ def enable_ssl(verify_or_params = {}, certs = nil, port = nil)
459
492
end
460
493
end
461
494
462
- # Disable SSL for all new instances .
495
+ # Disable SSL for this instance .
463
496
def disable_ssl
464
497
@ssl_params = nil
465
498
end
0 commit comments