<s> from __future__ import unicode_literals <EOL> import email <EOL> from moto . core import BaseBackend <EOL> from . exceptions import MessageRejectedError <EOL> from . utils import get_random_message_id <EOL> RECIPIENT_LIMIT = <NUM_LIT:50> <EOL> class Message ( object ) : <EOL> def __init__ ( self , message_id ) : <EOL> self . id = message_id <EOL> class RawMessage ( object ) : <EOL> def __init__ ( self , message_id ) : <EOL> self . id = message_id <EOL> class SESQuota ( object ) : <EOL> def __init__ ( self , sent ) : <EOL> self . sent = sent <EOL> @ property <EOL> def sent_past_24 ( self ) : <EOL> return self . sent <EOL> class SESBackend ( BaseBackend ) : <EOL> def __init__ ( self ) : <EOL> self . addresses = [ ] <EOL> self . domains = [ ] <EOL> self . sent_message_count = <NUM_LIT:0> <EOL> def _is_verified_address ( self , address ) : <EOL> if address in self . addresses : <EOL> return True <EOL> user , host = address . split ( '<STR_LIT:@>' , <NUM_LIT:1> ) <EOL> return host in self . domains <EOL> def verify_email_identity ( self , address ) : <EOL> self . addresses . append ( address ) <EOL> def verify_domain ( self , domain ) : <EOL> self . domains . append ( domain ) <EOL> def list_identities ( self ) : <EOL> return self . domains + self . addresses <EOL> def delete_identity ( self , identity ) : <EOL> if '<STR_LIT:@>' in identity : <EOL> self . addresses . remove ( identity ) <EOL> else : <EOL> self . domains . remove ( identity ) <EOL> def send_email ( self , source , subject , body , destinations ) : <EOL> recipient_count = sum ( map ( len , destinations . values ( ) ) ) <EOL> if recipient_count > RECIPIENT_LIMIT : <EOL> raise MessageRejectedError ( '<STR_LIT>' ) <EOL> if not self . _is_verified_address ( source ) : <EOL> raise MessageRejectedError ( <EOL> "<STR_LIT>" % source <EOL> ) <EOL> message_id = get_random_message_id ( ) <EOL> message = Message ( message_id ) <EOL> self . sent_message_count += recipient_count <EOL> return message <EOL> def send_raw_email ( self , source , destinations , raw_data ) : <EOL> if source not in self . addresses : <EOL> raise MessageRejectedError ( <EOL> "<STR_LIT>" % source <EOL> ) <EOL> recipient_count = len ( destinations ) <EOL> message = email . message_from_string ( raw_data ) <EOL> for header in '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' : <EOL> recipient_count += sum ( <EOL> d . strip ( ) and <NUM_LIT:1> or <NUM_LIT:0> <EOL> for d in message . get ( header , '<STR_LIT>' ) . split ( '<STR_LIT:U+002C>' ) <EOL> ) <EOL> if recipient_count > RECIPIENT_LIMIT : <EOL> raise MessageRejectedError ( '<STR_LIT>' ) <EOL> self . sent_message_count += recipient_count <EOL> message_id = get_random_message_id ( ) <EOL> return RawMessage ( message_id ) <EOL> def get_send_quota ( self ) : <EOL> return SESQuota ( self . sent_message_count ) <EOL> ses_backend = SESBackend ( ) </s>
