I'm processing inbound email on GAE and have a problem detecting if there is a value for CC. The code basically has to do 3 things: 1) Do nothing if there is no value for CC. 2) Save the CC to item.cc when it is present. 3) If an error occurs, log it. I've written following code to do this:
import traceback
from google.appengine.ext.webapp.mail_handlers import InboundMailHandler
from myapp.models import Item
class MyTask(InboundMailHandler):
def receive(self, mail_message):
item = Item()
try:
if mail_message.cc == None:
pass
else:
item.cc = mail_message.cc
except:
stacktrace = traceback.format_exc()
logging.error("%s", stacktrace)
item.put()
However, when I process an email without a CC value, I get following error:
AttributeError: 'InboundEmailMessage' object has no attribute 'cc'
What am I missing here?
Reading the source, it looks like most of the attributes of an InboundEmailMessage
only get set at all if they'd have a non-empty value.
You could do something like:
try:
item.cc = mail_message.cc
except AttributeError:
pass