Example #1
0
 def __init__(self, db, fields):
     """
         Initializes a new Message using a dictionary
         of database fields.
     """
     
     self.id = fields['intMessageId']
     
     if not 'intSenderId' in fields:
         
         sql = """
             SELECT
                 m.intSenderId,
                 m.datHappened,
                 m.strSummary,
                 r.intOnlyRecipient
             FROM mMessage m
                 LEFT JOIN (
                     SELECT intMessageId, MIN(intContactId) AS intOnlyRecipient
                     FROM mRecipient
                     GROUP BY intMessageId
                     HAVING COUNT(*) =1
                 ) r ON r.intMessageId = m.intId
             WHERE intId = ?"""
         
         row = db.executeOne(sql, self.id)
         fields['intSenderId'] = row['intSenderId']
         fields['datHappened'] = row['datHappened']
         fields['strSummary'] = row['strSummary']
     
     self.sender = contact.getContactFromId(db, fields['intSenderId'])
     self.sentDate = time.strptime(fields['datHappened'], '%Y-%m-%d %H:%M:%S')
     self.summary = fields['strSummary'].replace(u'\n', u'')
     if fields['strMessageType'] == 'imap':
         self.type = 'email'
     elif fields['strMessageType'] == 'iPhone SMS':
         self.type = 'SMS'
     elif fields['strMessageType'] == 'IM':
         self.type = 'IM'
     
     if len(self.summary) > 77:
         self.summary = self.summary[:77] + '...'
     
     if 'intOnlyRecipient' in fields and fields['intOnlyRecipient']:
         self.recipients = [contact.getContactFromId(db, fields['intOnlyRecipient'])]
     else:
         self.recipients = self.getRecipients(db)
Example #2
0
 def getRecipients(self, db):
     
     sql = """
         SELECT intContactId
         FROM mRecipient
         WHERE intMessageId = ?"""
     
     recipients = db.executeMany(sql, self.id)
     return [contact.getContactFromId(db, row['intContactId']) for row in recipients]
Example #3
0
 def __init__(self, db, conversation):
     ViewMessage.__init__(self, db, conversation)
     self.message = conversation
     self.message.getEntries(db)
     self.resize(800, 700)
     self.nextColour = None
     
     senders = {}
     
     maxDate = self.message.sentDate
     
     body = QTextEdit()
     for entry in self.message.entries:
         
         senderId = entry['intSenderId']
         if senderId in senders:
             sender, colour = senders[senderId]
         else:
             sender = contact.getContactFromId(db, senderId)
             colour = self.getNextColour()
             senders[senderId] = (sender, colour)
         
         dateSent = entry['datSent']
         
         if dateSent > maxDate:
             maxDate = dateSent
         
         dateSent = time.strftime('%Y-%m-%d %H:%M:%S', self.message.sentDate)
         
         sender = u"<b style='color: " + unicode(colour) + u"'>" + unicode(sender) + u'</b>: '
         sent = u'<i>' + unicode(dateSent) + u'</i>:'
         
         row = sender + sent + u'<br/>' + entry['strText'] + u'<br/>'
         
         row += u"<div style='height:20px; clear: both'></div>" 
         
         body.insertHtml(row)
     
     participants = u'Participants: '
     
     for id in senders:
         participants += unicode(senders[id][0]) + u', '
     
     self.senderLabel.setText(participants[:-2])
     self.sentLabel.setText('Between ' + time.strftime('%Y-%m-%d %H:%M:%S', self.message.sentDate) + \
         ' and ' + time.strftime('%Y-%m-%d %H:%M:%S', maxDate))
     
     body.setReadOnly(True)
     self.recipientsWidget.hide()
     
     grid = QGridLayout()
     grid.setSpacing(10)
     grid.addWidget(body, 0, 0)
     
     self.mainView.setLayout(grid)