Skip to content
This repository has been archived by the owner on Apr 13, 2018. It is now read-only.

Commit

Permalink
邮件增加[control]前缀,允许通过邮件远程控制叮当
Browse files Browse the repository at this point in the history
  • Loading branch information
wzpan committed Jun 10, 2017
1 parent 25c0c9b commit ffcc7eb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion client/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, persona, mic, profile):
self.mic = mic
self.profile = profile
self.brain = Brain(mic, profile)
self.notifier = Notifier(profile)
self.notifier = Notifier(profile, self.brain)
self.wxbot = None

def is_proper_time(self):
Expand Down
7 changes: 6 additions & 1 deletion client/notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ def __init__(self, gather, timestamp):
def run(self):
self.timestamp = self.gather(self.timestamp)

def __init__(self, profile):
def __init__(self, profile, brain):
self._logger = logging.getLogger(__name__)
self.q = Queue.Queue()
self.profile = profile
self.notifiers = []
self.brain = brain

if 'email' in profile and \
('enable' not in profile['email'] or profile['email']['enable']):
Expand Down Expand Up @@ -52,6 +53,10 @@ def styleEmail(e):
return subject.replace('[echo]', '')
else:
return ""
elif Email.isControlEmail(e, self.profile):
self.brain.query([subject.replace('[control]', '')
.strip()], None)
return ""
sender = Email.getSender(e)
return "您有来自 %s 的新邮件 %s" % (sender, subject)
for e in emails:
Expand Down
19 changes: 18 additions & 1 deletion client/plugins/Email.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ def getSender(msg):
return sender


def isSelfEmail(msg, profile):
""" Whether the email is sent by the user """
fromstr = msg["From"]
addr = (fromstr[fromstr.find('<')+1:fromstr.find('>')]).strip('\"')
address = profile['email']['address'].strip()
return addr == address


def getSubject(msg, profile):
"""
Returns the title of an email
Expand All @@ -57,7 +65,7 @@ def getSubject(msg, profile):
return ''
if 'read_email_title' in profile:
to_read = profile['read_email_title']
if '[echo]' in sub:
if '[echo]' in sub or '[control]' in sub:
return sub
if to_read:
return '邮件标题为 %s' % sub
Expand All @@ -83,6 +91,14 @@ def isEchoEmail(msg, profile):
return False


def isControlEmail(msg, profile):
""" Whether an email is a control email"""
subject = getSubject(msg, profile)
if '[control]' in subject and isSelfEmail(msg, profile):
return True
return False


def getDate(email):
return parser.parse(email.get('date'))

Expand Down Expand Up @@ -142,6 +158,7 @@ def fetchUnreadEmails(profile, since=None, markRead=False, limit=None):

if isEchoEmail(msg, profile):
conn.store(num, '+FLAGS', '\Seen')

conn.close()
conn.logout()

Expand Down

0 comments on commit ffcc7eb

Please sign in to comment.