Ejemplo n.º 1
0
    def set_email_rejected(self, handler_id, external_id):
        """Marks email identified by <HANDLER_ID>:<EXTERNAL_ID> as rejected.

	    Args:
	    	handler_id: Id of the email handler that was used to send the email.
	        external_id: External id that the service assigned to the email.
	    Returns:
	    	The result of redis operation.
	    """
        now = epoch_millis()
        return self.db_r.hset("email:%s:%s" % (handler_id, external_id),
                              'rejected_at', now)
Ejemplo n.º 2
0
Archivo: db.py Proyecto: haren/email
	def set_email_rejected(self, handler_id, external_id):
		"""Marks email identified by <HANDLER_ID>:<EXTERNAL_ID> as rejected.

	    Args:
	    	handler_id: Id of the email handler that was used to send the email.
	        external_id: External id that the service assigned to the email.
	    Returns:
	    	The result of redis operation.
	    """
		now = epoch_millis()
		return self.db_r.hset(
			"email:%s:%s" % (handler_id, external_id), 'rejected_at', now)
Ejemplo n.º 3
0
    def save_email(self, to_addr, cc_addr, bcc_addr, topic, text, sender_id,
                   handler_id, external_id, result):
        """Saves email data in redis.

		The hash to which email is saved in redis can be accessed with key:
		email:<HANDLER_ID>:<EXTERNAL_ID>

		The method also adds "<HANDLER_ID>:<EXTERNAL_ID>" to the user's emails
		set of emails identified by key emails:<SENDER_ID>.

	    Args:
	        to_addr: Email address of the main recipient.
	        cc_addr: A list of email addresses of all cc'd recipients.
	        bcc_addr: A list of email addresses of all bcc'd recipients.
	        topic: Email subject.
	        text: Email body.
	        sender_id: user_id of the sender.
	        handler_id: Id of the email handler that was used to send the email.
	        external_id: External id that the service assigned to the email.
	        result: Send result (failed / sent / queued), enum value.
	    """

        now = epoch_millis()
        cc_addr = cc_addr or []
        bcc_addr = bcc_addr or []
        email_data = {
            'to': to_addr,
            'cc': ','.join(cc_addr),
            'bcc': ','.join(bcc_addr),
            'subject': topic,
            'text': text,
            'sender_id': sender_id,
            'id': "%s:%s" % (handler_id, external_id)
        }
        if result == config.SEND_STATUS.SENT:
            email_data['sent_at'] = now
        elif result == config.SEND_STATUS.QUEUED:
            email_data['queued_at'] = now
        else:
            email_data['failed_at'] = now

        self.db_r.hmset("email:%s:%s" % (handler_id, external_id), email_data)
        self.db_r.sadd('emails:%s' % sender_id,
                       '%s:%s' % (handler_id, external_id))
        return
Ejemplo n.º 4
0
Archivo: db.py Proyecto: haren/email
	def save_email(self, to_addr, cc_addr, bcc_addr, topic,
					text, sender_id, handler_id, external_id, result):
		"""Saves email data in redis.

		The hash to which email is saved in redis can be accessed with key:
		email:<HANDLER_ID>:<EXTERNAL_ID>

		The method also adds "<HANDLER_ID>:<EXTERNAL_ID>" to the user's emails
		set of emails identified by key emails:<SENDER_ID>.

	    Args:
	        to_addr: Email address of the main recipient.
	        cc_addr: A list of email addresses of all cc'd recipients.
	        bcc_addr: A list of email addresses of all bcc'd recipients.
	        topic: Email subject.
	        text: Email body.
	        sender_id: user_id of the sender.
	        handler_id: Id of the email handler that was used to send the email.
	        external_id: External id that the service assigned to the email.
	        result: Send result (failed / sent / queued), enum value.
	    """

		now = epoch_millis()
		cc_addr  = cc_addr or []
		bcc_addr = bcc_addr or []
		email_data = {
			'to': to_addr,
			'cc': ','.join(cc_addr),
			'bcc': ','.join(bcc_addr),
			'subject': topic,
			'text': text,
			'sender_id': sender_id,
			'id': "%s:%s" % (handler_id, external_id)
		}
		if result == config.SEND_STATUS.SENT:
			email_data['sent_at'] = now
		elif result == config.SEND_STATUS.QUEUED:
			email_data['queued_at'] = now
		else:
			email_data['failed_at'] = now

		self.db_r.hmset("email:%s:%s" % (handler_id, external_id), email_data)
		self.db_r.sadd('emails:%s' % sender_id, '%s:%s' % (handler_id, external_id))
		return