How to detect attachment file size for inbound message?

161 views Asked by At

How could I check the size of attached file prior to processing it? I would like to receive messages with attached files in jpg or png format only less than 1 Mb.

The processing is manual:

class EmailHandler(webapp2.RequestHandler):
    def post(self):
        msg = email.message_from_string(self.request.body) # http://docs.python.org/2/library/email.parser.html
        for part in msg.walk():
            if part.get_content_type() == 'application/octet-stream':
                # part.get_payload() 

I can not understand if receiving of big files utilizes some limits (Mail Quota details). If so, then I would like to reject mails with big files in such a way that quota is not decreased, if possible. Secondly, I would like to handle properly over quota limits (>10 Mb) and reply back to the user that attachment is too big.

0

There are 0 answers