mirror of
https://github.com/chillout2k/gulag.git
synced 2025-12-13 16:00:18 +00:00
Cosmetics
This commit is contained in:
parent
70550c4021
commit
5723b18367
27
app/Gulag.py
27
app/Gulag.py
@ -143,10 +143,10 @@ class Gulag:
|
|||||||
# ist ein Attachment
|
# ist ein Attachment
|
||||||
filename = email.header.decode_header(part.get_filename())
|
filename = email.header.decode_header(part.get_filename())
|
||||||
if filename[0][1]:
|
if filename[0][1]:
|
||||||
# Encoded
|
# filename is encoded
|
||||||
filename = filename[0][0].decode(filename[0][1])
|
filename = filename[0][0].decode(filename[0][1])
|
||||||
else:
|
else:
|
||||||
# Nicht encoded
|
# filename isn´t encoded
|
||||||
filename = filename[0][0]
|
filename = filename[0][0]
|
||||||
attach_id = self.db.add_attachment({
|
attach_id = self.db.add_attachment({
|
||||||
'filename': filename,
|
'filename': filename,
|
||||||
@ -154,7 +154,7 @@ class Gulag:
|
|||||||
'content_encoding': part['Content-Transfer-Encoding']
|
'content_encoding': part['Content-Transfer-Encoding']
|
||||||
})
|
})
|
||||||
attachments.append(attach_id)
|
attachments.append(attach_id)
|
||||||
# Ende if part.get_filename()
|
# End if part.get_filename()
|
||||||
# get all URIs
|
# get all URIs
|
||||||
ctype = part.get_content_type()
|
ctype = part.get_content_type()
|
||||||
if(ctype == 'text/plain' or ctype == 'text/html'):
|
if(ctype == 'text/plain' or ctype == 'text/html'):
|
||||||
@ -162,12 +162,13 @@ class Gulag:
|
|||||||
curis = extract_uris(part.get_payload(decode=True).decode("utf-8"))
|
curis = extract_uris(part.get_payload(decode=True).decode("utf-8"))
|
||||||
if(len(curis) > 0):
|
if(len(curis) > 0):
|
||||||
uris = {**uris, **curis}
|
uris = {**uris, **curis}
|
||||||
# Ende for msg.walk()
|
# End for msg.walk()
|
||||||
# QuarMail und Attachments verknüpfen
|
# link message with attachments
|
||||||
if(len(attachments) > 0):
|
if(len(attachments) > 0):
|
||||||
for quarmail_id in quarmail_ids:
|
for quarmail_id in quarmail_ids:
|
||||||
for attachment_id in attachments:
|
for attachment_id in attachments:
|
||||||
self.db.quarmail2attachment(str(quarmail_id), str(attachment_id))
|
self.db.quarmail2attachment(str(quarmail_id), str(attachment_id))
|
||||||
|
# link message with uris
|
||||||
if(len(uris) > 0):
|
if(len(uris) > 0):
|
||||||
for quarmail_id in quarmail_ids:
|
for quarmail_id in quarmail_ids:
|
||||||
for uri in uris:
|
for uri in uris:
|
||||||
@ -179,9 +180,9 @@ class Gulag:
|
|||||||
self.db.quarmail2uri(str(quarmail_id), str(uri_id))
|
self.db.quarmail2uri(str(quarmail_id), str(uri_id))
|
||||||
except GulagDBException as e:
|
except GulagDBException as e:
|
||||||
logging.error(whoami(self) + e.message)
|
logging.error(whoami(self) + e.message)
|
||||||
# Ende for(unseen)
|
# End for(unseen)
|
||||||
imap_mb.close()
|
imap_mb.close()
|
||||||
# Ende for get_mailboxes
|
# End for get_mailboxes
|
||||||
|
|
||||||
def cleanup_quarmails(self):
|
def cleanup_quarmails(self):
|
||||||
logging.info(whoami(self) + "QuarMails to purge: " + str(len(
|
logging.info(whoami(self) + "QuarMails to purge: " + str(len(
|
||||||
@ -281,6 +282,7 @@ class Gulag:
|
|||||||
return self.db.get_quarmail_uris(args['quarmail_id'])
|
return self.db.get_quarmail_uris(args['quarmail_id'])
|
||||||
except GulagDBException as e:
|
except GulagDBException as e:
|
||||||
raise GulagException(whoami(self) + e.message) from e
|
raise GulagException(whoami(self) + e.message) from e
|
||||||
|
# get URIs from email@IMAP
|
||||||
qm_db = None
|
qm_db = None
|
||||||
try:
|
try:
|
||||||
qm_db = self.db.get_quarmail({"id": args['quarmail_id']})
|
qm_db = self.db.get_quarmail({"id": args['quarmail_id']})
|
||||||
@ -296,12 +298,13 @@ class Gulag:
|
|||||||
imap_mb = None
|
imap_mb = None
|
||||||
try:
|
try:
|
||||||
imap_mb = IMAPmailbox(mailbox)
|
imap_mb = IMAPmailbox(mailbox)
|
||||||
mparts = imap_mb.get_main_parts(qm_db['imap_uid'])
|
|
||||||
uris = []
|
uris = []
|
||||||
uri_pattern = r'(https?:\/\/[^\s<>"]+)'
|
for part in imap_mb.get_main_parts(qm_db['imap_uid']):
|
||||||
for part in mparts:
|
for uri in extract_uris(part.decode("utf-8")):
|
||||||
for m in re.finditer(uri_pattern, part.decode("utf-8")):
|
uris.append({
|
||||||
uris.append(m.group(0))
|
"uri": uri,
|
||||||
|
"fqdn": extract_fqdn(uri)
|
||||||
|
})
|
||||||
return uris
|
return uris
|
||||||
except IMAPmailboxException as e:
|
except IMAPmailboxException as e:
|
||||||
logging.warning(whoami(self) + e.message)
|
logging.warning(whoami(self) + e.message)
|
||||||
|
|||||||
@ -363,3 +363,5 @@ definitions:
|
|||||||
type: string
|
type: string
|
||||||
fqdn:
|
fqdn:
|
||||||
type: string
|
type: string
|
||||||
|
href:
|
||||||
|
type: string
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user