コード例 #1
0
ファイル: utils.py プロジェクト: henca887/wappy
def create_mail_account(user, parameters):
    """Constuct mail account from dictionary with parameters."""
    account = MailAccount()
    account.user = user
    account.name = parameters['name']

    incoming = MailTransportDetails()
    incoming.protocol = parameters['incoming_protocol']
    incoming.server_address = parameters['incoming_server_address']
    incoming.server_port = int(parameters['incoming_server_port'])
    incoming.username = parameters['incoming_username']
    incoming.password = parameters['incoming_password']
    incoming.save()
    account.incoming = incoming

    outgoing = MailTransportDetails()
    outgoing.protocol = parameters['outgoing_protocol']
    outgoing.server_address = parameters['outgoing_server_address']
    outgoing.server_port = int(parameters['outgoing_server_port'])
    outgoing.username = parameters['outgoing_username']
    outgoing.password = parameters['outgoing_password']
    outgoing.save()
    account.outgoing = outgoing

    account.save()

    return account
コード例 #2
0
ファイル: utils.py プロジェクト: henca887/wappy
def ensure_private_message_account_exists(user):
    account_name = '%s@wappy' % user.username
    try:
        user.mail_accounts.get(name=account_name)
    except:
        mail_account = MailAccount()
        mail_account.user = user
        mail_account.name = account_name
        incoming = MailTransportDetails()
        incoming.protocol = 'pm'
        incoming.save()
        mail_account.incoming = incoming
        outgoing = MailTransportDetails()
        outgoing.protocol = 'pm'
        outgoing.save()
        mail_account.outgoing = outgoing
        mail_account.save()
        inbox = MailFolder()
        inbox.account = mail_account
        inbox.path = 'Inbox'
        inbox.save()
        sent = MailFolder()
        sent.account = mail_account
        sent.path = 'Sent'
        sent.save()