def test_save_draft_syncback(db, config, message): from inbox.server.actions.gmail import remote_save_draft from inbox.server.sendmail.base import all_recipients from inbox.server.sendmail.message import create_email, SenderInfo from inbox.server.models.tables.imap import ImapAccount account = db.session.query(ImapAccount).get(ACCOUNT_ID) sender_info = SenderInfo(name=account.full_name, email=account.email_address) to, subject, body = message email = create_email(sender_info, all_recipients(to), subject, body, None) flags = [u'\\Draft'] date = datetime.utcnow() remote_save_draft(ACCOUNT_ID, account.drafts_folder.name, email.to_string(), flags=flags, date=date) with crispin_client(account.id, account.provider) as c: criteria = ['NOT DELETED', 'SUBJECT "{0}"'.format(subject)] c.conn.select_folder(account.drafts_folder.name, readonly=False) inbox_uids = c.conn.search(criteria) assert inbox_uids, 'Message missing from Drafts folder' c.conn.delete_messages(inbox_uids) c.conn.expunge()
def _create_gmail_draft(sender_info, recipients, subject, body, attachments, original_draft=None, reply_to=None): """ Create a draft email message. """ mimemsg = create_email(sender_info, recipients, subject, body, attachments) # The generated `X-INBOX-ID` UUID of the message is too big to serve as the # msg_uid for the corresponding ImapUid. The msg_uid is a SQL BigInteger # (20 bits), so we truncate the `X-INBOX-ID` to that size. Note that # this still provides a large enough ID space to make collisions rare. x_inbox_id = mimemsg.headers.get('X-INBOX-ID') uid = int(x_inbox_id, 16) & (1 << 20) - 1 date = datetime.utcnow() flags = [u'\\Draft'] return DraftMessage(uid=uid, msg=mimemsg.to_string(), original_draft=original_draft, reply_to=reply_to, date=date, flags=flags)
def create_gmail_email(sender_info, recipients, subject, body, attachments=None): """ Create a Gmail email. """ mimemsg = create_email(sender_info, recipients, subject, body, attachments) return smtp_attrs(mimemsg)
def create_gmail_reply(sender_info, replyto, recipients, subject, body, attachments=None): """ Create a Gmail email reply. """ mimemsg = create_email(sender_info, recipients, subject, body, attachments) # Add general reply headers: reply = add_reply_headers(replyto, mimemsg) # Set the 'Subject' header of the reply, required for Gmail. # Gmail requires the same subject as the original (adding Re:/Fwd: is fine # though) to group messages in the same conversation, # See: https://support.google.com/mail/answer/5900?hl=en reply.headers['Subject'] = REPLYSTR + replyto.subject return smtp_attrs(reply)