mirror of
https://github.com/samsonjs/imapbackup.git
synced 2026-04-27 14:57:44 +00:00
added timeout option in an attempt to fix #3
This commit is contained in:
parent
b2ab83412b
commit
edbb92844c
1 changed files with 19 additions and 4 deletions
|
|
@ -1,9 +1,9 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python -u
|
||||||
|
|
||||||
"""IMAP Incremental Backup Script"""
|
"""IMAP Incremental Backup Script"""
|
||||||
__version__ = "1.4g"
|
__version__ = "1.4h"
|
||||||
__author__ = "Rui Carmo (http://taoofmac.com)"
|
__author__ = "Rui Carmo (http://taoofmac.com)"
|
||||||
__copyright__ = "(C) 2006-2017 Rui Carmo. Code under MIT License.(C)"
|
__copyright__ = "(C) 2006-2018 Rui Carmo. Code under MIT License.(C)"
|
||||||
__contributors__ = "jwagnerhki, Bob Ippolito, Michael Leonhard, Giuseppe Scrivano <gscrivano@gnu.org>, Ronan Sheth, Brandon Long, Christian Schanz, A. Bovett"
|
__contributors__ = "jwagnerhki, Bob Ippolito, Michael Leonhard, Giuseppe Scrivano <gscrivano@gnu.org>, Ronan Sheth, Brandon Long, Christian Schanz, A. Bovett"
|
||||||
|
|
||||||
# = Contributors =
|
# = Contributors =
|
||||||
|
|
@ -35,6 +35,8 @@ __contributors__ = "jwagnerhki, Bob Ippolito, Michael Leonhard, Giuseppe Scrivan
|
||||||
# - Submit patch of socket._fileobject.read
|
# - Submit patch of socket._fileobject.read
|
||||||
# - Improve imaplib module with LIST parsing code, submit patch
|
# - Improve imaplib module with LIST parsing code, submit patch
|
||||||
# DONE:
|
# DONE:
|
||||||
|
# v1.4h
|
||||||
|
# - Add timeout option
|
||||||
# v1.3c
|
# v1.3c
|
||||||
# - Add SSL support
|
# - Add SSL support
|
||||||
# - Support host:port
|
# - Support host:port
|
||||||
|
|
@ -380,6 +382,7 @@ def print_usage():
|
||||||
print " -s HOST --server=HOST Address of server, port optional, eg. mail.com:143"
|
print " -s HOST --server=HOST Address of server, port optional, eg. mail.com:143"
|
||||||
print " -u USER --user=USER Username to log into server"
|
print " -u USER --user=USER Username to log into server"
|
||||||
print " -p PASS --pass=PASS Prompts for password if not specified."
|
print " -p PASS --pass=PASS Prompts for password if not specified."
|
||||||
|
print " -t SECS --timeout=SECS Sets socket timeout to SECS seconds."
|
||||||
print " --thunderbird Create Mozilla Thunderbird compatible mailbox"
|
print " --thunderbird Create Mozilla Thunderbird compatible mailbox"
|
||||||
print " --nospinner Disable spinner (makes output log-friendly)"
|
print " --nospinner Disable spinner (makes output log-friendly)"
|
||||||
print "\nNOTE: mbox files are created in the current working directory."
|
print "\nNOTE: mbox files are created in the current working directory."
|
||||||
|
|
@ -438,6 +441,8 @@ def process_cline():
|
||||||
config['user'] = value
|
config['user'] = value
|
||||||
elif option in ("-p", "--pass"):
|
elif option in ("-p", "--pass"):
|
||||||
config['pass'] = value
|
config['pass'] = value
|
||||||
|
elif option in ("-t", "--timeout"):
|
||||||
|
config['timeout'] = value
|
||||||
elif option == "--thunderbird":
|
elif option == "--thunderbird":
|
||||||
config['thunderbird'] = True
|
config['thunderbird'] = True
|
||||||
elif option == "--nospinner":
|
elif option == "--nospinner":
|
||||||
|
|
@ -484,6 +489,14 @@ def check_config(config, warnings, errors):
|
||||||
config['port'] = port
|
config['port'] = port
|
||||||
except ValueError:
|
except ValueError:
|
||||||
errors.append("Invalid port. Port must be an integer between 0 and 65535.")
|
errors.append("Invalid port. Port must be an integer between 0 and 65535.")
|
||||||
|
if 'timeout' in config:
|
||||||
|
try:
|
||||||
|
timeout = int(config['timeout'])
|
||||||
|
if timeout <= 0:
|
||||||
|
raise ValueError
|
||||||
|
config['timeout']=timeout
|
||||||
|
except ValueError:
|
||||||
|
errors.append("Invalid timeout value. Must be an integer greater than 0.")
|
||||||
return (config, warnings, errors)
|
return (config, warnings, errors)
|
||||||
|
|
||||||
def get_config():
|
def get_config():
|
||||||
|
|
@ -531,6 +544,8 @@ def connect_and_login(config):
|
||||||
"""Connects to the server and logs in. Returns IMAP4 object."""
|
"""Connects to the server and logs in. Returns IMAP4 object."""
|
||||||
try:
|
try:
|
||||||
assert(not (('keyfilename' in config) ^ ('certfilename' in config)))
|
assert(not (('keyfilename' in config) ^ ('certfilename' in config)))
|
||||||
|
if config['timeout']:
|
||||||
|
socket.setdefaulttimeout(config['timeout'])
|
||||||
|
|
||||||
if config['usessl'] and 'keyfilename' in config:
|
if config['usessl'] and 'keyfilename' in config:
|
||||||
print "Connecting to '%s' TCP port %d," % (config['server'], config['port']),
|
print "Connecting to '%s' TCP port %d," % (config['server'], config['port']),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue