Пример #1
0
def retrieve_emails():
    try:
        email = request.query.email
        amount = strex.safeguard(request.query.amount, 1)
        
        if strex.is_none_or_empty(email):
            return {'error':'no email supplied'}

        if int(amount) < 1:
            amount = 1

        try:
            conn = None
            curs = None
            
            conn = sqlite3.connect(config.settings['database'])
            conn.row_factory = dict_factory
            curs = conn.cursor()

            sql = 'SELECT MailLogId, IPAddress, PortNumber, Subject, Sender, Recipients, Body, TimeStamp FROM MailLog WHERE Sender = ? ORDER BY MailLogId DESC LIMIT ?'
            curs.execute(sql, (email, amount,))
            values = curs.fetchall()
            
            curs.close()
            conn.close()

            if values is None:
                return '{}'
            return json.JSONEncoder().encode(values)
        except Exception as e:
            close_conn(curs, conn)
            return {'error':str(e)}
    except Exception as e:
        return {'error':str(e)}
Пример #2
0
def delete_email():
    try:
        mailLogId = strex.safeguard(request.query.mailLogId, 0)

        if int(mailLogId) <= 0:
            return {'error':'no mailLogId supplied'}

        try:
            conn = None
            curs = None
            
            conn = sqlite3.connect(config.settings['database'])
            curs = conn.cursor()
            
            sql = 'DELETE FROM MailLog WHERE MailLogId = ?'
            curs.execute(sql, (mailLogId,))

            conn.commit()
            curs.close()
            conn.close()
            return '{}'
        except Exception as e:
            close_conn(curs, conn)
            return {'error':str(e)}
    except Exception as e:
        return {'error':str(e)}
Пример #3
0
def retrieve_email():
    try:
        mailLogId = strex.safeguard(request.query.mailLogId, 0)

        if int(mailLogId) <= 0:
            return {'error':'no mailLogId supplied'}

        try:
            conn = None
            curs = None
            
            conn = sqlite3.connect(config.settings['database'])
            conn.row_factory = dict_factory
            curs = conn.cursor()
            
            sql = 'SELECT MailLogId, IPAddress, PortNumber, Subject, Sender, Recipients, Body, TimeStamp FROM MailLog WHERE MailLogId = ? ORDER BY MailLogId DESC LIMIT 1'
            curs.execute(sql, (mailLogId,))
            value = curs.fetchone()
            
            curs.close()
            conn.close()

            if value is None:
                return '{}'
            return json.JSONEncoder().encode(value)
        except Exception as e:
            close_conn(curs, conn)
            return {'error':str(e)}
    except Exception as e:
        return {'error':str(e)}
Пример #4
0
def create_email():
    try:
        ip = strex.safeguard(request.query.ip, '127.0.0.1')    
        port = strex.safeguard(request.query.port, '1234')
        subject = strex.safeguard(request.query.subject)
        body = strex.safeguard(request.query.body)
        
        sender = request.query.sender
        if strex.is_none_or_empty(sender):
            return {'error':'no sender supplied'}
        
        recipients = request.query.recipients
        if strex.is_none_or_empty(recipients):
            return {'error':'no recipients supplied'}

        try:
            conn = None
            curs = None
            
            conn = sqlite3.connect(config.settings['database'])
            conn.row_factory = dict_factory
            curs = conn.cursor()

            sql = 'INSERT INTO MailLog(IPAddress, PortNumber, Subject, Sender, Recipients, Body) VALUES (?, ?, ?, ?, ?, ?)'
            curs.execute(sql, (str(ip), str(port), str(subject), str(sender), str(recipients), str(body)))
            _id = curs.lastrowid

            sql = 'SELECT MailLogId, IPAddress, PortNumber, Subject, Sender, Recipients, Body, TimeStamp FROM MailLog WHERE MailLogId = ? ORDER BY MailLogId DESC LIMIT 1'
            curs.execute(sql, (_id,))
            value = curs.fetchone()
            
            conn.commit()
            curs.close()
            conn.close()
            return json.JSONEncoder().encode(value)
        except Exception as e:
            close_conn(curs, conn)
            return {'error':str(e)}
    except Exception as e:
        return {'error':str(e)}