Exemplo n.º 1
0
    def get(self, email_id):
        logging.info('MailDetailsPage processing')
        logging.info('email_id: ' + email_id)
        email_id = str(email_id).strip()
        if email_id and email_id != '':
            logging.info('valid email_id')

        user = users.get_current_user()

        email = Email.get(email_id)
        if email:
            logging.info('attachments')
            email._files = None
            if email.attachments:
                if len(email.attachments) > 0:
                    email._files = []
                for i in range(len(email.attachments)):
                    file = Files.get(email.attachments[i])
                    email._files.append(file)
                    logging.info('file.name : ' + file.name)

        template_values = {
            'home_url': '/home',
            'email_url': '/mail',
            'nickname': user.nickname(),
            'logout_url': users.create_logout_url("/"),
            'email': email
        }

        self.template_values = template_values
        self.render('mail_details.html')
Exemplo n.º 2
0
    def get(self, emailid):
        logging.info('downloading zip file for email: ' + emailid)
        emailid = str(emailid).strip()
        if emailid and emailid != '':
            email = Email.get(emailid)
            if email:
                logging.info('email attachments count: ' + str(len(email.attachments)))
                
                # create the zip stream
                zipstream=StringIO()
                zfile = zipfile.ZipFile(zipstream,"w")

                for attachment in email.attachments:
                    file_attachment = Files.get(attachment)
                    if file_attachment:
                        zfile = self.addFile(zfile, file_attachment.name, file_attachment.content)
                
                zfile.close()
                zipstream.seek(0)
                
                self.response.headers['Content-Type'] = 'application/zip'
                self.response.headers['Content-Disposition'] = 'attachment; filename="attachments.zip"'
                #self.response.out.write(zfile.content)
                while True:
                    buf = zipstream.read(2048)
                    if buf == "":
                        break
                    self.response.out.write(buf)
Exemplo n.º 3
0
    def get(self, email_id):
        logging.info('MailDetailsPage processing')
        logging.info('email_id: ' + email_id)
        email_id = str(email_id).strip()
        if email_id and email_id != '':
            logging.info('valid email_id')
        
        user = users.get_current_user()
        
        email = Email.get(email_id)
        if email:
            logging.info('attachments')
            email._files = None
            if email.attachments:
                if len(email.attachments) > 0:
                    email._files = []
                for i in range(len(email.attachments)):
                    file = Files.get(email.attachments[i])
                    email._files.append(file)
                    logging.info('file.name : ' + file.name)

        template_values = {
                           'home_url' : '/home',
                           'email_url' : '/mail',
                           'nickname' : user.nickname(),
                           'logout_url': users.create_logout_url("/"),
                           'email': email
                }
        
        self.template_values = template_values
        self.render('mail_details.html')
Exemplo n.º 4
0
    def get(self, emailid):
        logging.info('downloading zip file for email: ' + emailid)
        emailid = str(emailid).strip()
        if emailid and emailid != '':
            email = Email.get(emailid)
            if email:
                logging.info('email attachments count: ' +
                             str(len(email.attachments)))

                # create the zip stream
                zipstream = StringIO()
                zfile = zipfile.ZipFile(zipstream, "w")

                for attachment in email.attachments:
                    file_attachment = Files.get(attachment)
                    if file_attachment:
                        zfile = self.addFile(zfile, file_attachment.name,
                                             file_attachment.content)

                zfile.close()
                zipstream.seek(0)

                self.response.headers['Content-Type'] = 'application/zip'
                self.response.headers[
                    'Content-Disposition'] = 'attachment; filename="attachments.zip"'
                #self.response.out.write(zfile.content)
                while True:
                    buf = zipstream.read(2048)
                    if buf == "":
                        break
                    self.response.out.write(buf)
