mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-11-07 22:31:59 +01:00
Improved imapfetch.py
Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
parent
1d615a1967
commit
f7f91c0855
@ -66,7 +66,7 @@ def process_folder(conn, folder):
|
||||
if opts['id']:
|
||||
cursor = opts['db'].cursor()
|
||||
data = (ST_RUNNING, n, opts['id'])
|
||||
cursor.execute("UPDATE import SET status=%s, total = total + %s WHERE id=%s", data)
|
||||
cursor.execute("UPDATE import SET status=%s, total=total+%s WHERE id=%s", data)
|
||||
opts['db'].commit()
|
||||
|
||||
rc, data = conn.search(None, 'ALL')
|
||||
@ -91,11 +91,16 @@ def main():
|
||||
default="junk,trash,spam,draft")
|
||||
parser.add_argument("-f", "--folders", type=str,
|
||||
help="Comma separated list of IMAP folders to download")
|
||||
parser.add_argument("-i", "--import-from-table", help="Read imap conn data from import table", action='store_true')
|
||||
parser.add_argument("-d", "--dir", help="directory to chdir",
|
||||
default="/var/piler/imap")
|
||||
parser.add_argument("-i", "--import-from-table", action='store_true',
|
||||
help="Read imap conn data from import table")
|
||||
parser.add_argument("-v", "--verbose", help="verbose mode", action='store_true')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
os.chdir(args.dir)
|
||||
|
||||
if not bool(args.import_from_table or args.server):
|
||||
print("Please specify either --import-from-table or --server <imap host>")
|
||||
sys.exit(1)
|
||||
@ -158,10 +163,15 @@ def main():
|
||||
conn.close()
|
||||
|
||||
if opts['db']:
|
||||
subprocess.call(["pilerimport", "-d", "/var/piler/imap", "-r"])
|
||||
if opts['id']:
|
||||
subprocess.call(["pilerimport",
|
||||
"-d", args.dir,
|
||||
"-r",
|
||||
"-T", str(opts['id'])])
|
||||
opts['db'].close()
|
||||
|
||||
print("Processed {} messages".format(opts['counter']))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user