Supporting broadcasts and delivery to specific recipients

This commit is contained in:
Chuck 2013-07-10 20:24:33 +07:00
parent cccb043b67
commit ebce2e29dd
8 changed files with 834 additions and 702 deletions

View File

@ -1259,12 +1259,12 @@ class MyForm(QtGui.QMainWindow):
self.ui.tableWidgetSubscriptions.setRowCount(0)
shared.sqlLock.acquire()
shared.sqlSubmitQueue.put(
'SELECT label, address, enabled FROM subscriptions')
'SELECT label, address, receiving_identity, enabled FROM subscriptions')
shared.sqlSubmitQueue.put('')
queryreturn = shared.sqlReturnQueue.get()
shared.sqlLock.release()
for row in queryreturn:
label, address, enabled = row
label, address, receivingIdentity, enabled = row
self.ui.tableWidgetSubscriptions.insertRow(0)
newItem = QtGui.QTableWidgetItem(unicode(label, 'utf-8'))
if not enabled:
@ -1276,6 +1276,10 @@ class MyForm(QtGui.QMainWindow):
if not enabled:
newItem.setTextColor(QtGui.QColor(128, 128, 128))
self.ui.tableWidgetSubscriptions.setItem(0, 1, newItem)
newItem = QtGui.QTableWidgetItem(unicode(receivingIdentity, 'utf-8'))
newItem.setFlags(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
self.ui.tableWidgetSubscriptions.setItem(0, 2, newItem)
def click_pushButtonSend(self):
self.statusBar().showMessage('')
@ -1656,7 +1660,7 @@ class MyForm(QtGui.QMainWindow):
self.statusBar().showMessage(_translate(
"MainWindow", "The address you entered was invalid. Ignoring it."))
def addSubscription(self, label, address):
def addSubscription(self, label, address, receivingIdentity):
address = addBMIfNotPresent(address)
#This should be handled outside of this function, for error displaying and such, but it must also be checked here.
if shared.isAddressInMySubscriptionsList(address):
@ -1669,11 +1673,14 @@ class MyForm(QtGui.QMainWindow):
newItem = QtGui.QTableWidgetItem(address)
newItem.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled )
self.ui.tableWidgetSubscriptions.setItem(0,1,newItem)
newItem = QtGui.QTableWidgetItem(unicode(receivingIdentity, 'utf-8'))
newItem.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled )
self.ui.tableWidgetSubscriptions.setItem(0,2,newItem)
self.ui.tableWidgetSubscriptions.setSortingEnabled(True)
#Add to database (perhaps this should be separated from the MyForm class)
t = (str(label),address,True)
t = (str(label),address,receivingIdentity,True)
shared.sqlLock.acquire()
shared.sqlSubmitQueue.put('''INSERT INTO subscriptions VALUES (?,?,?)''')
shared.sqlSubmitQueue.put('''INSERT INTO subscriptions (label, address, receiving_identity, enabled) VALUES (?,?,?,?)''')
shared.sqlSubmitQueue.put(t)
queryreturn = shared.sqlReturnQueue.get()
shared.sqlSubmitQueue.put('commit')
@ -1682,7 +1689,7 @@ class MyForm(QtGui.QMainWindow):
shared.reloadBroadcastSendersForWhichImWatching()
def click_pushButtonAddSubscription(self):
self.NewSubscriptionDialogInstance = NewSubscriptionDialog(self)
self.NewSubscriptionDialogInstance = NewSubscriptionDialog(self, True)
if self.NewSubscriptionDialogInstance.exec_():
if self.NewSubscriptionDialogInstance.ui.labelSubscriptionAddressCheck.text() != _translate("MainWindow", "Address is valid."):
self.statusBar().showMessage(_translate("MainWindow", "The address you entered was invalid. Ignoring it."))
@ -1693,7 +1700,9 @@ class MyForm(QtGui.QMainWindow):
self.statusBar().showMessage(_translate("MainWindow", "Error: You cannot add the same address to your subsciptions twice. Perhaps rename the existing one if you want."))
return
label = self.NewSubscriptionDialogInstance.ui.newsubscriptionlabel.text().toUtf8()
self.addSubscription(label, address)
comboBoxIndex = self.NewSubscriptionDialogInstance.ui.comboBoxReceivingIdentity.currentIndex()
receivingIdentity = str(self.NewSubscriptionDialogInstance.ui.comboBoxReceivingIdentity.itemData(comboBoxIndex).toPyObject())
self.addSubscription(label, address, receivingIdentity)
def loadBlackWhiteList(self):
# Initialize the Blacklist or Whitelist table
@ -2321,7 +2330,7 @@ class MyForm(QtGui.QMainWindow):
self.statusBar().showMessage(QtGui.QApplication.translate("MainWindow", "Error: You cannot add the same address to your subsciptions twice. Perhaps rename the existing one if you want."))
continue
labelAtCurrentRow = self.ui.tableWidgetAddressBook.item(currentRow,0).text().toUtf8()
self.addSubscription(labelAtCurrentRow, addressAtCurrentRow)
self.addSubscription(labelAtCurrentRow, addressAtCurrentRow, '') # TODO
self.ui.tabWidget.setCurrentIndex(4)
def on_context_menuAddressBook(self, point):
@ -2339,10 +2348,12 @@ class MyForm(QtGui.QMainWindow):
currentRow, 0).text().toUtf8()
addressAtCurrentRow = self.ui.tableWidgetSubscriptions.item(
currentRow, 1).text()
t = (str(labelAtCurrentRow), str(addressAtCurrentRow))
receivingIdentity = self.ui.tableWidgetSubscriptions.item(
currentRow, 2).text()
t = (str(labelAtCurrentRow), str(addressAtCurrentRow), str(receivingIdentity))
shared.sqlLock.acquire()
shared.sqlSubmitQueue.put(
'''DELETE FROM subscriptions WHERE label=? AND address=?''')
'''DELETE FROM subscriptions WHERE label=? AND address=? AND receiving_identity=?''')
shared.sqlSubmitQueue.put(t)
shared.sqlReturnQueue.get()
shared.sqlSubmitQueue.put('commit')
@ -2364,18 +2375,19 @@ class MyForm(QtGui.QMainWindow):
currentRow, 0).text().toUtf8()
addressAtCurrentRow = self.ui.tableWidgetSubscriptions.item(
currentRow, 1).text()
t = (str(labelAtCurrentRow), str(addressAtCurrentRow))
receivingIdentity = self.ui.tableWidgetSubscriptions.item(
currentRow, 2).text()
t = (str(labelAtCurrentRow), str(addressAtCurrentRow), str(receivingIdentity))
shared.sqlLock.acquire()
shared.sqlSubmitQueue.put(
'''update subscriptions set enabled=1 WHERE label=? AND address=?''')
'''update subscriptions set enabled=1 WHERE label=? AND address=? AND receiving_identity=?''')
shared.sqlSubmitQueue.put(t)
shared.sqlReturnQueue.get()
shared.sqlSubmitQueue.put('commit')
shared.sqlLock.release()
self.ui.tableWidgetSubscriptions.item(
currentRow, 0).setTextColor(QtGui.QColor(0, 0, 0))
self.ui.tableWidgetSubscriptions.item(
currentRow, 1).setTextColor(QtGui.QColor(0, 0, 0))
for i in range(3):
self.ui.tableWidgetSubscriptions.item(
currentRow, i).setTextColor(QtGui.QColor(0, 0, 0))
shared.reloadBroadcastSendersForWhichImWatching()
def on_action_SubscriptionsDisable(self):
@ -2384,18 +2396,19 @@ class MyForm(QtGui.QMainWindow):
currentRow, 0).text().toUtf8()
addressAtCurrentRow = self.ui.tableWidgetSubscriptions.item(
currentRow, 1).text()
t = (str(labelAtCurrentRow), str(addressAtCurrentRow))
receivingIdentity = self.ui.tableWidgetSubscriptions.item(
currentRow, 2).text()
t = (str(labelAtCurrentRow), str(addressAtCurrentRow), str(receivingIdentity))
shared.sqlLock.acquire()
shared.sqlSubmitQueue.put(
'''update subscriptions set enabled=0 WHERE label=? AND address=?''')
'''update subscriptions set enabled=0 WHERE label=? AND address=? AND receiving_identity=?''')
shared.sqlSubmitQueue.put(t)
shared.sqlReturnQueue.get()
shared.sqlSubmitQueue.put('commit')
shared.sqlLock.release()
self.ui.tableWidgetSubscriptions.item(
currentRow, 0).setTextColor(QtGui.QColor(128, 128, 128))
self.ui.tableWidgetSubscriptions.item(
currentRow, 1).setTextColor(QtGui.QColor(128, 128, 128))
for i in range(3):
self.ui.tableWidgetSubscriptions.item(
currentRow, i).setTextColor(QtGui.QColor(128, 128, 128))
shared.reloadBroadcastSendersForWhichImWatching()
def on_context_menuSubscriptions(self, point):
@ -2651,10 +2664,12 @@ class MyForm(QtGui.QMainWindow):
if currentRow >= 0:
addressAtCurrentRow = self.ui.tableWidgetSubscriptions.item(
currentRow, 1).text()
receivingIdentity = self.ui.tableWidgetSubscriptions.item(
currentRow, 2).text()
t = (str(self.ui.tableWidgetSubscriptions.item(
currentRow, 0).text().toUtf8()), str(addressAtCurrentRow))
currentRow, 0).text().toUtf8()), str(addressAtCurrentRow), str(receivingIdentity))
shared.sqlSubmitQueue.put(
'''UPDATE subscriptions set label=? WHERE address=?''')
'''UPDATE subscriptions set label=? WHERE address=? AND receiving_identity=?''')
shared.sqlSubmitQueue.put(t)
shared.sqlReturnQueue.get()
shared.sqlSubmitQueue.put('commit')
@ -3027,7 +3042,7 @@ class SpecialAddressBehaviorDialog(QtGui.QDialog):
class NewSubscriptionDialog(QtGui.QDialog):
def __init__(self, parent):
def __init__(self, parent, showReceivingIdentity=False):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_NewSubscriptionDialog()
self.ui.setupUi(self)
@ -3035,6 +3050,29 @@ class NewSubscriptionDialog(QtGui.QDialog):
QtCore.QObject.connect(self.ui.lineEditSubscriptionAddress, QtCore.SIGNAL(
"textChanged(QString)"), self.subscriptionAddressChanged)
if showReceivingIdentity:
self.ui.label_3.setVisible(True)
self.ui.comboBoxReceivingIdentity.setVisible(True)
configSections = shared.config.sections()
for addressInKeysFile in configSections:
if addressInKeysFile != 'bitmessagesettings':
status, addressVersionNumber, streamNumber, hash = decodeAddress(
addressInKeysFile)
if status != 'success':
continue
isEnabled = shared.config.getboolean(
addressInKeysFile, 'enabled')
if not isEnabled:
continue
self.ui.comboBoxReceivingIdentity.insertItem(0, unicode("{} - {}".format(shared.config.get(
addressInKeysFile, 'label'), addressInKeysFile), 'utf-8'), addressInKeysFile)
else:
self.ui.label_3.setVisible(False)
self.ui.comboBoxReceivingIdentity.setVisible(False)
def subscriptionAddressChanged(self, QString):
status, a, b, c = decodeAddress(str(QString))
if status == 'missingbm':

