mirror of
https://github.com/chillout2k/gulag.git
synced 2025-12-13 16:00:18 +00:00
get_attachment(id), get_uri(id) implemented
This commit is contained in:
parent
25dbedc06c
commit
437f2e2ac2
28
app/Gulag.py
28
app/Gulag.py
@ -533,6 +533,26 @@ class Gulag:
|
|||||||
raise GulagException(whoami(self) + e.message) from e
|
raise GulagException(whoami(self) + e.message) from e
|
||||||
if 'data' not in args:
|
if 'data' not in args:
|
||||||
return at_db
|
return at_db
|
||||||
|
# pull attachment from IMAP mailbox
|
||||||
|
mailbox = None
|
||||||
|
try:
|
||||||
|
mailbox = self.db.get_mailbox(at_db['mailbox_id'])
|
||||||
|
except GulagDBNotFoundException as e:
|
||||||
|
raise GulagNotFoundException(whoami(self) + e.message) from e
|
||||||
|
except GulagDBException as e:
|
||||||
|
logging.warning(whoami(self) + e.message)
|
||||||
|
raise GulagException(whoami(self) + e.message) from e
|
||||||
|
imap_mb = None
|
||||||
|
try:
|
||||||
|
imap_mb = IMAPmailbox(mailbox)
|
||||||
|
at_db['data'] = imap_mb.get_attachment(
|
||||||
|
at_db['imap_uid'],at_db['filename']
|
||||||
|
)
|
||||||
|
imap_mb.close
|
||||||
|
return at_db
|
||||||
|
except IMAPmailboxException as e:
|
||||||
|
logging.warning(whoami(self) + e.message)
|
||||||
|
raise GulagException(whoami(self) + e.message) from e
|
||||||
|
|
||||||
def modify_attachment(self, attachment):
|
def modify_attachment(self, attachment):
|
||||||
try:
|
try:
|
||||||
@ -599,6 +619,14 @@ class Gulag:
|
|||||||
except GulagDBException as e:
|
except GulagDBException as e:
|
||||||
raise GulagException(whoami(self) + e.message) from e
|
raise GulagException(whoami(self) + e.message) from e
|
||||||
|
|
||||||
|
def get_uri(self,uri_id):
|
||||||
|
try:
|
||||||
|
return self.db.get_uri(uri_id)
|
||||||
|
except GulagDBNotFoundException as e:
|
||||||
|
raise GulagNotFoundException(whoami(self) + e.message) from e
|
||||||
|
except GulagDBException as e:
|
||||||
|
raise GulagException(whoami(self) + e.message) from e
|
||||||
|
|
||||||
def modify_uri(self, uri):
|
def modify_uri(self, uri):
|
||||||
try:
|
try:
|
||||||
if 'id' not in uri:
|
if 'id' not in uri:
|
||||||
|
|||||||
@ -473,7 +473,7 @@ class GulagDB:
|
|||||||
query += " from QuarMail2Attachment"
|
query += " from QuarMail2Attachment"
|
||||||
query += " left join QuarMails ON QuarMails.id = QuarMail2Attachment.quarmail_id"
|
query += " left join QuarMails ON QuarMails.id = QuarMail2Attachment.quarmail_id"
|
||||||
query += " left join Attachments ON Attachments.id = QuarMail2Attachment.attachment_id"
|
query += " left join Attachments ON Attachments.id = QuarMail2Attachment.attachment_id"
|
||||||
query += " where id=" + str(args['id']) + ";"
|
query += " where attachment_id=" + str(args['id']) + ";"
|
||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
data = cursor.fetchall()
|
data = cursor.fetchall()
|
||||||
if not data:
|
if not data:
|
||||||
@ -486,8 +486,7 @@ class GulagDB:
|
|||||||
for (name, value) in zip(desc, tuple):
|
for (name, value) in zip(desc, tuple):
|
||||||
dict[name[0]] = value
|
dict[name[0]] = value
|
||||||
#dict['href'] = self.uri_prefixes['attachments'] + str(dict['id'])
|
#dict['href'] = self.uri_prefixes['attachments'] + str(dict['id'])
|
||||||
dict['href'] = self.uri_prefixes['quarmails'] + str(quarmail_id)
|
dict['href'] = self.uri_prefixes['attachments'] + str(dict['id'])
|
||||||
dict['href'] += "/attachments/" + str(dict['id'])
|
|
||||||
return Attachment(dict).__dict__
|
return Attachment(dict).__dict__
|
||||||
except mariadb.Error as e:
|
except mariadb.Error as e:
|
||||||
raise GulagDBException(whoami(self) + str(e.msg)) from e
|
raise GulagDBException(whoami(self) + str(e.msg)) from e
|
||||||
@ -583,6 +582,29 @@ class GulagDB:
|
|||||||
except mariadb.Error as e:
|
except mariadb.Error as e:
|
||||||
raise GulagDBException(whoami(self) + str(e.msg)) from e
|
raise GulagDBException(whoami(self) + str(e.msg)) from e
|
||||||
|
|
||||||
|
def get_uri(self,uri_id):
|
||||||
|
try:
|
||||||
|
query = "select * from URIs where id=" + str(uri_id) + ";"
|
||||||
|
cursor = self.conn.cursor()
|
||||||
|
cursor.execute(query)
|
||||||
|
data = cursor.fetchall()
|
||||||
|
if not data:
|
||||||
|
raise GulagDBNotFoundException(whoami(self) +
|
||||||
|
"URI(" + str(uri_id) + ") not found!"
|
||||||
|
)
|
||||||
|
desc = cursor.description
|
||||||
|
tuple = data[0]
|
||||||
|
dict = {}
|
||||||
|
for (name, value) in zip(desc, tuple):
|
||||||
|
dict[name[0]] = value
|
||||||
|
dict['href'] = self.uri_prefixes['uris'] + str(dict['id'])
|
||||||
|
try:
|
||||||
|
return URI(dict).__dict__
|
||||||
|
except URIException as e:
|
||||||
|
raise GulagDBException(whoami(self) + e.message) from e
|
||||||
|
except mariadb.Error as e:
|
||||||
|
raise GulagDBException(whoami(self) + str(e.msg)) from e
|
||||||
|
|
||||||
def modify_uri(self, uri):
|
def modify_uri(self, uri):
|
||||||
try:
|
try:
|
||||||
cursor = self.conn.cursor()
|
cursor = self.conn.cursor()
|
||||||
|
|||||||
@ -187,6 +187,8 @@ class ResAttachments(GulagResource):
|
|||||||
class ResAttachment(GulagResource):
|
class ResAttachment(GulagResource):
|
||||||
def get(self,attachment_id):
|
def get(self,attachment_id):
|
||||||
args = {"id": attachment_id}
|
args = {"id": attachment_id}
|
||||||
|
if(request.args.get('data')):
|
||||||
|
args['data'] = True
|
||||||
try:
|
try:
|
||||||
return self.gulag.get_attachment(args)
|
return self.gulag.get_attachment(args)
|
||||||
except GulagNotFoundException as e:
|
except GulagNotFoundException as e:
|
||||||
@ -211,9 +213,8 @@ class ResAttachment(GulagResource):
|
|||||||
|
|
||||||
class ResURI(GulagResource):
|
class ResURI(GulagResource):
|
||||||
def get(self,uri_id):
|
def get(self,uri_id):
|
||||||
args = {"id": uri_id}
|
|
||||||
try:
|
try:
|
||||||
return self.gulag.get_uri(args)
|
return self.gulag.get_uri(uri_id)
|
||||||
except GulagNotFoundException as e:
|
except GulagNotFoundException as e:
|
||||||
abort(404, message=whoami(self)+e.message)
|
abort(404, message=whoami(self)+e.message)
|
||||||
except GulagException as e:
|
except GulagException as e:
|
||||||
|
|||||||
@ -8,7 +8,8 @@ from Resources import (ResRoot,ResMailboxes,
|
|||||||
ResQuarMails,ResQuarMail,ResQuarMailAttachments,
|
ResQuarMails,ResQuarMail,ResQuarMailAttachments,
|
||||||
ResQuarMailAttachment,ResAttachments,ResAttachment,
|
ResQuarMailAttachment,ResAttachments,ResAttachment,
|
||||||
ResRspamd2Mailbox,ResQuarMailURIs,ResQuarMailURI,
|
ResRspamd2Mailbox,ResQuarMailURIs,ResQuarMailURI,
|
||||||
ResMailradar2Mailbox,ResQuarMailRelease,ResQuarMailBounce
|
ResMailradar2Mailbox,ResQuarMailRelease,ResQuarMailBounce,
|
||||||
|
ResURI
|
||||||
)
|
)
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('--config', required=True, help="Path to config file")
|
parser.add_argument('--config', required=True, help="Path to config file")
|
||||||
@ -72,6 +73,10 @@ try:
|
|||||||
'/api/v1/attachments/<int:attachment_id>',
|
'/api/v1/attachments/<int:attachment_id>',
|
||||||
resource_class_kwargs={'gulag_object': gulag}
|
resource_class_kwargs={'gulag_object': gulag}
|
||||||
)
|
)
|
||||||
|
api.add_resource(ResURI,
|
||||||
|
'/api/v1/uris/<int:uri_id>',
|
||||||
|
resource_class_kwargs={'gulag_object': gulag}
|
||||||
|
)
|
||||||
api.add_resource(ResRspamd2Mailbox,
|
api.add_resource(ResRspamd2Mailbox,
|
||||||
'/api/v1/mailboxes/<string:mailbox_id>/rspamd2mailbox',
|
'/api/v1/mailboxes/<string:mailbox_id>/rspamd2mailbox',
|
||||||
resource_class_kwargs={'gulag_object': gulag}
|
resource_class_kwargs={'gulag_object': gulag}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user