Пример #1
0
def new():
    reciever = session['reply']
    session['reply'] = None
    dao = MailDao()
    length = dao.numInbox(session['userid'])
    if ('log' in request.form):
        session['userid'] = None
        return login()
    elif ('rec' in request.form):
        if (isValidUser(request.form['rec'])):
            num = dao.numMails()
            now = datetime.datetime.now(timezone('US/Eastern'))
            textMail = request.form['text']
            textMail = textMail.replace('\r\n', '<br>')
            mail = Mail(num, session['userid'], request.form['rec'],
                        request.form['subj'], textMail, 0, 0,
                        now.strftime("%m/%d/%Y %H:%M"))
            dao.insert(mail)
            session['mail'] = num
            return redirect(url_for('outbox'))
        else:
            num = dao.numMails()
            textMail = request.form['text']
            textMail = textMail.replace('\r\n', '<br>')
            text = "Mail you tried to send:<br>To: " + request.form[
                'rec'] + "<br>Subject: " + request.form[
                    'subj'] + "<br>" + textMail
            now = datetime.datetime.now(timezone('US/Eastern'))
            mail = Mail(num, 'System', session['userid'], "User doesn't exist",
                        text, 0, 0, now.strftime("%m/%d/%Y %H:%M"))
            dao.insert(mail)
            session['mail'] = num
            return redirect(url_for('inbox'))
    return render_template('new.html', **locals())
Пример #2
0
def trash():
    dao = MailDao()
    mails = dao.selectTrash(session['userid'])
    mails.reverse()
    mail = dao.selectById(request.form.get('ident', None))
    length = dao.numInbox(session['userid'])
    if ('log' in request.form):
        session['userid'] = None
        return redirect(url_for('login'))
    elif ('delete' in request.form):
        deleteMailTrash(request.form['delete'])
        return redirect(url_for('trash'))
    elif ('reply' in request.form):
        session['reply'] = request.form['reply']
        return redirect(url_for('new'))
    return render_template('trash.html', **locals())
Пример #3
0
def outbox():
    ident = request.form.get('ident', None)
    if (session['mail'] is not None):
        ident = session['mail']
    session['mail'] = None
    dao = MailDao()
    mails = dao.selectOutbox(session['userid'])
    mails.reverse()
    mail = dao.selectById(ident)
    length = dao.numInbox(session['userid'])
    if ('log' in request.form):
        session['userid'] = None
        return redirect(url_for('login'))
    elif ('delete' in request.form):
        deleteMailOut(request.form['delete'])
        return redirect(url_for('outbox'))
    return render_template('outbox.html', **locals())
Пример #4
0
def deleteMailTrash(ident):
    dao = MailDao()
    mail = dao.selectById(ident)
    mail.deletedInbox = 2
    dao.update(mail)
Пример #5
0
def deleteMailOut(ident):
    dao = MailDao()
    mail = dao.selectById(ident)
    mail.deletedOutbox = 1
    dao.update(mail)
Пример #6
0
def deleteMailIn(ident):
    dao = MailDao()
    mail = dao.selectById(ident)
    mail.deletedInbox = 1
    dao.update(mail)
Пример #7
0
from maildao import MailDao
from mail import Mail
from userdao import UserDao
from user import User
import os
import logging

FORMAT = "[%(filename)s:%(lineno)s - %(funcName)10s() ] %(message)s"
logging.basicConfig(filename='output.log', format=FORMAT)
logger = logging.getLogger('root')
logger.setLevel(logging.DEBUG)

os.remove('users.db')
dao = UserDao()
dao.populate()
users = dao.selectAll()
for user in users:
    print(user.toString())

os.remove('mails.db')
dao = MailDao()
dao.populate()
mails = dao.selectAll()
for mail in mails:
    print(mail.ident, mail.sender, mail.subject)