View File

@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'bitmessageui.ui'
#
# Created: Thu Jun 13 01:02:50 2013
# Created: Wed Jul 10 18:36:45 2013
# by: PyQt4 UI code generator 4.10.1
#
# WARNING! All changes made in this file will be lost!
@ -246,14 +246,16 @@ class Ui_MainWindow(object):
self.tableWidgetSubscriptions.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
self.tableWidgetSubscriptions.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
self.tableWidgetSubscriptions.setObjectName(_fromUtf8("tableWidgetSubscriptions"))
self.tableWidgetSubscriptions.setColumnCount(2)
self.tableWidgetSubscriptions.setColumnCount(3)
self.tableWidgetSubscriptions.setRowCount(0)
item = QtGui.QTableWidgetItem()
self.tableWidgetSubscriptions.setHorizontalHeaderItem(0, item)
item = QtGui.QTableWidgetItem()
self.tableWidgetSubscriptions.setHorizontalHeaderItem(1, item)
item = QtGui.QTableWidgetItem()
self.tableWidgetSubscriptions.setHorizontalHeaderItem(2, item)
self.tableWidgetSubscriptions.horizontalHeader().setCascadingSectionResizes(True)
self.tableWidgetSubscriptions.horizontalHeader().setDefaultSectionSize(400)
self.tableWidgetSubscriptions.horizontalHeader().setDefaultSectionSize(245)
self.tableWidgetSubscriptions.horizontalHeader().setHighlightSections(False)
self.tableWidgetSubscriptions.horizontalHeader().setSortIndicatorShown(False)
self.tableWidgetSubscriptions.horizontalHeader().setStretchLastSection(True)
@ -518,6 +520,8 @@ class Ui_MainWindow(object):
item.setText(_translate("MainWindow", "Label", None))
item = self.tableWidgetSubscriptions.horizontalHeaderItem(1)
item.setText(_translate("MainWindow", "Address", None))
item = self.tableWidgetSubscriptions.horizontalHeaderItem(2)
item.setText(_translate("MainWindow", "Receiving Identity", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.subscriptions), _translate("MainWindow", "Subscriptions", None))
self.label_6.setText(_translate("MainWindow", "The Address book is useful for adding names or labels to other people\'s Bitmessage addresses so that you can recognize them more easily in your inbox. You can add entries here using the \'Add\' button, or from your inbox by right-clicking on a message.", None))
self.pushButtonAddAddressBook.setText(_translate("MainWindow", "Add new entry", None))
@ -559,13 +563,3 @@ class Ui_MainWindow(object):
self.actionDeleteAllTrashedMessages.setText(_translate("MainWindow", "Delete all trashed messages", None))
import bitmessage_icons_rc
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
MainWindow = QtGui.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())

