I just put together the following script that saves an attachment as
an avatar. I tested it once and then went on doing other things; when
I came back I noticed in the logs that the app kept sending the email
again and again every few minutes. Why is this happenning? Any
suggestions?

import cgi
import os
import logging

from model import User
from model import Comment
from model import Venue

from email.utils import parseaddr
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db
from google.appengine.api import mail
from google.appengine.ext.webapp.mail_handlers import
InboundMailHandler
from google.appengine.api import images
#----------------------------------------------------------------------
#--decode function written by jesmith----------
#--http://stackoverflow.com/questions/4357022/writing-and-image-
attachment-to-datastore-as-an-avatar-is-it-possible/4359487#4359487
def goodDecode(encodedPayload):
  if not hasattr(encodedPayload, 'encoding'):
    return encodedPayload
  encoding = encodedPayload.encoding
  payload = encodedPayload.payload
  if encoding and encoding.lower() != '7bit':
    payload = payload.decode(encoding)
  return payload
#---------------------------------------------
class Register(InboundMailHandler):
    def receive(self, message):
        senderEmail = message.sender
        emailTuple = parseaddr(senderEmail)
        emailUserName = emailTuple[0]
        emailAddress = emailTuple[1]

        newUser = User(userEmail=emailAddress,
                       userName=emailUserName)

        db.put(newUser)
#--save the attachment as
avatar------------------------------------------
        q = User.all()
        q.filter("userEmail =", emailAddress)
        qTable = q.fetch(10)
        if qTable:
            logging.info("qTable true")
            for row in qTable:
                avatar =
images.resize(goodDecode(message.attachments[0][1]), 50, 50)
                row.avatar = db.Blob(avatar)
            db.put(qTable)
            self.redirect("/")
        else:
            logging.info("else user not found")
            self.redirect("/user-not-found")
#-----------------------------------------------------------------------
        mail.send_mail(sender="<[email protected]>",
               to=message.sender,
               subject="Thank you for registering...",
               body="""Enjoy!"""
                 )

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to