Ignore:
Timestamp:
12 Aug 2014, 15:49:43 (10 years ago)
Author:
uli
Message:

Make sure that by default no CC is mailed.

Location:
main/waeup.kofa/trunk/src/waeup/kofa
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/smtp.py

    r11586 r11778  
    160160
    161161def send_mail(from_name, from_addr, rcpt_name, rcpt_addrs,
    162               subject, body, config=None):
     162              subject, body, config=None, cc=False):
    163163    """Send mail.
    164164
     
    167167
    168168    Please note: the `from_addr` given will be used for the reply-to
    169     and cc field only. It will _not_ be used for the `from` field, as
    170     yahoo does not allow non-yahoo servers to deliver mail with
     169    (and cc) field only. It will _not_ be used for the `from` field,
     170    as yahoo does not allow non-yahoo servers to deliver mail with
    171171    ``@yahoo.com`` in the from-field.
    172172
    173173    The from-address set here will be: `FROM_ADDRESS` as set above.
     174
     175    ``cc`` tells whether we want the from-address to be CCed. This is
     176    not the case by default as we easily act as an open relay
     177    otherwise.
    174178
    175179    XXX: The hard-coded from-address should be changable or be
     
    187191    body["From"] = sender_addr
    188192    body["To"] = body_to.strip(', ')
    189     body["Cc"] = body["Reply-To"] = reply_addr
     193    if cc:
     194        body["Cc"] = reply_addr
     195    body["Reply-To"] = reply_addr
    190196    body["Subject"] = encode_header_item(subject)
    191197
  • main/waeup.kofa/trunk/src/waeup/kofa/tests/test_smtp.py

    r11586 r11778  
    244244             u'msg: From: A sender <no-reply@waeup.org>',
    245245             u'msg: To: A recipient <recpt@example.com>',
     246             # u'msg: Cc: A sender <sender@example.com>',
     247             u'msg: Reply-To: A sender <sender@example.com>',
     248             u'msg: Subject: A subject',
     249             u'msg: ',
     250             u'msg: This is a test mail.',
     251             u'']
     252            )
     253        return
     254
     255    def test_send_mail_with_cc(self):
     256        # with cc=True the message will be CCed to the from address
     257        mail_id = send_mail(
     258            u'A sender', u'sender@example.com',
     259            u'A recipient', u'recpt@example.com',
     260            u'A subject',
     261            u'This is a test mail.',
     262            cc=True)
     263        self.assertEqual(mail_id, 'fake-message-id@example.com')
     264        self.assertEqual(
     265            self.get_fake_smtp_output().split('\n'),
     266            [u'Sending email from no-reply@waeup.org to '
     267             u'recpt@example.com, sender@example.com:',
     268             u'Message:',
     269             u'msg: MIME-Version: 1.0',
     270             u'msg: Content-Type: text/plain; charset="us-ascii"',
     271             u'msg: Content-Transfer-Encoding: 7bit',
     272             u'msg: From: A sender <no-reply@waeup.org>',
     273             u'msg: To: A recipient <recpt@example.com>',
    246274             u'msg: Cc: A sender <sender@example.com>',
    247275             u'msg: Reply-To: A sender <sender@example.com>',
     
    270298             u'msg: From: A sender <no-reply@waeup.org>',
    271299             u'msg: To: A recipient <recpt@example.com>',
    272              u'msg: Cc: A sender <sender@example.com>',
     300             # u'msg: Cc: A sender <sender@example.com>',
    273301             u'msg: Reply-To: A sender <sender@example.com>',
    274302             u'msg: Subject: A subject',
     
    296324             u'msg: From: A sender <no-reply@waeup.org>',
    297325             u'msg: To: A recipient <recpt@example.com>',
    298              u'msg: Cc: A sender <sender@example.com>',
     326             # u'msg: Cc: A sender <sender@example.com>',
    299327             u'msg: Reply-To: A sender <sender@example.com>',
    300328             u'msg: Subject: A subject',
Note: See TracChangeset for help on using the changeset viewer.