Merge pull request #40 from navjotcis/newwork

worked on implementing sql query for sent and inbox on the bases of u…
This commit is contained in:
navjotcis 2019-10-04 16:47:23 +05:30 committed by GitHub
commit 410b35fbf4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 47 deletions

3
.gitignore vendored
View File

@ -19,4 +19,5 @@ docs/_*/*
docs/autodoc/ docs/autodoc/
pyan/ pyan/
.buildozer/ .buildozer/
bin/ bin/
src/images/default_identicon/

View File

@ -119,7 +119,7 @@ class Inbox(Screen):
'secondary_text': mail[5][:50] + '........' if len( 'secondary_text': mail[5][:50] + '........' if len(
mail[5]) >= 50 else ( mail[5]) >= 50 else (
mail[5] + ',' + mail[3].replace('\n', ''))[0:50] + '........', mail[5] + ',' + mail[3].replace('\n', ''))[0:50] + '........',
'receivedTime': mail[6]}) 'msgid': mail[1]})
for item in data: for item in data:
meny = TwoLineAvatarIconListItem( meny = TwoLineAvatarIconListItem(
text=item['text'], text=item['text'],
@ -130,7 +130,7 @@ class Inbox(Screen):
source='./images/text_images/{}.png'.format( source='./images/text_images/{}.png'.format(
avatarImageFirstLetter(item['secondary_text'].strip())))) avatarImageFirstLetter(item['secondary_text'].strip()))))
meny.bind(on_press=partial( meny.bind(on_press=partial(
self.inbox_detail, item['receivedTime'])) self.inbox_detail, item['msgid']))
carousel = Carousel(direction='right') carousel = Carousel(direction='right')
carousel.height = meny.height carousel.height = meny.height
carousel.size_hint_y = None carousel.size_hint_y = None
@ -141,13 +141,13 @@ class Inbox(Screen):
del_btn.background_normal = '' del_btn.background_normal = ''
del_btn.background_color = (1, 0, 0, 1) del_btn.background_color = (1, 0, 0, 1)
del_btn.bind(on_press=partial( del_btn.bind(on_press=partial(
self.delete, item['receivedTime'])) self.delete, item['msgid']))
carousel.add_widget(del_btn) carousel.add_widget(del_btn)
carousel.add_widget(meny) carousel.add_widget(meny)
ach_btn = Button(text='Achieve') ach_btn = Button(text='Achieve')
ach_btn.background_color = (0, 1, 0, 1) ach_btn.background_color = (0, 1, 0, 1)
ach_btn.bind(on_press=partial( ach_btn.bind(on_press=partial(
self.archive, item['receivedTime'])) self.archive, item['msgid']))
carousel.add_widget(ach_btn) carousel.add_widget(ach_btn)
carousel.index = 1 carousel.index = 1
self.ids.ml.add_widget(carousel) self.ids.ml.add_widget(carousel)
@ -163,10 +163,10 @@ class Inbox(Screen):
valign='top') valign='top')
self.ids.ml.add_widget(content) self.ids.ml.add_widget(content)
def inbox_detail(self, receivedTime, *args): def inbox_detail(self, msg_id, *args):
"""Load inbox page details.""" """Load inbox page details."""
state.detailPageType = 'inbox' state.detailPageType = 'inbox'
state.sentMailTime = receivedTime state.mail_id = msg_id
if self.manager: if self.manager:
src_mng_obj = self.manager src_mng_obj = self.manager
else: else:
@ -178,7 +178,7 @@ class Inbox(Screen):
def delete(self, data_index, instance, *args): def delete(self, data_index, instance, *args):
"""Delete inbox mail from inbox listing.""" """Delete inbox mail from inbox listing."""
sqlExecute( sqlExecute(
"UPDATE inbox SET folder = 'trash' WHERE received = {};".format( "UPDATE inbox SET folder = 'trash' WHERE msgid = ?;",str(
data_index)) data_index))
try: try:
msg_count_objs = \ msg_count_objs = \
@ -207,7 +207,7 @@ class Inbox(Screen):
def archive(self, data_index, instance, *args): def archive(self, data_index, instance, *args):
"""Archive inbox mail from inbox listing.""" """Archive inbox mail from inbox listing."""
sqlExecute( sqlExecute(
"UPDATE inbox SET folder = 'trash' WHERE received = {};".format( "UPDATE inbox SET folder = 'trash' WHERE msgid = ?;",str(
data_index)) data_index))
self.ids.ml.remove_widget(instance.parent.parent) self.ids.ml.remove_widget(instance.parent.parent)
self.update_trash() self.update_trash()
@ -465,15 +465,15 @@ class DropDownWidget(BoxLayout):
if status == 'success': if status == 'success':
if state.detailPageType == 'draft' and state.send_draft_mail: if state.detailPageType == 'draft' and state.send_draft_mail:
sqlExecute( sqlExecute(
"UPDATE sent SET toaddress = '{0}' \ "UPDATE sent SET toaddress = ? \
, fromaddress ='{1}' , subject = '{2}'\ , fromaddress = ? , subject = ?\
, message = '{3}', folder = 'sent'\ , message = ?, folder = 'sent'\
WHERE lastactiontime = '{4}';".format( WHERE ackdata = ?;",
toAddress, toAddress,
fromAddress, fromAddress,
subject, subject,
message, message,
state.send_draft_mail)) str(state.send_draft_mail))
self.parent.parent.screens[15].clear_widgets() self.parent.parent.screens[15].clear_widgets()
self.parent.parent.screens[15].add_widget(Draft()) self.parent.parent.screens[15].add_widget(Draft())
state.detailPageType = '' state.detailPageType = ''
@ -690,12 +690,12 @@ class Random(Screen):
label, 1, "", eighteenByteRipe, label, 1, "", eighteenByteRipe,
nonceTrialsPerByte, nonceTrialsPerByte,
payloadLengthExtraBytes)) payloadLengthExtraBytes))
self.manager.current = 'myaddress'
self.ids.label.text = '' self.ids.label.text = ''
self.parent.parent.parent.parent.ids.toolbar.opacity = 1 self.parent.parent.parent.parent.ids.toolbar.opacity = 1
self.parent.parent.parent.parent.ids.toolbar.disabled = False self.parent.parent.parent.parent.ids.toolbar.disabled = False
self.parent.parent.parent.parent.ids.sc10.ids.ml.clear_widgets() self.parent.parent.parent.parent.ids.sc10.ids.ml.clear_widgets()
self.parent.parent.parent.parent.ids.sc10.init_ui() self.parent.parent.parent.parent.ids.sc10.init_ui()
self.manager.current = 'myaddress'
toast('New address created') toast('New address created')
@ -752,7 +752,7 @@ class Sent(Screen):
'secondary_text': mail[2][:50] + '........' if len( 'secondary_text': mail[2][:50] + '........' if len(
mail[2]) >= 50 else ( mail[2]) >= 50 else (
mail[2] + ',' + mail[3].replace('\n', ''))[0:50] + '........', mail[2] + ',' + mail[3].replace('\n', ''))[0:50] + '........',
'lastactiontime': mail[6]}) 'ackdata': mail[5]})
for item in data: for item in data:
meny = TwoLineAvatarIconListItem( meny = TwoLineAvatarIconListItem(
text=item['text'], text=item['text'],
@ -763,7 +763,7 @@ class Sent(Screen):
source='./images/text_images/{}.png'.format( source='./images/text_images/{}.png'.format(
avatarImageFirstLetter(item['secondary_text'].strip())))) avatarImageFirstLetter(item['secondary_text'].strip()))))
meny.bind(on_press=partial( meny.bind(on_press=partial(
self.sent_detail, item['lastactiontime'])) self.sent_detail, item['ackdata']))
carousel = Carousel(direction='right') carousel = Carousel(direction='right')
carousel.height = meny.height carousel.height = meny.height
carousel.size_hint_y = None carousel.size_hint_y = None
@ -774,13 +774,13 @@ class Sent(Screen):
del_btn.background_normal = '' del_btn.background_normal = ''
del_btn.background_color = (1, 0, 0, 1) del_btn.background_color = (1, 0, 0, 1)
del_btn.bind(on_press=partial( del_btn.bind(on_press=partial(
self.delete, item['lastactiontime'])) self.delete, item['ackdata']))
carousel.add_widget(del_btn) carousel.add_widget(del_btn)
carousel.add_widget(meny) carousel.add_widget(meny)
ach_btn = Button(text='Achieve') ach_btn = Button(text='Achieve')
ach_btn.background_color = (0, 1, 0, 1) ach_btn.background_color = (0, 1, 0, 1)
ach_btn.bind(on_press=partial( ach_btn.bind(on_press=partial(
self.archive, item['lastactiontime'])) self.archive, item['ackdata']))
carousel.add_widget(ach_btn) carousel.add_widget(ach_btn)
carousel.index = 1 carousel.index = 1
self.ids.ml.add_widget(carousel) self.ids.ml.add_widget(carousel)
@ -796,10 +796,10 @@ class Sent(Screen):
valign='top') valign='top')
self.ids.ml.add_widget(content) self.ids.ml.add_widget(content)
def sent_detail(self, lastsenttime, *args): def sent_detail(self, ackdata, *args):
"""Load sent mail details.""" """Load sent mail details."""
state.detailPageType = 'sent' state.detailPageType = 'sent'
state.sentMailTime = lastsenttime state.mail_id = ackdata
if self.manager: if self.manager:
src_mng_obj = self.manager src_mng_obj = self.manager
else: else:
@ -828,7 +828,7 @@ class Sent(Screen):
state.all_count = str(int(state.all_count) - 1) state.all_count = str(int(state.all_count) - 1)
sqlExecute( sqlExecute(
"UPDATE sent SET folder = 'trash' \ "UPDATE sent SET folder = 'trash' \
WHERE lastactiontime = {};".format(data_index)) WHERE ackdata = ?;",str(data_index))
self.ids.ml.remove_widget(instance.parent.parent) self.ids.ml.remove_widget(instance.parent.parent)
toast('Deleted') toast('Deleted')
self.update_trash() self.update_trash()
@ -837,7 +837,7 @@ class Sent(Screen):
"""Archive sent mail from sent mail listing.""" """Archive sent mail from sent mail listing."""
sqlExecute( sqlExecute(
"UPDATE sent SET folder = 'trash' \ "UPDATE sent SET folder = 'trash' \
WHERE lastactiontime = {};".format(data_index)) WHERE ackdata = ?;",str(data_index))
self.ids.ml.remove_widget(instance.parent.parent) self.ids.ml.remove_widget(instance.parent.parent)
self.update_trash() self.update_trash()
@ -1422,8 +1422,7 @@ class MailDetail(Screen):
if state.detailPageType == 'sent' or state.detailPageType == 'draft': if state.detailPageType == 'sent' or state.detailPageType == 'draft':
data = sqlQuery( data = sqlQuery(
"select toaddress, fromaddress, subject, message, status, \ "select toaddress, fromaddress, subject, message, status, \
ackdata from sent where lastactiontime = {};".format( ackdata from sent where ackdata = ?;", state.mail_id)
state.sentMailTime))
state.status = self state.status = self
state.ackdata = data[0][5] state.ackdata = data[0][5]
self.assign_mail_details(data) self.assign_mail_details(data)
@ -1431,7 +1430,7 @@ class MailDetail(Screen):
elif state.detailPageType == 'inbox': elif state.detailPageType == 'inbox':
data = sqlQuery( data = sqlQuery(
"select toaddress, fromaddress, subject, message from inbox \ "select toaddress, fromaddress, subject, message from inbox \
where received = {};".format(state.sentMailTime)) where msgid = ?;",str(state.mail_id))
self.assign_mail_details(data) self.assign_mail_details(data)
state.kivyapp.set_mail_detail_header() state.kivyapp.set_mail_detail_header()
@ -1455,7 +1454,7 @@ class MailDetail(Screen):
if state.detailPageType == 'sent': if state.detailPageType == 'sent':
sqlExecute( sqlExecute(
"UPDATE sent SET folder = 'trash' WHERE \ "UPDATE sent SET folder = 'trash' WHERE \
lastactiontime = {};".format(state.sentMailTime)) ackdata = ?;", str(state.mail_id))
msg_count_objs.send_cnt.badge_text = str(int(state.sent_count) - 1) msg_count_objs.send_cnt.badge_text = str(int(state.sent_count) - 1)
state.sent_count = str(int(state.sent_count) - 1) state.sent_count = str(int(state.sent_count) - 1)
self.parent.screens[3].ids.ml.clear_widgets() self.parent.screens[3].ids.ml.clear_widgets()
@ -1463,15 +1462,12 @@ class MailDetail(Screen):
elif state.detailPageType == 'inbox': elif state.detailPageType == 'inbox':
sqlExecute( sqlExecute(
"UPDATE inbox SET folder = 'trash' WHERE \ "UPDATE inbox SET folder = 'trash' WHERE \
received = {};".format(state.sentMailTime)) msgid = ?;",str(state.mail_id))
# msg_count_objs.inbox_cnt.badge_text = str(
# int(state.inbox_count) - 1)
# state.inbox_count = str(int(state.inbox_count) - 1)
self.parent.screens[0].ids.ml.clear_widgets() self.parent.screens[0].ids.ml.clear_widgets()
self.parent.screens[0].loadMessagelist(state.association) self.parent.screens[0].loadMessagelist(state.association)
elif state.detailPageType == 'draft': elif state.detailPageType == 'draft':
sqlExecute("DELETE FROM sent WHERE lastactiontime = '{}';".format( sqlExecute("DELETE FROM sent WHERE ackdata = ?;",str(
state.sentMailTime)) state.mail_id))
msg_count_objs.draft_cnt.badge_text = str(int(state.draft_count) - 1) msg_count_objs.draft_cnt.badge_text = str(int(state.draft_count) - 1)
state.draft_count = str(int(state.draft_count) - 1) state.draft_count = str(int(state.draft_count) - 1)
self.parent.screens[15].clear_widgets() self.parent.screens[15].clear_widgets()
@ -1494,7 +1490,7 @@ class MailDetail(Screen):
"""Method used for replying inbox messages.""" """Method used for replying inbox messages."""
data = sqlQuery( data = sqlQuery(
"select toaddress, fromaddress, subject, message from inbox where \ "select toaddress, fromaddress, subject, message from inbox where \
received = {};".format(state.sentMailTime)) msgid = ?;",str(state.mail_id))
composer_obj = self.parent.screens[2].children[0].ids composer_obj = self.parent.screens[2].children[0].ids
composer_obj.ti.text = data[0][0] composer_obj.ti.text = data[0][0]
composer_obj.btn.text = data[0][0] composer_obj.btn.text = data[0][0]
@ -1511,7 +1507,7 @@ class MailDetail(Screen):
def write_msg(self, navApp): def write_msg(self, navApp):
"""Method used to write on draft mail.""" """Method used to write on draft mail."""
state.send_draft_mail = state.sentMailTime state.send_draft_mail = state.mail_id
composer_ids = \ composer_ids = \
self.parent.parent.parent.parent.ids.sc3.children[0].ids self.parent.parent.parent.parent.ids.sc3.children[0].ids
composer_ids.ti.text = state.write_msg['from_addr'] composer_ids.ti.text = state.write_msg['from_addr']
@ -1662,7 +1658,7 @@ class Draft(Screen):
mail[2]) > 10 else mail[2] + '\n' + " " + ( mail[2]) > 10 else mail[2] + '\n' + " " + (
third_text[:25] + '...!') if len( third_text[:25] + '...!') if len(
third_text) > 25 else third_text, third_text) > 25 else third_text,
'lastactiontime': mail[6]}) 'ackdata': mail[5]})
for item in self.data: for item in self.data:
meny = TwoLineAvatarIconListItem( meny = TwoLineAvatarIconListItem(
text='Draft', text='Draft',
@ -1672,7 +1668,7 @@ class Draft(Screen):
meny.add_widget(AvatarSampleWidget( meny.add_widget(AvatarSampleWidget(
source='./images/avatar.png')) source='./images/avatar.png'))
meny.bind(on_press=partial( meny.bind(on_press=partial(
self.draft_detail, item['lastactiontime'])) self.draft_detail, item['ackdata']))
carousel = Carousel(direction='right') carousel = Carousel(direction='right')
carousel.height = meny.height carousel.height = meny.height
carousel.size_hint_y = None carousel.size_hint_y = None
@ -1683,7 +1679,7 @@ class Draft(Screen):
del_btn.background_normal = '' del_btn.background_normal = ''
del_btn.background_color = (1, 0, 0, 1) del_btn.background_color = (1, 0, 0, 1)
del_btn.bind(on_press=partial( del_btn.bind(on_press=partial(
self.delete_draft, item['lastactiontime'])) self.delete_draft, item['ackdata']))
carousel.add_widget(del_btn) carousel.add_widget(del_btn)
carousel.add_widget(meny) carousel.add_widget(meny)
carousel.index = 1 carousel.index = 1
@ -1699,10 +1695,10 @@ class Draft(Screen):
valign='top') valign='top')
self.ids.ml.add_widget(content) self.ids.ml.add_widget(content)
def draft_detail(self, lastsenttime, *args): def draft_detail(self, ackdata, *args):
"""Method used to show draft Details.""" """Method used to show draft Details."""
state.detailPageType = 'draft' state.detailPageType = 'draft'
state.sentMailTime = lastsenttime state.mail_id = ackdata
if self.manager: if self.manager:
src_mng_obj = self.manager src_mng_obj = self.manager
else: else:
@ -1713,7 +1709,7 @@ class Draft(Screen):
def delete_draft(self, data_index, instance, *args): def delete_draft(self, data_index, instance, *args):
"""Method used to delete draft message permanently.""" """Method used to delete draft message permanently."""
sqlExecute("DELETE FROM sent WHERE lastactiontime = '{}';".format( sqlExecute("DELETE FROM sent WHERE ackdata = ?;",str(
data_index)) data_index))
try: try:
msg_count_objs = \ msg_count_objs = \
@ -1815,11 +1811,11 @@ class Allmails(Screen):
def loadMessagelist(self, account, where="", what=""): def loadMessagelist(self, account, where="", what=""):
"""Load Inbox, Sent anf Draft list of messages.""" """Load Inbox, Sent anf Draft list of messages."""
inbox = sqlQuery( inbox = sqlQuery(
"SELECT toaddress, fromaddress, subject, message, folder, received from\ "SELECT toaddress, fromaddress, subject, message, folder, msgid from\
inbox WHERE folder = 'inbox' and toaddress = '{}';".format( inbox WHERE folder = 'inbox' and toaddress = '{}';".format(
account)) account))
sent_and_draft = sqlQuery( sent_and_draft = sqlQuery(
"SELECT toaddress, fromaddress, subject, message, folder, lastactiontime from sent \ "SELECT toaddress, fromaddress, subject, message, folder, ackdata from sent \
WHERE folder = 'sent' and fromaddress = '{}';".format( WHERE folder = 'sent' and fromaddress = '{}';".format(
account)) account))
@ -1870,7 +1866,7 @@ class Allmails(Screen):
"""Load sent and inbox mail details.""" """Load sent and inbox mail details."""
state.detailPageType = folder state.detailPageType = folder
state.is_allmail = True state.is_allmail = True
state.sentMailTime = unique_id state.mail_id = unique_id
if self.manager: if self.manager:
src_mng_obj = self.manager src_mng_obj = self.manager
else: else:
@ -1883,11 +1879,11 @@ class Allmails(Screen):
"""Delete inbox mail from all mail listing listing.""" """Delete inbox mail from all mail listing listing."""
if folder == 'inbox': if folder == 'inbox':
sqlExecute( sqlExecute(
"UPDATE inbox SET folder = 'trash' WHERE received = {};".format( "UPDATE inbox SET folder = 'trash' WHERE msgid = ?;",str(
unique_id)) unique_id))
else: else:
sqlExecute( sqlExecute(
"UPDATE sent SET folder = 'trash' WHERE lastactiontime = {};".format( "UPDATE sent SET folder = 'trash' WHERE ackdata = ?;",str(
unique_id)) unique_id))
self.ids.ml.remove_widget(instance.parent.parent) self.ids.ml.remove_widget(instance.parent.parent)
try: try:

View File

@ -67,7 +67,7 @@ kivyapp = None
navinstance = None navinstance = None
sentMailTime = 0 mail_id = 0
myAddressObj = None myAddressObj = None