3 # Copyright 2010 Google Inc. All Rights Reserved.
5 """Handle incoming email for Cloud Photo Stitcher.
7 Expects a zip file of images and stitches them.
9 mail to batch_name@photostitch.appspot.com.
12 try: # (code before imports) pylint: disable-msg=C6205
13 import auto_import_fixer
# (unused import) pylint: disable-msg=W0611,C6204
21 from google
.appengine
.ext
import webapp
22 from google
.appengine
.ext
.webapp
import util
23 from google
.appengine
.ext
.webapp
.mail_handlers
import InboundMailHandler
24 from google
.appengine
.ext
.webapp
.util
import run_wsgi_app
25 from stitch_request
import StitchRequest
27 class EmailHandler(InboundMailHandler
):
28 def receive(self
, mail_message
):
29 logging
.info("Received a message from: " + mail_message
.sender
)
30 images
= mail_message
.bodies('image/jpeg')
31 req
= StitchRequest(mail_message
.sender
, 'batchx', config
.gs_bucket
)
32 for file, attachment
in mail_message
.attachments
:
33 logging
.info('attachment: %s' % file)
34 file = file.lower().replace(' ', '')
35 if not (file.endswith('.jpg') or file.endswith('.jpeg')):
37 logging
.info('writing %s, %d bytes' % (file, len(attachment
)))
38 req
.AddFile(file, attachment
)
39 logging
.info('%s' % req
.toJson())
42 application
= webapp
.WSGIApplication([EmailHandler
.mapping()],
44 util
.run_wsgi_app(application
)
47 if __name__
== '__main__':