View File

@ -535,7 +535,7 @@ p, li { white-space: pre-wrap; }
<bool>true</bool>
</attribute>
<attribute name="horizontalHeaderDefaultSectionSize">
<number>400</number>
<number>245</number>
</attribute>
<attribute name="horizontalHeaderHighlightSections">
<bool>false</bool>
@ -559,6 +559,11 @@ p, li { white-space: pre-wrap; }
<string>Address</string>
</property>
</column>
<column>
<property name="text">
<string>Receiving Identity</string>
</property>
</column>
</widget>
</item>
</layout>

View File

@ -2,8 +2,8 @@
# Form implementation generated from reading ui file 'newsubscriptiondialog.ui'
#
# Created: Fri Oct 19 15:30:41 2012
# by: PyQt4 UI code generator 4.9.4
# Created: Wed Jul 10 18:56:32 2013
# by: PyQt4 UI code generator 4.10.1
#
# WARNING! All changes made in this file will be lost!
@ -12,12 +12,21 @@ from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_NewSubscriptionDialog(object):
def setupUi(self, NewSubscriptionDialog):
NewSubscriptionDialog.setObjectName(_fromUtf8("NewSubscriptionDialog"))
NewSubscriptionDialog.resize(368, 192)
NewSubscriptionDialog.resize(413, 208)
self.formLayout = QtGui.QFormLayout(NewSubscriptionDialog)
self.formLayout.setFieldGrowthPolicy(QtGui.QFormLayout.AllNonFixedFieldsGrow)
self.formLayout.setObjectName(_fromUtf8("formLayout"))
@ -35,18 +44,24 @@ class Ui_NewSubscriptionDialog(object):
self.lineEditSubscriptionAddress = QtGui.QLineEdit(NewSubscriptionDialog)
self.lineEditSubscriptionAddress.setObjectName(_fromUtf8("lineEditSubscriptionAddress"))
self.formLayout.setWidget(5, QtGui.QFormLayout.SpanningRole, self.lineEditSubscriptionAddress)
self.buttonBox = QtGui.QDialogButtonBox(NewSubscriptionDialog)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
self.buttonBox.setObjectName(_fromUtf8("buttonBox"))
self.formLayout.setWidget(8, QtGui.QFormLayout.FieldRole, self.buttonBox)
spacerItem1 = QtGui.QSpacerItem(20, 10, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
self.formLayout.setItem(7, QtGui.QFormLayout.FieldRole, spacerItem1)
self.labelSubscriptionAddressCheck = QtGui.QLabel(NewSubscriptionDialog)
self.labelSubscriptionAddressCheck.setText(_fromUtf8(""))
self.labelSubscriptionAddressCheck.setWordWrap(True)
self.labelSubscriptionAddressCheck.setObjectName(_fromUtf8("labelSubscriptionAddressCheck"))
self.formLayout.setWidget(6, QtGui.QFormLayout.SpanningRole, self.labelSubscriptionAddressCheck)
self.buttonBox = QtGui.QDialogButtonBox(NewSubscriptionDialog)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
self.buttonBox.setObjectName(_fromUtf8("buttonBox"))
self.formLayout.setWidget(10, QtGui.QFormLayout.FieldRole, self.buttonBox)
spacerItem1 = QtGui.QSpacerItem(20, 10, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
self.formLayout.setItem(9, QtGui.QFormLayout.SpanningRole, spacerItem1)
self.comboBoxReceivingIdentity = QtGui.QComboBox(NewSubscriptionDialog)
self.comboBoxReceivingIdentity.setObjectName(_fromUtf8("comboBoxReceivingIdentity"))
self.formLayout.setWidget(8, QtGui.QFormLayout.SpanningRole, self.comboBoxReceivingIdentity)
self.label_3 = QtGui.QLabel(NewSubscriptionDialog)
self.label_3.setObjectName(_fromUtf8("label_3"))
self.formLayout.setWidget(7, QtGui.QFormLayout.LabelRole, self.label_3)
self.retranslateUi(NewSubscriptionDialog)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), NewSubscriptionDialog.accept)
@ -54,7 +69,8 @@ class Ui_NewSubscriptionDialog(object):
QtCore.QMetaObject.connectSlotsByName(NewSubscriptionDialog)
def retranslateUi(self, NewSubscriptionDialog):
NewSubscriptionDialog.setWindowTitle(QtGui.QApplication.translate("NewSubscriptionDialog", "Add new entry", None, QtGui.QApplication.UnicodeUTF8))
self.label_2.setText(QtGui.QApplication.translate("NewSubscriptionDialog", "Label", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("NewSubscriptionDialog", "Address", None, QtGui.QApplication.UnicodeUTF8))
NewSubscriptionDialog.setWindowTitle(_translate("NewSubscriptionDialog", "Add new entry", None))
self.label_2.setText(_translate("NewSubscriptionDialog", "Label", None))
self.label.setText(_translate("NewSubscriptionDialog", "Address", None))
self.label_3.setText(_translate("NewSubscriptionDialog", "Receiving Identity", None))

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>368</width>
<height>192</height>
<width>413</width>
<height>208</height>
</rect>
</property>
<property name="windowTitle">
@ -50,7 +50,17 @@
<item row="5" column="0" colspan="2">
<widget class="QLineEdit" name="lineEditSubscriptionAddress"/>
</item>
<item row="8" column="1">
<item row="6" column="0" colspan="2">
<widget class="QLabel" name="labelSubscriptionAddressCheck">
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="10" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -60,7 +70,7 @@
</property>
</widget>
</item>
<item row="7" column="1">
<item row="9" column="0" colspan="2">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -73,13 +83,13 @@
</property>
</spacer>
</item>
<item row="6" column="0" colspan="2">
<widget class="QLabel" name="labelSubscriptionAddressCheck">
<item row="8" column="0" colspan="2">
<widget class="QComboBox" name="comboBoxReceivingIdentity"/>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>
<string>Receiving Identity</string>
</property>
</widget>
</item>

View File

@ -293,7 +293,7 @@ class bitmessagePOP3Server(asyncore.dispatcher):
_ = bitmessagePOP3Connection(sock, peer_address, debug=self.debug)
@staticmethod
def reformatMessageForReceipt(toAddress, fromAddress, body, subject):
def reformatMessageForReceipt(toAddress, fromAddress, body, subject, broadcast=False):
message = parser.Parser().parsestr(body)
with shared.printLock:
print(message)
@ -310,7 +310,8 @@ class bitmessagePOP3Server(asyncore.dispatcher):
# Checksum to make sure incoming message hasn't been tampered with
c = hashlib.sha256(body).digest()[:2]
c = (ord(checksum[0]) << 8) | ord(checksum[1])
#c = (ord(checksum[0]) << 8) | ord(checksum[1])
print(c, checksum)
# Valid Bitmessage subject line already
if c == checksum:
@ -323,33 +324,58 @@ class bitmessagePOP3Server(asyncore.dispatcher):
if 'Date' in message and 'From' in message:
body_is_valid = True
if not body_is_valid:
fromLabel = '{}@{}'.format(getBase58Capitaliation(fromAddress), fromAddress)
t = (fromAddress,)
mailingListName = None
if broadcast:
# Determine a mailing list label, just in case
with shared.sqlLock:
t = (fromAddress,toAddress)
shared.sqlSubmitQueue.put(
'''SELECT label FROM addressbook WHERE address=?''')
'''SELECT label FROM subscriptions WHERE address=? AND receiving_identity=?''')
shared.sqlSubmitQueue.put(t)
queryreturn = shared.sqlReturnQueue.get()
for row in queryreturn:
fromLabel = '{} <{}>'.format(row[0], fromLabel)
mailingListName = row[0]
break
if not body_is_valid:
fromLabel = '{}@{}'.format(getBase58Capitaliation(fromAddress), fromAddress)
if broadcast and mailingListName is not None:
fromLabel = '{} <{}>'.format(mailingListName, fromLabel)
else:
with shared.sqlLock:
t = (fromAddress,)
shared.sqlSubmitQueue.put(
'''SELECT label FROM addressbook WHERE address=?''')
shared.sqlSubmitQueue.put(t)
queryreturn = shared.sqlReturnQueue.get()
for row in queryreturn:
fromLabel = '{} <{}>'.format(row[0], fromLabel)
break
message['From'] = fromLabel
message['Date'] = utils.formatdate()
message['Date'] = utils.formatdate(localtime=False)
message['X-Bitmessage-Subject'] = subject
if not subject_is_valid and 'Subject' not in message:
message['Subject'] = subject
if mailingListName is not None:
message['Subject'] = bitmessagePOP3Server.addMailingListNameToSubject(subject, mailingListName)
else:
message['Subject'] = subject
toLabel = '{}@{}'.format(getBase58Capitaliation(toAddress), toAddress)
try:
toLabel = '{} <{}>'.format(shared.config.get(toAddress, 'label'), toLabel)
except:
pass
if broadcast:
# The To: field on a broadcast is the mailing list, not you
toLabel = '{}@{}'.format(getBase58Capitaliation(fromAddress), fromAddress)
if mailingListName is not None:
toLabel = '{} <{}>'.format(mailingListName, toLabel)
message['To'] = toLabel
elif 'To' not in message:
toLabel = '{}@{}'.format(getBase58Capitaliation(toAddress), toAddress)
try:
toLabel = '{} <{}>'.format(shared.config.get(toAddress, 'label'), toLabel)
except:
pass
if "To" not in message:
message['To'] = toLabel
# Return-Path

