def forward_message(request, folder, uid): '''Reply to a message''' # Get the message M = serverLogin( request ) folder_name = base64.urlsafe_b64decode(str(folder)) folder = M[folder_name] message = folder[int(uid)] # Create a temporary file fl = tempfile.mkstemp(suffix='.tmp', prefix='webpymail_', dir=settings.TEMPDIR) # Save message source to a file os.write( fl[0], message.source() ) os.close(fl[0]) # Add a entry to the Attachments table: attachment = Attachments( user = request.user, temp_file = fl[1], filename = 'attached_message', mime_type = 'MESSAGE/RFC822', sent = False ) attachment.save() # Gather some message info subject = _('Fwd: ') + message.envelope['env_subject'].decode('utf-8') return send_message( request, subject=subject, attachments='%d' % attachment.id)
def forward_message(request, folder, uid): '''Reply to a message''' # Get the message M = serverLogin(request) folder_name = base64.urlsafe_b64decode(str(folder)) folder = M[folder_name] message = folder[int(uid)] # Create a temporary file fl = tempfile.mkstemp(suffix='.tmp', prefix='webpymail_', dir=settings.TEMPDIR) # Save message source to a file os.write(fl[0], message.source()) os.close(fl[0]) # Add a entry to the Attachments table: attachment = Attachments(user=request.user, temp_file=fl[1], filename='attached_message', mime_type='MESSAGE/RFC822', sent=False) attachment.save() # Gather some message info subject = _('Fwd: ') + message.envelope['env_subject'].decode('utf-8') return send_message(request, subject=subject, attachments='%d' % attachment.id)
def add_new_files(self, file_list): ''' @param file_list: a file list as returned on request.FILES ''' for a_file in file_list: # Create a temporary file fl = tempfile.mkstemp(suffix='.tmp', prefix='webpymail_', dir=settings.TEMPDIR) # Save the attachments to the temp file os.write(fl[0], a_file.read()) os.close(fl[0]) # Add a entry to the Attachments table: attachment = Attachments(user=self.user, temp_file=fl[1], filename=a_file.name, mime_type=a_file.content_type, sent=False) attachment.save() self.file_list.append(attachment)
def add_new_files(self, file_list ): ''' @param file_list: a file list as returned on request.FILES ''' for a_file in file_list: # Create a temporary file fl = tempfile.mkstemp(suffix='.tmp', prefix='webpymail_', dir=settings.TEMPDIR) # Save the attachments to the temp file os.write( fl[0], a_file.read() ) os.close(fl[0]) # Add a entry to the Attachments table: attachment = Attachments( user = self.user, temp_file = fl[1], filename = a_file.name, mime_type = a_file.content_type, sent = False ) attachment.save() self.file_list.append(attachment)
def forward_message(request, folder, uid): '''Reply to a message''' context = {'page_title': _('Forward Message')} # Get the message message = get_message(request, folder, uid) # Headers headers = get_headers(message) # Handle the request if request.method == 'GET': # Extract the relevant headers subject = _('Fwd: ') + message.envelope['env_subject'] # Create a temporary file fl = tempfile.mkstemp(suffix='.tmp', prefix='webpymail_', dir=settings.TEMPDIR) # Save message source to a file os.write(fl[0], bytes(message.source(), 'utf-8')) os.close(fl[0]) # Add a entry to the Attachments table: attachment = Attachments(user=request.user, temp_file=fl[1], filename='attached_message', mime_type='MESSAGE/RFC822', sent=False) attachment.save() # Show the compose message form return create_initial_message(request, subject=subject, attachments='%d' % attachment.id, headers=headers, context=context) else: # Invoque the compose message form return send_message(request, headers=headers, context=context)
def forward_message_inline(request, folder, uid): '''Reply to a message''' def message_header(message): text = '' text += show_addrs(_('From'), message.envelope['env_from'], _('Unknown')) text += show_addrs(_('To'), message.envelope['env_to'], _('-')) text += show_addrs(_('Cc'), message.envelope['env_cc'], _('-')) text += (_('Date: ') + message.envelope['env_date'].strftime('%Y-%m-%d %H:%M') + '\n') text += _('Subject: ') + message.envelope['env_subject'] + '\n\n' return text context = {'page_title': _('Forward Message Inline')} # Get the message message = get_message(request, folder, uid) # Headers headers = get_headers(message) # Handle the request if request.method == 'GET': # Extract the relevant headers subject = _('Fwd: ') + message.envelope['env_subject'] # Extract the message text text = '' text += '\n\n' + _('Forwarded Message').center(40, '-') + '\n' text += message_header(message) for part in message.bodystructure.serial_message(): if part.is_text() and part.is_plain() and not part.is_attachment(): text += message.part(part) if part.is_encapsulated(): if part.is_start(): text += ('\n\n' + _('Encapsuplated Message').center(40, '-') + '\n') text += message_header(part) else: text += ('\n' + _('End Encapsuplated Message').center(40, '-') + '\n') text += '\n' + _('End Forwarded Message').center(40, '-') + '\n' # Extract the message attachments attach_list = [] for part in message.bodystructure.serial_message(): if part.is_attachment() and not part.is_encapsulated(): # Create a temporary file fl = tempfile.mkstemp(suffix='.tmp', prefix='webpymail_', dir=settings.TEMPDIR) # Save message source to a file os.write(fl[0], message.part(part, decode_text=False)) os.close(fl[0]) # Add a entry to the Attachments table: attachment = Attachments( user=request.user, temp_file=fl[1], filename=(part.filename() if part.filename() else _('Unknown')), mime_type='%s/%s' % (part.media, part.media_subtype), content_desc=(part.body_fld_desc if part.body_fld_desc else ''), content_id=part.body_fld_id if part.body_fld_id else '', show_inline=part.body_fld_dsp[0].upper() != 'ATTACHMENT', sent=False) attachment.save() attach_list.append(attachment.id) attachments = ','.join(['%d' % Xi for Xi in attach_list]) # Show the compose message form return create_initial_message(request, text=text, subject=subject, attachments=attachments, headers=headers, context=context) else: # Invoque the compose message form return send_message(request, headers=headers, context=context)
def forward_message_inline(request, folder, uid): '''Reply to a message''' def message_header( message ): text = '' text += show_addrs( _('From'), message.envelope['env_from'], _('Unknown') ) text += show_addrs( _('To'), message.envelope['env_to'], _('-') ) text += show_addrs( _('Cc'), message.envelope['env_cc'], _('-') ) text += _('Date: ') + message.envelope['env_date'].strftime('%Y-%m-%d %H:%M') + '\n' text += _('Subject: ') + message.envelope['env_subject'].decode('utf-8') + '\n\n' return text # Get the message M = serverLogin( request ) folder_name = base64.urlsafe_b64decode(str(folder)) folder = M[folder_name] message = folder[int(uid)] # Extract the message text text = '' text += '\n\n' + _('Forwarded Message').center(40,'-') + '\n' text += message_header( message ) for part in message.bodystructure.serial_message(): if part.is_text() and part.test_plain() and not part.is_attachment(): text += message.part( part ) if part.is_encapsulated(): if part.is_start(): text += '\n\n' + _('Encapsuplated Message').center(40,'-') + '\n' text += message_header( part ) else: text += '\n' + _('End Encapsuplated Message').center(40,'-') + '\n' text += '\n' + _('End Forwarded Message').center(40,'-') + '\n' # Extract the message attachments attach_list = [] for part in message.bodystructure.serial_message(): if part.is_attachment() and not part.is_encapsulated(): # Create a temporary file fl = tempfile.mkstemp(suffix='.tmp', prefix='webpymail_', dir=settings.TEMPDIR) # Save message source to a file os.write( fl[0], message.part(part, decode_text = False) ) os.close(fl[0]) # Add a entry to the Attachments table: attachment = Attachments( user = request.user, temp_file = fl[1], filename = part.filename() if part.filename() else _('Unknown'), mime_type = '%s/%s' % (part.media, part.media_subtype), content_desc = part.body_fld_desc if part.body_fld_desc else '', content_id = part.body_fld_id if part.body_fld_id else '', show_inline = False if part.body_fld_dsp[0].upper() == 'ATTACHMENT' else True, sent = False ) attachment.save() attach_list.append(attachment.id) # Gather some message info subject = _('Fwd: ') + message.envelope['env_subject'].decode('utf-8') return send_message( request, subject=subject, text = text, attachments=','.join([ '%d' % Xi for Xi in attach_list ]) )
def forward_message_inline(request, folder, uid): '''Reply to a message''' def message_header(message): text = '' text += show_addrs(_('From'), message.envelope['env_from'], _('Unknown')) text += show_addrs(_('To'), message.envelope['env_to'], _('-')) text += show_addrs(_('Cc'), message.envelope['env_cc'], _('-')) text += _('Date: ') + message.envelope['env_date'].strftime( '%Y-%m-%d %H:%M') + '\n' text += _('Subject: ') + message.envelope['env_subject'].decode( 'utf-8') + '\n\n' return text # Get the message M = serverLogin(request) folder_name = base64.urlsafe_b64decode(str(folder)) folder = M[folder_name] message = folder[int(uid)] # Extract the message text text = '' text += '\n\n' + _('Forwarded Message').center(40, '-') + '\n' text += message_header(message) for part in message.bodystructure.serial_message(): if part.is_text() and part.test_plain() and not part.is_attachment(): text += message.part(part) if part.is_encapsulated(): if part.is_start(): text += '\n\n' + _('Encapsuplated Message').center(40, '-') + '\n' text += message_header(part) else: text += '\n' + _('End Encapsuplated Message').center( 40, '-') + '\n' text += '\n' + _('End Forwarded Message').center(40, '-') + '\n' # Extract the message attachments attach_list = [] for part in message.bodystructure.serial_message(): if part.is_attachment() and not part.is_encapsulated(): # Create a temporary file fl = tempfile.mkstemp(suffix='.tmp', prefix='webpymail_', dir=settings.TEMPDIR) # Save message source to a file os.write(fl[0], message.part(part, decode_text=False)) os.close(fl[0]) # Add a entry to the Attachments table: attachment = Attachments( user=request.user, temp_file=fl[1], filename=part.filename() if part.filename() else _('Unknown'), mime_type='%s/%s' % (part.media, part.media_subtype), content_desc=part.body_fld_desc if part.body_fld_desc else '', content_id=part.body_fld_id if part.body_fld_id else '', show_inline=False if part.body_fld_dsp[0].upper() == 'ATTACHMENT' else True, sent=False) attachment.save() attach_list.append(attachment.id) # Gather some message info subject = _('Fwd: ') + message.envelope['env_subject'].decode('utf-8') return send_message(request, subject=subject, text=text, attachments=','.join(['%d' % Xi for Xi in attach_list]))