Exemplo n.º 5
0
    def get(self):
        logging.info('MailPage processing')
        user = users.get_current_user()
        
        page = self.request.get("page", default_value="1");
        page = int(page);
        
        q = RegisteredUserSettings.all()
        q.filter('user', user)
        user_settings_list = q.fetch(1)

        if user_settings_list == None or len(user_settings_list) == 0:
            # settings not yet created - for old users
            logging.info("creating user settings...")
            user_settings = RegisteredUserSettings(paging_pager_count=settings.PAGE_SIZE, user=user)
            user_settings.put()
        else:
            logging.info("user settings already exist...")
            user_settings = user_settings_list[0]
            logging.info("user_settings_list[0] : " + str(user_settings.paging_pager_count))
        
        btn_delete = self.request.get("btn_delete", None)
        
        if btn_delete != None:
            logging.info("deleting emails...")
            
            delete_mail_ids = self.request.get("delete_mail_ids", allow_multiple=True, default_value=None)
            deleted_count = 0
            keys_to_delete = []
            if delete_mail_ids:
                #change this to use a list of keys and delete list and not one key at a time
                for delete_mail_id in delete_mail_ids:
                    logging.info("deleting email : " + str(delete_mail_id))
                    
                    logging.info("deleting email attachments")
                    current_email = Email.get(delete_mail_id)
                    attachment_keys = []
                    for attachment_key in current_email.attachments:
                        attachment_keys.append(attachment_key)
                    db.delete(attachment_keys)
                    
                    keys_to_delete.append(delete_mail_id)
                    #Email.delete(delete_mail_id)
                    deleted_count += 1

                db.delete(keys_to_delete)
                logging.info("deleted_count : " + str(deleted_count))
            
            if page > 1 and deleted_count == int(user_settings.paging_pager_count):
                page -= 1
        
        emails = Email.all()
        emails.filter('user', user).order('-received')

        emails_paged = self.emails_paged(emails, page, user_settings)
        
        emails = emails_paged["results"];
        next_page = None;
        prev_page = None;
        if emails_paged["nextPageExists"]: next_page = page + 1;
        if emails_paged["prevPageExists"]: prev_page = page - 1;

        template_values = {
                           'home_url' : '/home',
                           'nickname' : user.nickname(),
                           'logout_url': users.create_logout_url("/"),
                           'emails': emails,
                           'next_page': next_page,
                           'prev_page': prev_page,
                           'user_settings': user_settings
                }

        self.template_values = template_values
        self.render('mail.html')
Exemplo n.º 6
0
    def receive(self, mail_message):
        logging.info("Received a message from: " + str(mail_message.sender))

        to_email_parsed = str(mail_message.to)
        to_email_parsed = parse_email(to_email_parsed)

        logging.info("to email trimmed: " + to_email_parsed)

        user = check_user_registered_by_email(to_email_parsed)

        html_body = ''
        plain_body = ''

        bodies = mail_message.bodies()
        for content_type, body in bodies:
            if body.encoding == '8bit':
                body.encoding = '7bit'

            #test for html content
            if content_type == "text/html":
                #parse html result
                html_body += body.decode()
                logging.info('body text/html')

            if content_type == "text/plain":
                plain_body += body.decode()
                logging.info('body text/plain')

        from_email_parsed = mail_message.sender
        from_email_parsed = parse_email(from_email_parsed)
        if from_email_parsed == '*****@*****.**':
            self.check_if_confirmation_mail(plain_body, html_body)

        if not user:
            logging.info('check_user_registered_by_email is FALSE; from : ' +
                         from_email_parsed)
        else:
            logging.info('check_user_registered_by_email is TRUE')

            params = {}
            if hasattr(mail_message, 'sender'):
                params['sender'] = mail_message.sender
            if hasattr(mail_message, 'to'):
                params['to'] = mail_message.to
            if hasattr(mail_message, 'cc'):
                params['cc'] = mail_message.cc
            if hasattr(mail_message, 'bcc'):
                params['bcc'] = mail_message.bcc
            if hasattr(mail_message, 'reply_to'):
                params['reply_to'] = mail_message.reply_to
            if hasattr(mail_message, 'subject'):
                params['subject'] = mail_message.subject
            if hasattr(mail_message, 'body'):
                params['body'] = plain_body
            if hasattr(mail_message, 'html'):
                params['html'] = html_body

            params['user'] = user

            attachments = []
            if hasattr(mail_message, 'attachments'):
                for (name, content) in mail_message.attachments:
                    logging.info('new attachment name : ' + name)
                    try:
                        new_file = Files(name=name,
                                         content=db.Blob(content.decode()))
                        attachments.append(new_file)
                        #new_file.put()
                        #attachments.append(new_file.key())
                    except:
                        logging.info('decoding content failed')
                #if len(attachments) <> 0:
                #params['attachments'] = attachments

            new_email = Email(**params)

            #try:
            #new_email.put()
            #except:
            #logging.info('html_body: ' + html_body)
            #logging.info('plain_body: ' + plain_body)

            mem_key = datetime.datetime.now()
            mem_key = str(mem_key.year) + str(mem_key.month) + str(
                mem_key.day) + str(mem_key.hour) + str(mem_key.minute) + str(
                    mem_key.second) + str(mem_key.microsecond)
            memcache.add(key=mem_key,
                         value={
                             'email': new_email,
                             'files': attachments
                         })
            taskqueue.add(url='/task_put_email', params={'mem_key': mem_key})

            logging.info('new email mem_key : ' + str(mem_key))