View File

@ -702,27 +702,58 @@ class receiveDataThread(threading.Thread):
body = 'Unknown encoding type.\n\n' + repr(message)
subject = ''
toAddress = '[Broadcast subscribers]'
if messageEncodingType != 0:
t = (fromAddress,)
shared.sqlLock.acquire()
shared.sqlSubmitQueue.put(
'''SELECT receiving_identity FROM subscriptions WHERE address=?''')
shared.sqlSubmitQueue.put(t)
queryreturn = shared.sqlReturnQueue.get()
shared.sqlLock.release()
t = (self.inventoryHash, toAddress, fromAddress, subject, int(
time.time()), body, 'inbox', messageEncodingType, 0)
helper_inbox.insert(t)
print('queryreturn: {}'.format(queryreturn))
for row in queryreturn:
receivingIdentity, = row
shared.UISignalQueue.put(('displayNewInboxMessage', (
self.inventoryHash, toAddress, fromAddress, subject, body)))
if receivingIdentity == '':
toAddress = '[Broadcast subscribers]'
formattedBody = body
formattedSubject = subject
elif not shared.safeConfigGetBoolean(receivingIdentity, 'enabled'):
continue
else:
try:
isEmailAddress = shared.config.getboolean(receivingIdentity, 'foremail')
except:
isEmailAddress = False
# If we are behaving as an API then we might need to run an
# outside command to let some program know that a new message
# has arrived.
if shared.safeConfigGetBoolean('bitmessagesettings', 'apienabled'):
try:
apiNotifyPath = shared.config.get(
'bitmessagesettings', 'apinotifypath')
except:
apiNotifyPath = ''
if apiNotifyPath != '':
call([apiNotifyPath, "newBroadcast"])
# TODO - kinda stinks that the 'inbox' toAddress is used for both the recipient AND broadcast flag
toAddress = receivingIdentity
if isEmailAddress:
formattedBody, formattedSubject = bitmessagePOP3Server.reformatMessageForReceipt(receivingIdentity, fromAddress, body, subject, broadcast=True)
else:
formattedBody = body
formattedSubject = subject
t = (self.inventoryHash, toAddress, fromAddress, formattedSubject, int(
time.time()), formattedBody, 'inbox', messageEncodingType, 0)
helper_inbox.insert(t)
shared.UISignalQueue.put(('displayNewInboxMessage', (
self.inventoryHash, toAddress, fromAddress, formattedSubject, formattedBody)))
# If we are behaving as an API then we might need to run an
# outside command to let some program know that a new message
# has arrived.
if shared.safeConfigGetBoolean('bitmessagesettings', 'apienabled'):
try:
apiNotifyPath = shared.config.get(
'bitmessagesettings', 'apinotifypath')
except:
apiNotifyPath = ''
if apiNotifyPath != '':
call([apiNotifyPath, "newBroadcast"])
# Display timing data
with shared.printLock:

View File

@ -219,6 +219,18 @@ class sqlThread(threading.Thread):
parameters = (int(time.time()),)
self.cur.execute(item, parameters)
# We need a receiving identity in subscriptions table. This allows us to
# Route broadcast messages to a number of individual identities (some
# can be wrapped with E-mail, some can be left in the users inbox)
item = '''SELECT value FROM settings WHERE key='subscriptionidentities';'''
parameters = ''
self.cur.execute(item, parameters)
queryreturn = self.cur.fetchall()
if len(queryreturn) == 0:
print 'Modifying subscriptions table to include a receiving identity'
self.cur.execute('''ALTER TABLE subscriptions ADD COLUMN receiving_identity TEXT DEFAULT '';''')
self.cur.execute('''INSERT INTO settings (value, key) VALUES ('1', 'subscriptionidentities');''')
while True:
item = shared.sqlSubmitQueue.get()
if item == 'commit':