-
Notifications
You must be signed in to change notification settings - Fork 573
Expand file tree
/
Copy pathmaildetail.py
More file actions
247 lines (216 loc) · 10.4 KB
/
maildetail.py
File metadata and controls
247 lines (216 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# pylint: disable=unused-argument, consider-using-f-string, import-error, attribute-defined-outside-init
# pylint: disable=unnecessary-comprehension, no-member, no-name-in-module, too-few-public-methods
"""
Maildetail screen for inbox, sent, draft and trash.
"""
import os
from datetime import datetime
import sqlite3
from kivy.core.clipboard import Clipboard
from kivy.clock import Clock
from kivy.properties import (
StringProperty,
NumericProperty
)
from kivy.uix.screenmanager import Screen
from kivy.factory import Factory
from kivy.app import App
from kivymd.uix.button import MDFlatButton, MDIconButton
from kivymd.uix.dialog import MDDialog
from kivymd.uix.list import (
OneLineListItem,
IRightBodyTouch
)
from pybitmessage.bitmessagekivy.baseclass.common import (
toast, avatar_image_first_letter, show_time_history, kivy_state_variables
)
from pybitmessage.bitmessagekivy.baseclass.popup import SenderDetailPopup
from pybitmessage.bitmessagekivy.get_platform import platform
from pybitmessage.helper_sql import sqlQuery
class OneLineListTitle(OneLineListItem):
"""OneLineListTitle class for kivy Ui"""
__events__ = ('on_long_press', )
long_press_time = NumericProperty(1)
def on_state(self, instance, value):
"""On state"""
if value == 'down':
lpt = self.long_press_time
self._clockev = Clock.schedule_once(self._do_long_press, lpt)
else:
self._clockev.cancel()
def _do_long_press(self, dt):
"""Do long press"""
self.dispatch('on_long_press')
def on_long_press(self, *largs):
"""On long press"""
self.copymessageTitle(self.text)
def copymessageTitle(self, title_text):
"""this method is for displaying dialog box"""
self.title_text = title_text
width = .8 if platform == 'android' else .55
self.dialog_box = MDDialog(
text=title_text,
size_hint=(width, .25),
buttons=[
MDFlatButton(
text="Copy", on_release=self.callback_for_copy_title
),
MDFlatButton(
text="Cancel", on_release=self.callback_for_copy_title,
),
],)
self.dialog_box.open()
def callback_for_copy_title(self, instance):
"""Callback of alert box"""
if instance.text == 'Copy':
Clipboard.copy(self.title_text)
self.dialog_box.dismiss()
toast(instance.text)
class IconRightSampleWidget(IRightBodyTouch, MDIconButton):
"""IconRightSampleWidget class for kivy Ui"""
class MailDetail(Screen): # pylint: disable=too-many-instance-attributes
"""MailDetail Screen class for kivy Ui"""
to_addr = StringProperty()
from_addr = StringProperty()
subject = StringProperty()
message = StringProperty()
status = StringProperty()
page_type = StringProperty()
time_tag = StringProperty()
avatarImg = StringProperty()
no_subject = '(no subject)'
def __init__(self, *args, **kwargs):
"""Mail Details method"""
super(MailDetail, self).__init__(*args, **kwargs)
self.kivy_state = kivy_state_variables()
Clock.schedule_once(self.init_ui, 0)
def init_ui(self, dt=0):
"""Clock Schdule for method MailDetail mails"""
self.page_type = self.kivy_state.detail_page_type if self.kivy_state.detail_page_type else ''
try:
if self.kivy_state.detail_page_type in ('sent', 'draft'):
App.get_running_app().set_mail_detail_header()
elif self.kivy_state.detail_page_type == 'inbox':
data = sqlQuery(
"select toaddress, fromaddress, subject, message, received from inbox"
" where msgid = ?", sqlite3.Binary(self.kivy_state.mail_id))
if len(data) < 1:
data = sqlQuery(
"select toaddress, fromaddress, subject, message, received from inbox"
" where msgid = CAST(? AS TEXT)", self.kivy_state.mail_id)
self.assign_mail_details(data)
App.get_running_app().set_mail_detail_header()
except Exception as e: # pylint: disable=unused-variable
print('Something wents wrong!!')
def assign_mail_details(self, data):
"""Assigning mail details"""
subject = data[0][2].decode() if isinstance(data[0][2], bytes) else data[0][2]
body = data[0][3].decode() if isinstance(data[0][2], bytes) else data[0][3]
self.to_addr = data[0][0] if len(data[0][0]) > 4 else ' '
self.from_addr = data[0][1]
self.subject = subject.capitalize(
) if subject.capitalize() else self.no_subject
self.message = body
if len(data[0]) == 7:
self.status = data[0][4]
self.time_tag = show_time_history(data[0][4]) if self.kivy_state.detail_page_type == 'inbox' \
else show_time_history(data[0][6])
self.avatarImg = os.path.join(self.kivy_state.imageDir, 'draft-icon.png') \
if self.kivy_state.detail_page_type == 'draft' \
else (os.path.join(self.kivy_state.imageDir, 'text_images', '{0}.png'.format(avatar_image_first_letter(
self.subject.strip()))))
self.timeinseconds = data[0][4] if self.kivy_state.detail_page_type == 'inbox' else data[0][6]
def delete_mail(self):
"""Method for mail delete"""
msg_count_objs = App.get_running_app().root.ids.content_drawer.ids
self.kivy_state.searching_text = ''
self.children[0].children[0].active = True
if self.kivy_state.detail_page_type == 'sent':
App.get_running_app().root.ids.id_sent.ids.sent_search.ids.search_field.text = ''
msg_count_objs.send_cnt.ids.badge_txt.text = str(int(self.kivy_state.sent_count) - 1)
self.kivy_state.sent_count = str(int(self.kivy_state.sent_count) - 1)
self.parent.screens[2].ids.ml.clear_widgets()
self.parent.screens[2].loadSent(self.kivy_state.selected_address)
elif self.kivy_state.detail_page_type == 'inbox':
App.get_running_app().root.ids.id_inbox.ids.inbox_search.ids.search_field.text = ''
msg_count_objs.inbox_cnt.ids.badge_txt.text = str(
int(self.kivy_state.inbox_count) - 1)
self.kivy_state.inbox_count = str(int(self.kivy_state.inbox_count) - 1)
self.parent.screens[0].ids.ml.clear_widgets()
self.parent.screens[0].loadMessagelist(self.kivy_state.selected_address)
elif self.kivy_state.detail_page_type == 'draft':
msg_count_objs.draft_cnt.ids.badge_txt.text = str(
int(self.kivy_state.draft_count) - 1)
self.kivy_state.draft_count = str(int(self.kivy_state.draft_count) - 1)
self.parent.screens[13].clear_widgets()
self.parent.screens[13].add_widget(Factory.Draft())
if self.kivy_state.detail_page_type != 'draft':
msg_count_objs.trash_cnt.ids.badge_txt.text = str(
int(self.kivy_state.trash_count) + 1)
msg_count_objs.allmail_cnt.ids.badge_txt.text = str(
int(self.kivy_state.all_count) - 1)
self.kivy_state.trash_count = str(int(self.kivy_state.trash_count) + 1)
self.kivy_state.all_count = str(int(self.kivy_state.all_count) - 1) if \
int(self.kivy_state.all_count) else '0'
self.parent.screens[3].clear_widgets()
self.parent.screens[3].add_widget(Factory.Trash())
self.parent.screens[14].clear_widgets()
self.parent.screens[14].add_widget(Factory.Allmails())
Clock.schedule_once(self.callback_for_delete, 4)
def callback_for_delete(self, dt=0):
"""Delete method from allmails"""
if self.kivy_state.detail_page_type:
self.children[0].children[0].active = False
App.get_running_app().set_common_header()
self.parent.current = 'allmails' \
if self.kivy_state.is_allmail else self.kivy_state.detail_page_type
self.kivy_state.detail_page_type = ''
toast('Deleted')
def get_message_details_to_reply(self, data):
"""Getting message details and fill into fields when reply"""
sender_address = ' wrote:--------------\n'
message_time = '\n\n --------------On '
composer_obj = self.parent.screens[1].children[1].ids
composer_obj.ti.text = data[0][0]
composer_obj.composer_dropdown.text = data[0][0]
composer_obj.txt_input.text = data[0][1]
split_subject = data[0][2].split('Re:', 1)
composer_obj.subject.text = 'Re: ' + (split_subject[1] if len(split_subject) > 1 else split_subject[0])
time_obj = datetime.fromtimestamp(int(data[0][4]))
time_tag = time_obj.strftime("%d %b %Y, %I:%M %p")
sender_name = data[0][1]
composer_obj.body.text = (
message_time + time_tag + ', ' + sender_name + sender_address + data[0][3])
composer_obj.body.focus = True
composer_obj.body.cursor = (0, 0)
def inbox_reply(self):
"""Reply inbox messages"""
self.kivy_state.in_composer = True
App.get_running_app().root.ids.id_create.children[1].ids.rv.data = ''
App.get_running_app().root.ids.sc3.children[1].ids.rv.data = ''
self.parent.current = 'create'
App.get_running_app().set_navbar_for_composer()
def get_message_details_for_draft_reply(self, data):
"""Getting and setting message details fill into fields when draft reply"""
composer_ids = (
self.parent.parent.ids.id_create.children[1].ids)
composer_ids.ti.text = data[0][1]
composer_ids.btn.text = data[0][1]
composer_ids.txt_input.text = data[0][0]
composer_ids.subject.text = data[0][2] if data[0][2] != self.no_subject else ''
composer_ids.body.text = data[0][3]
def write_msg(self, navApp):
"""Write on draft mail"""
self.kivy_state.send_draft_mail = self.kivy_state.mail_id
self.parent.current = 'create'
navApp.set_navbar_for_composer()
def detailedPopup(self):
"""Detailed popup"""
obj = SenderDetailPopup()
obj.open()
arg = (self.to_addr, self.from_addr, self.timeinseconds)
obj.assignDetail(*arg)
@staticmethod
def callback_for_menu_items(text_item, *arg):
"""Callback of alert box"""
toast(text_item)