some adjustments to the way headers are built for old-style messages
This commit is contained in:
parent
ebce2e29dd
commit
1e3cd7fc88
|
@ -243,8 +243,11 @@ class bitmessagePOP3Connection(asyncore.dispatcher):
|
||||||
with shared.printLock:
|
with shared.printLock:
|
||||||
sys.stdout.write(str(msg) + ": " + str(content))
|
sys.stdout.write(str(msg) + ": " + str(content))
|
||||||
yield "+OK {} octets".format(msg['size'])
|
yield "+OK {} octets".format(msg['size'])
|
||||||
yield content['message']
|
#yield content['message']
|
||||||
yield '.'
|
# TODO - this is temporary until I come up with better organization for
|
||||||
|
# the responses.
|
||||||
|
self.sendline(content['message'], END='')
|
||||||
|
yield (bitmessagePOP3Connection.END + '.')
|
||||||
|
|
||||||
def handleDele(self, data):
|
def handleDele(self, data):
|
||||||
index = int(data.decode('ascii')) - 1
|
index = int(data.decode('ascii')) - 1
|
||||||
|
@ -294,11 +297,40 @@ class bitmessagePOP3Server(asyncore.dispatcher):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def reformatMessageForReceipt(toAddress, fromAddress, body, subject, broadcast=False):
|
def reformatMessageForReceipt(toAddress, fromAddress, body, subject, broadcast=False):
|
||||||
|
originalBody = body
|
||||||
|
ostensiblyFrom = None
|
||||||
|
if broadcast:
|
||||||
|
# Temporarily strip out the annoying 'message ostensibly from' to see if there are already headers
|
||||||
|
i = body.find('Message ostensibly from')
|
||||||
|
if i >= 0:
|
||||||
|
e = body.find(':\n\n')
|
||||||
|
if e >= i and '\n' not in body[i:e]:
|
||||||
|
line = body[:e]
|
||||||
|
body = body[e+3:]
|
||||||
|
i = line.rfind(' ')
|
||||||
|
if i >= 0:
|
||||||
|
testFromAddress = line[i+1:]
|
||||||
|
status, addressVersionNumber, streamNumber, ripe = decodeAddress(testFromAddress)
|
||||||
|
if status == 'success':
|
||||||
|
ostensiblyFrom = testFromAddress
|
||||||
|
|
||||||
message = parser.Parser().parsestr(body)
|
message = parser.Parser().parsestr(body)
|
||||||
|
|
||||||
|
body_is_valid = False
|
||||||
|
if 'Date' in message and 'From' in message:
|
||||||
|
body_is_valid = True
|
||||||
|
|
||||||
|
if broadcast and not body_is_valid:
|
||||||
|
# Let's keep the "ostensibly from" stuff since beneath it does not lie an internet message
|
||||||
|
body = originalBody
|
||||||
|
message = parser.Parser().parsestr(body)
|
||||||
|
if 'Date' in message and 'From' in message:
|
||||||
|
body_is_valid = True
|
||||||
|
|
||||||
|
print '--------'
|
||||||
with shared.printLock:
|
with shared.printLock:
|
||||||
print(message)
|
print(message)
|
||||||
|
print '--------'
|
||||||
subject_is_valid = False
|
|
||||||
|
|
||||||
i = subject.find('<Bitmessage Mail: ')
|
i = subject.find('<Bitmessage Mail: ')
|
||||||
if i >= 0:
|
if i >= 0:
|
||||||
|
@ -314,16 +346,10 @@ class bitmessagePOP3Server(asyncore.dispatcher):
|
||||||
print(c, checksum)
|
print(c, checksum)
|
||||||
|
|
||||||
# Valid Bitmessage subject line already
|
# Valid Bitmessage subject line already
|
||||||
if c == checksum:
|
if c != checksum:
|
||||||
subject_is_valid = True
|
|
||||||
else:
|
|
||||||
with shared.printLock:
|
with shared.printLock:
|
||||||
print 'Got E-Mail formatted message with incorrect checksum...'
|
print 'Got E-Mail formatted message with incorrect checksum...'
|
||||||
|
|
||||||
body_is_valid = False
|
|
||||||
if 'Date' in message and 'From' in message:
|
|
||||||
body_is_valid = True
|
|
||||||
|
|
||||||
mailingListName = None
|
mailingListName = None
|
||||||
if broadcast:
|
if broadcast:
|
||||||
# Determine a mailing list label, just in case
|
# Determine a mailing list label, just in case
|
||||||
|
@ -338,11 +364,17 @@ class bitmessagePOP3Server(asyncore.dispatcher):
|
||||||
break
|
break
|
||||||
|
|
||||||
if not body_is_valid:
|
if not body_is_valid:
|
||||||
|
if broadcast:
|
||||||
|
if ostensiblyFrom is not None:
|
||||||
|
fromLabel = '{}@{}'.format(getBase58Capitaliation(ostensiblyFrom), ostensiblyFrom)
|
||||||
|
# TODO - check address book?
|
||||||
|
else:
|
||||||
fromLabel = '{}@{}'.format(getBase58Capitaliation(fromAddress), fromAddress)
|
fromLabel = '{}@{}'.format(getBase58Capitaliation(fromAddress), fromAddress)
|
||||||
|
if mailingListName is not None:
|
||||||
if broadcast and mailingListName is not None:
|
|
||||||
fromLabel = '{} <{}>'.format(mailingListName, fromLabel)
|
fromLabel = '{} <{}>'.format(mailingListName, fromLabel)
|
||||||
else:
|
else:
|
||||||
|
fromLabel = '{}@{}'.format(getBase58Capitaliation(fromAddress), fromAddress)
|
||||||
|
|
||||||
with shared.sqlLock:
|
with shared.sqlLock:
|
||||||
t = (fromAddress,)
|
t = (fromAddress,)
|
||||||
shared.sqlSubmitQueue.put(
|
shared.sqlSubmitQueue.put(
|
||||||
|
@ -357,9 +389,12 @@ class bitmessagePOP3Server(asyncore.dispatcher):
|
||||||
message['Date'] = utils.formatdate(localtime=False)
|
message['Date'] = utils.formatdate(localtime=False)
|
||||||
|
|
||||||
message['X-Bitmessage-Subject'] = subject
|
message['X-Bitmessage-Subject'] = subject
|
||||||
if not subject_is_valid and 'Subject' not in message:
|
|
||||||
|
if 'Subject' in message:
|
||||||
if mailingListName is not None:
|
if mailingListName is not None:
|
||||||
message['Subject'] = bitmessagePOP3Server.addMailingListNameToSubject(subject, mailingListName)
|
s = message['Subject']
|
||||||
|
del message['Subject']
|
||||||
|
message['Subject'] = bitmessagePOP3Server.addMailingListNameToSubject(s, mailingListName)
|
||||||
else:
|
else:
|
||||||
message['Subject'] = subject
|
message['Subject'] = subject
|
||||||
|
|
||||||
|
@ -368,7 +403,12 @@ class bitmessagePOP3Server(asyncore.dispatcher):
|
||||||
toLabel = '{}@{}'.format(getBase58Capitaliation(fromAddress), fromAddress)
|
toLabel = '{}@{}'.format(getBase58Capitaliation(fromAddress), fromAddress)
|
||||||
if mailingListName is not None:
|
if mailingListName is not None:
|
||||||
toLabel = '{} <{}>'.format(mailingListName, toLabel)
|
toLabel = '{} <{}>'.format(mailingListName, toLabel)
|
||||||
|
if 'To' in message:
|
||||||
|
del message['To']
|
||||||
message['To'] = toLabel
|
message['To'] = toLabel
|
||||||
|
if 'Reply-To' not in message:
|
||||||
|
del message['Reply-To']
|
||||||
|
message['Reply-To'] = toLabel
|
||||||
elif 'To' not in message:
|
elif 'To' not in message:
|
||||||
toLabel = '{}@{}'.format(getBase58Capitaliation(toAddress), toAddress)
|
toLabel = '{}@{}'.format(getBase58Capitaliation(toAddress), toAddress)
|
||||||
try:
|
try:
|
||||||
|
|
Reference in New Issue
Block a user