Added remove support to imapfetch.py

Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
Janos SUTO 2023-05-01 20:58:42 +02:00
parent 73e56cd162
commit 85e925a6ae

View File

@ -14,6 +14,7 @@ opts = {}
INBOX = 'INBOX' INBOX = 'INBOX'
ST_RUNNING = 1 ST_RUNNING = 1
imaplib._MAXLINE = 10000000
def generate_auth_string(user, token): def generate_auth_string(user, token):
auth_string = f"user={user}\1auth=Bearer {token}\1\1" auth_string = f"user={user}\1auth=Bearer {token}\1\1"
@ -99,6 +100,11 @@ def process_folder(conn, folder):
opts['counter'] += 1 opts['counter'] += 1
with open("{}.eml".format(opts['counter']), "wb") as f: with open("{}.eml".format(opts['counter']), "wb") as f:
f.write(data[0][1]) f.write(data[0][1])
if opts['remove']:
conn.store(num, '+FLAGS', '\\Deleted')
if opts['remove']:
conn.expunge()
def main(): def main():
@ -121,6 +127,7 @@ def main():
default="/var/piler/imap") default="/var/piler/imap")
parser.add_argument("-i", "--import-from-table", action='store_true', parser.add_argument("-i", "--import-from-table", action='store_true',
help="Read imap conn data from import table") help="Read imap conn data from import table")
parser.add_argument("-r", "--remove", help="remove downloaded messages", action='store_true')
parser.add_argument("-v", "--verbose", help="verbose mode", action='store_true') parser.add_argument("-v", "--verbose", help="verbose mode", action='store_true')
args = parser.parse_args() args = parser.parse_args()
@ -139,6 +146,7 @@ def main():
opts['db'] = None opts['db'] = None
opts['id'] = 0 opts['id'] = 0
opts['access_token'] = '' opts['access_token'] = ''
opts['remove'] = args.remove
if args.date: if args.date:
opts['search'] = args.date opts['search'] = args.date