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
|
||||
if 'data' not in args:
|
||||
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):
|
||||
try:
|
||||
@ -599,6 +619,14 @@ class Gulag:
|
||||
except GulagDBException as 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):
|
||||
try:
|
||||
if 'id' not in uri:
|
||||
|
||||
@ -473,7 +473,7 @@ class GulagDB:
|
||||
query += " from QuarMail2Attachment"
|
||||
query += " left join QuarMails ON QuarMails.id = QuarMail2Attachment.quarmail_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)
|
||||
data = cursor.fetchall()
|
||||
if not data:
|
||||
@ -486,8 +486,7 @@ class GulagDB:
|
||||
for (name, value) in zip(desc, tuple):
|
||||
dict[name[0]] = value
|
||||
#dict['href'] = self.uri_prefixes['attachments'] + str(dict['id'])
|
||||
dict['href'] = self.uri_prefixes['quarmails'] + str(quarmail_id)
|
||||
dict['href'] += "/attachments/" + str(dict['id'])
|
||||
dict['href'] = self.uri_prefixes['attachments'] + str(dict['id'])
|
||||
return Attachment(dict).__dict__
|
||||
except mariadb.Error as e:
|
||||
raise GulagDBException(whoami(self) + str(e.msg)) from e
|
||||
@ -583,6 +582,29 @@ class GulagDB:
|
||||
except mariadb.Error as 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):
|
||||
try:
|
||||
cursor = self.conn.cursor()
|
||||
|
||||
@ -187,6 +187,8 @@ class ResAttachments(GulagResource):
|
||||
class ResAttachment(GulagResource):
|
||||
def get(self,attachment_id):
|
||||
args = {"id": attachment_id}
|
||||
if(request.args.get('data')):
|
||||
args['data'] = True
|
||||
try:
|
||||
return self.gulag.get_attachment(args)
|
||||
except GulagNotFoundException as e:
|
||||
@ -211,9 +213,8 @@ class ResAttachment(GulagResource):
|
||||
|
||||
class ResURI(GulagResource):
|
||||
def get(self,uri_id):
|
||||
args = {"id": uri_id}
|
||||
try:
|
||||
return self.gulag.get_uri(args)
|
||||
return self.gulag.get_uri(uri_id)
|
||||
except GulagNotFoundException as e:
|
||||
abort(404, message=whoami(self)+e.message)
|
||||
except GulagException as e:
|
||||
|
||||
@ -8,7 +8,8 @@ from Resources import (ResRoot,ResMailboxes,
|
||||
ResQuarMails,ResQuarMail,ResQuarMailAttachments,
|
||||
ResQuarMailAttachment,ResAttachments,ResAttachment,
|
||||
ResRspamd2Mailbox,ResQuarMailURIs,ResQuarMailURI,
|
||||
ResMailradar2Mailbox,ResQuarMailRelease,ResQuarMailBounce
|
||||
ResMailradar2Mailbox,ResQuarMailRelease,ResQuarMailBounce,
|
||||
ResURI
|
||||
)
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--config', required=True, help="Path to config file")
|
||||
@ -72,6 +73,10 @@ try:
|
||||
'/api/v1/attachments/<int:attachment_id>',
|
||||
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/v1/mailboxes/<string:mailbox_id>/rspamd2mailbox',
|
||||
resource_class_kwargs={'gulag_object': gulag}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user