-
Notifications
You must be signed in to change notification settings - Fork 0
/
emailcomment.py
49 lines (42 loc) · 1.84 KB
/
emailcomment.py
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
#!/usr/bin/env python
import webapp2
import datetime
from createevent import Event
from event import ChatUser
from google.appengine.api import channel
from google.appengine.ext.webapp.mail_handlers import InboundMailHandler
from formcomment import Comment
class EmailHandler(InboundMailHandler):
"""
Email handler, builds a whitelisted delegates comment from email body.
Couldnt get attachments to upload to blobstore so removed to avoid bugs
Uses the Comment object from formcomment.py
tests for delegates and logs unauthorised use
preformats comment with html so that it can just be dumped to the page
uses channel api to update comment section through connected client ids
on event page and in database
"""
def receive(self, mail_message):
user = mail_message.sender
eventname = mail_message.subject
eventlist = Event.query().fetch()
time=datetime.datetime.now()
for event in eventlist:
whitelist=str(event.whitelist)
if user in whitelist:
content='!!comment!!<span class="media"><a class="media-left" href="#"></a><div class="media-body"><h4 class="media-heading">'+str(user)+'</h4>'+mail_message.body.decode()+'<div>'+time.strftime('%H:%M')+'</div></div></span>'
eventkey = event.key.urlsafe()
cmnt = Comment()
cmnt.event = eventkey
cmnt.content = content
cmnt.user = user
cmnt.put()
clientquery = ChatUser.query(ChatUser.event == eventkey)
clients=clientquery.fetch()
for client in clients:
channel.send_message(client.uuid, content)
else:
print "false request from " + user
app = webapp2.WSGIApplication([
('/_ah/mail/.+', EmailHandler)
], debug=True)