57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
'''
|
|
@author: Klaus-Uwe Mitterer
|
|
'''
|
|
from optparse import OptionParser
|
|
import EmlHelper
|
|
import ImapHelper
|
|
|
|
def validateAction(options):
|
|
message=EmlHelper.EmlHelper.readFile(options.file)
|
|
account=ImapHelper.ImapHelper(options.server,options.port,options.ssl,options.user,options.password,options.folder)
|
|
account.addMessage(message)
|
|
|
|
def run():
|
|
usage = "usage: %prog [options] file"
|
|
parser = OptionParser(usage)
|
|
parser.add_option("-s", "--server", dest="server",
|
|
help="imap server", action="store",type="string")
|
|
parser.add_option("-u", "--user",
|
|
action="store", dest="user",type="string",
|
|
help="imap username")
|
|
parser.add_option("-p", "--password",
|
|
action="store", dest="password",type="string",
|
|
help="imap user password")
|
|
parser.add_option("-f", "--folder",
|
|
action="store", dest="folder",type="string",
|
|
help="imap folder")
|
|
parser.add_option( "--port",
|
|
action="store", dest="port",type="int",
|
|
help="imap port")
|
|
parser.add_option( "--ssl",
|
|
action="store_true", dest="ssl",
|
|
help="use ssl")
|
|
|
|
(options, args) = parser.parse_args()
|
|
if len(args) == 0:
|
|
parser.error("Eml file path is required")
|
|
options.file=args[0]
|
|
if options.server is None:
|
|
parser.error("server address is required")
|
|
if options.user is None:
|
|
parser.error("user is required")
|
|
if options.password is None:
|
|
parser.error("password is required")
|
|
if options.folder is None:
|
|
parser.error("imap folder is required")
|
|
if options.ssl is None:
|
|
options.ssl=False
|
|
if options.port is None:
|
|
if options.ssl is True:
|
|
options.port=993
|
|
else:
|
|
options.port=143
|
|
validateAction(options)
|
|
|
|
if __name__ == "__main__":
|
|
run()
|