Auto-register for email gateway if necessary

If attempting to send to an email address from an unregistered
account, auto-send registration to mailchuck.
Use label if possible, otherwise random 12 characater address

Fixes #131
This commit is contained in:
Peter Šurda 2015-12-02 23:12:38 +01:00
parent 082eb823bb
commit bdfaa90ecb

View File

@ -52,7 +52,9 @@ import pickle
import platform import platform
import textwrap import textwrap
import debug import debug
import random
import subprocess import subprocess
import string
import datetime import datetime
from helper_sql import * from helper_sql import *
import l10n import l10n
@ -2185,12 +2187,24 @@ class MyForm(settingsmixin.SMainWindow):
toAddressesList)) # remove duplicate addresses. If the user has one address with a BM- and the same address without the BM-, this will not catch it. They'll send the message to the person twice. toAddressesList)) # remove duplicate addresses. If the user has one address with a BM- and the same address without the BM-, this will not catch it. They'll send the message to the person twice.
for toAddress in toAddressesList: for toAddress in toAddressesList:
if toAddress != '': if toAddress != '':
if toAddress.find("@") >= 0 and isinstance(acct, GatewayAccount): if toAddress.find("@") >= 0:
acct.createMessage(toAddress, fromAddress, subject, message) if isinstance(acct, GatewayAccount):
subject = acct.subject acct.createMessage(toAddress, fromAddress, subject, message)
toAddress = acct.toAddress subject = acct.subject
logger.debug("Subject: %s" % (subject)) toAddress = acct.toAddress
logger.debug("address: %s" % (toAddress)) else:
email = acct.getLabel()
if email[-14:] != "@mailchuck.com": #attempt register
# 12 character random email address
email = ''.join(random.SystemRandom().choice(string.ascii_lowercase) for _ in range(12)) + "@mailchuck.com"
acct = MailchuckAccount(fromAddress)
acct.register(email)
shared.config.set(fromAddress, 'label', email)
shared.config.set(fromAddress, 'gateway', 'mailchuck')
shared.writeKeysFile()
self.statusBar().showMessage(_translate(
"MainWindow", "Error: Your account wasn't registered at an email gateway. Sending registration now as %1, please wait for the registration to be processed before retrying sending.").arg(email))
return
status, addressVersionNumber, streamNumber, ripe = decodeAddress( status, addressVersionNumber, streamNumber, ripe = decodeAddress(
toAddress) toAddress)
if status != 'success': if status != 'success':