From 454711666b88a16e362a95c12bf34cfb1c2bb582 Mon Sep 17 00:00:00 2001 From: Joseph Pan Date: Thu, 25 May 2017 23:14:54 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=B0=83=E6=95=B4=E9=82=AE=E7=AE=B1?= =?UTF-8?q?=E7=9A=84=E6=92=AD=E6=8A=A5=EF=BC=8C=E5=B8=A6=20[echo]=20?= =?UTF-8?q?=E7=9A=84=E5=B0=86=E5=8F=AA=E9=98=85=E8=AF=BB=E6=A0=87=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/notifier.py | 7 +++++-- client/plugins/Email.py | 13 ++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/client/notifier.py b/client/notifier.py index b93cfd7..f970a5b 100644 --- a/client/notifier.py +++ b/client/notifier.py @@ -45,8 +45,11 @@ def handleEmailNotifications(self, lastDate): lastDate = Email.getMostRecentDate(emails) def styleEmail(e): - return "您有来自 %s 的新邮件 %s" % (Email.getSender(e), Email.getSubject(e, self.profile)) - + subject = Email.getSubject(e, self.profile) + if '[echo]' in subject: + return subject.replace('[echo]', '') + sender = Email.getSender(e) + return "您有来自 %s 的新邮件 %s" % (sender, subject) for e in emails: self.q.put(styleEmail(e)) diff --git a/client/plugins/Email.py b/client/plugins/Email.py index 7b234a0..1c14f1a 100644 --- a/client/plugins/Email.py +++ b/client/plugins/Email.py @@ -28,6 +28,9 @@ def getSender(msg): if(len(ls) == 2): fromname = email.Header.decode_header((ls[0]).strip('\"')) sender = my_unicode(fromname[0][0], fromname[0][1]) + elif(len(ls) > 2): + fromname = email.Header.decode_header((msg[:msg.find('<')]).strip('\"')) + sender = my_unicode(fromname[0][0], fromname[0][1]) else: sender = msg['From'] return sender @@ -44,12 +47,16 @@ def getSubject(msg, profile): Title of the email. """ subject = email.Header.decode_header(msg['subject']) - sub = my_unicode(subject[0][0], subject[0][1]).replace('[read]', '') + sub = my_unicode(subject[0][0], subject[0][1]) to_read = False + if sub.strip() == '': + return '' if 'read_email_title' in profile: to_read = profile['read_email_title'] - if '[read]' in subject or to_read: - return u',邮件标题为:' + sub + if '[echo]' in sub: + return sub + if to_read: + return '邮件标题为 %s' % sub return '' From 56365fa89679949eccd76622b52e826100381558 Mon Sep 17 00:00:00 2001 From: Joseph Pan Date: Thu, 25 May 2017 23:54:22 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/plugins/Camera.py | 2 +- client/plugins/Echo.py | 2 +- client/plugins/Email.py | 1 + client/plugins/Time.py | 1 + client/plugins/Unclear.py | 1 + 5 files changed, 5 insertions(+), 2 deletions(-) diff --git a/client/plugins/Camera.py b/client/plugins/Camera.py index 1cf0ec5..01ac821 100644 --- a/client/plugins/Camera.py +++ b/client/plugins/Camera.py @@ -15,9 +15,9 @@ def handle(text, mic, profile, wxbot=None): Arguments: text -- user-input, typically transcribed speech mic -- used to interact with the user (for both input and output) - wxBot -- wechat robot profile -- contains information related to the user (e.g., phone number) + wxbot -- wechat bot instance """ sys.path.append(mic.dingdangpath.LIB_PATH) from app_utils import sendToUser diff --git a/client/plugins/Echo.py b/client/plugins/Echo.py index 57be22d..2b3159a 100644 --- a/client/plugins/Echo.py +++ b/client/plugins/Echo.py @@ -10,9 +10,9 @@ def handle(text, mic, profile, wxbot=None): Arguments: text -- user-input, typically transcribed speech mic -- used to interact with the user (for both input and output) - wxBot -- wechat robot profile -- contains information related to the user (e.g., phone number) + wxBot -- wechat robot """ text = text.lower().replace('echo', '').replace(u'传话', '') mic.say(text) diff --git a/client/plugins/Email.py b/client/plugins/Email.py index 1c14f1a..79338f2 100644 --- a/client/plugins/Email.py +++ b/client/plugins/Email.py @@ -132,6 +132,7 @@ def handle(text, mic, profile, wxbot=None): mic -- used to interact with the user (for both input and output) profile -- contains information related to the user (e.g., email address) + wxBot -- wechat robot """ try: msgs = fetchUnreadEmails(profile, limit=5) diff --git a/client/plugins/Time.py b/client/plugins/Time.py index 4f02350..58758c7 100644 --- a/client/plugins/Time.py +++ b/client/plugins/Time.py @@ -16,6 +16,7 @@ def handle(text, mic, profile, wxbot=None): mic -- used to interact with the user (for both input and output) profile -- contains information related to the user (e.g., phone number) + wxBot -- wechat robot """ tz = getTimezone(profile) diff --git a/client/plugins/Unclear.py b/client/plugins/Unclear.py index b66d90d..b7a7ff0 100644 --- a/client/plugins/Unclear.py +++ b/client/plugins/Unclear.py @@ -24,6 +24,7 @@ def handle(text, mic, profile, wxbot=None): mic -- used to interact with the user (for both input and output) profile -- contains information related to the user (e.g., phone number) + wxBot -- wechat robot """ if need_robot(profile): robot = get_robot_by_slug("tuling")