marrow / mailer

A light-weight, modular, message representation and mail delivery framework for Python.
MIT License
276 stars 62 forks source link

Message's To Field Behaves Differently with List or Tuple #70

Open jplehmann opened 7 years ago

jplehmann commented 7 years ago

If you try to be immutable, it doesn't like you.

Works fine.

In [4]: Message(author="nlp1.noreply@lexmachina.com", to=["jlehmann@lexmachina.com"])
Out[4]: <marrow.mailer.message.Message at 0x7fe136bd3590>

Dies horribly. Seems to go down a different code path and expects a 2-tuple of name and email. But that wasn't what was intended at all -- should just be a list of emails.

In [5]: Message(author="nlp1.noreply@lexmachina.com", to=("jlehmann@lexmachina.com",))
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-5-a713a363d72b> in <module>()
----> 1 Message(author="nlp1.noreply@lexmachina.com", to=("jlehmann@lexmachina.com",))

/home/lex/local/lib/python2.7/site-packages/marrow/mailer/message.pyc in __init__(self, author, to, subject, **kw)
     86 
     87                 if to is not None:
---> 88                         self.to = to
     89 
     90                 if subject is not None:

/home/lex/local/lib/python2.7/site-packages/marrow/mailer/message.pyc in __setattr__(self, name, value)
     99         def __setattr__(self, name, value):
    100                 """Set the dirty flag as properties are updated."""
--> 101                 object.__setattr__(self, name, value)
    102                 if name not in ('bcc', '_id', '_dirty', '_processed'):
    103                         object.__setattr__(self, '_dirty', True)

/home/lex/local/lib/python2.7/site-packages/marrow/mailer/address.pyc in __set__(self, instance, value)
    220         def __set__(self, instance, value):
    221                 if not isinstance(value, self.cls):
--> 222                         value = self.cls(value)
    223 
    224                 setattr(instance, self.attr, value)

/home/lex/local/lib/python2.7/site-packages/marrow/mailer/address.pyc in __init__(self, addresses, encoding)
    137 
    138                 elif isinstance(addresses, tuple):
--> 139                         self.append(Address(addresses, encoding=encoding))
    140                         return
    141 

/home/lex/local/lib/python2.7/site-packages/marrow/mailer/address.pyc in __init__(self, name_or_email, email, encoding)
     37                         if isinstance(name_or_email, (tuple, list)):
     38                                 self.name = unicodestr(name_or_email[0], encoding)
---> 39                                 self.address = unicodestr(name_or_email[1], encoding)
     40 
     41                         elif isinstance(name_or_email, bytes):

IndexError: tuple index out of range

Versions:

$ pip freeze | grep marrow
marrow.interface==1.0.1
marrow.mailer==4.0.1
marrow.util==1.2.3
pyramid-marrowmailer==0.1