Changeset 1120

Show
Ignore:
Timestamp:
05/28/08 10:07:08
Author:
crchemist
Message:

Refactor email processing.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • qPloneComments/branches/plone-3.0/patch.py

    r1018 r1120  
    55from AccessControl import ClassSecurityInfo 
    66from Globals import InitializeClass 
     7import rfc822 
     8from StringIO import StringIO 
     9from utils import * 
    710 
    8 from utils import * 
     11def _mungeHeaders( messageText, mto=None, mfrom=None, subject=None): 
     12    """Sets missing message headers, and deletes Bcc. 
     13       returns fixed message, fixed mto and fixed mfrom""" 
     14    mfile=StringIO(messageText.lstrip()) 
     15    mo=rfc822.Message(mfile) 
     16 
     17    # Parameters given will *always* override headers in the messageText. 
     18    # This is so that you can't override or add to subscribers by adding them to 
     19    # the message text. 
     20    if subject: 
     21        mo['Subject'] = subject 
     22    elif not mo.getheader('Subject'): 
     23        mo['Subject'] = '[No Subject]' 
     24 
     25    if mto: 
     26        if isinstance(mto, basestring): 
     27            mto = [rfc822.dump_address_pair(addr) for addr in rfc822.AddressList(mto) ] 
     28        if not mo.getheader('To'): 
     29            mo['To'] = ','.join(mto) 
     30    else: 
     31        mto = [] 
     32        for header in ('To', 'Cc', 'Bcc'): 
     33            v = mo.getheader(header) 
     34            if v: 
     35                mto += [rfc822.dump_address_pair(addr) for addr in rfc822.AddressList(v)] 
     36        if not mto: 
     37            raise MailHostError, "No message recipients designated" 
     38 
     39    if mfrom: 
     40        mo['From'] = mfrom 
     41    else: 
     42        if mo.getheader('From') is None: 
     43            raise MailHostError,"Message missing SMTP Header 'From'" 
     44        mfrom = mo['From'] 
     45 
     46    if mo.getheader('Bcc'): 
     47        mo.__delitem__('Bcc') 
     48 
     49    if not mo.getheader('Date'): 
     50        mo['Date'] = DateTime().rfc822() 
     51 
     52    mo.rewindbody() 
     53    finalmessage = mo 
     54    finalmessage = mo.__str__() + '\n' + mfile.read() 
     55    mfile.close() 
     56    return finalmessage, mto, mfrom 
    957 
    1058# Patching createReply method of  
     
    91139DiscussionItemContainer.createReply = createReply 
    92140DiscussionItemContainer.getReplies = getReplies 
     141 
     142""" 
     143try: 
     144    from Products.MailHost import MailHost 
     145    MailHost._mungeHeaders = _mungeHeaders 
     146except ImportError: 
     147    pass 
     148""" 
  • qPloneComments/branches/plone-3.0/skins/qplonecomments/approve_comment_template.pt

    r1018 r1120  
    33     tal:define="charset here/portal_properties/site_properties/default_charset|string:utf-8; 
    44                 dummy python:request.RESPONSE.setHeader('Content-Type', 'text/html;;charset=%s' % charset); 
    5                  organization_name options/organization_name" 
    6 >To: <tal:x replace="options/mto"/> 
    7 From: <tal:x replace="options/mfrom"/> 
    8 Subject: <tal:x condition="organization_name" replace="string:[$organization_name] "/><tal:subject i18n:translate="approvemail_subject">New comment awaits moderation</tal:subject> 
     5                 organization_name options/organization_name"> 
    96 
    10 <tal:new_comment define="obj nocall:options/obj"  
     7<tal:new_comment define="obj nocall:options/obj" 
    118       i18n:translate="approvemail_new_comment_link"> 
    129       Please review new comment added to the following page "<tal:x replace="obj/Title" i18n:name="title"/>": 
  • qPloneComments/branches/plone-3.0/skins/qplonecomments/notify_comment_template.pt

    r1018 r1120  
    44                 dummy python:request.RESPONSE.setHeader('Content-Type', 'text/html;;charset=%s' % charset); 
    55                 organization_name options/organization_name; 
    6                  obj nocall:options/obj" 
    7 >To: <tal:x replace="options/mto"/> 
    8 From: <tal:x replace="options/mfrom"/> 
    9 Subject: <tal:subject define="obj nocall:options/obj"  
    10                       i18n:translate="notifycomment_subject">Your comment on '<tal:x replace="obj/Title" i18n:name="title"/>' is now published</tal:subject> 
     6                 obj nocall:options/obj"> 
    117 
    128<tal:x replace="options/name"/>, 
  • qPloneComments/branches/plone-3.0/skins/qplonecomments/published_comment_template.pt

    r1018 r1120  
    44                 dummy python:request.RESPONSE.setHeader('Content-Type', 'text/html;;charset=%s' % charset); 
    55                 organization_name options/organization_name" 
    6 >To: <tal:x replace="options/mto"/> 
    7 From: <tal:x replace="options/mfrom"/> 
    8 Subject: <tal:x condition="organization_name" replace="string:[$organization_name] "/><tal:subject i18n:translate="publishedmail_subject">New comment added</tal:subject> 
    96 
    107<tal:new_comment define="obj nocall:options/obj" i18n:translate="publishedmail_new_comment_link"> 
  • qPloneComments/branches/plone-3.0/skins/qplonecomments/rejected_comment_template.pt

    r1018 r1120  
    44                 dummy python:request.RESPONSE.setHeader('Content-Type', 'text/html;;charset=%s' % charset); 
    55                 organization_name options/organization_name; 
    6                  obj nocall:options/obj" 
    7 >To: <tal:x replace="options/mto"/> 
    8 From: <tal:x replace="options/mfrom"/> 
    9 Subject: <tal:subject define="obj nocall:options/obj"  
    10                       i18n:translate="notifyreject_subject">Your comment on '<tal:x replace="obj/Title" i18n:name="title"/>' was not approved.</tal:subject> 
     6                 obj nocall:options/obj"> 
    117 
    128<tal:x replace="options/name"/>, 
  • qPloneComments/branches/plone-3.0/skins/qplonecomments/reply_notify_template.pt

    r1018 r1120  
    44                 dummy python:request.RESPONSE.setHeader('Content-Type', 'text/html;;charset=%s' % charset); 
    55                 organization_name options/organization_name; 
    6                  obj nocall:options/obj" 
    7 >To: <tal:x replace="options/mto"/> 
    8 From: <tal:x replace="options/mfrom"/> 
    9 Subject: <tal:subject define="obj nocall:options/obj"  
    10                       i18n:translate="replynotify_subject">Someone replied to your comment on '<tal:x replace="obj/Title" i18n:name="title"/>'</tal:subject> 
    11  
     6                 obj nocall:options/obj"> 
    127<tal:x replace="options/name"/>, 
    138<tal:notify define="obj nocall:options/obj"  
  • qPloneComments/branches/plone-3.0/utils.py

    r1102 r1120  
    11from Products.CMFCore.utils import getToolByName 
    2  
    32# Get apropriate property from (propery_sheeet) configlet 
    43def getProp(self, prop_name, marker=None): 
     
    9594    admin_email = context.portal_url.getPortalObject().getProperty('email_from_address') 
    9695 
     96    subject = '' 
    9797    if state == 'enable_approve_user_notification': 
     98        subject = 'Your comment on %s is now published'%context.Title() 
    9899        if user_email: 
    99100            template = 'notify_comment_template' 
     
    107108 
    108109    elif state == 'enable_rejected_user_notification': 
     110        subject = 'Your comment on %s was not approved.'%context.Title() 
    109111        if user_email: 
    110112            template = 'rejected_comment_template' 
     
    119121    elif state == 'enable_reply_user_notification': 
    120122        template = 'reply_notify_template' 
     123        subject = 'Someone replied to your comment on %s'%context.Title() 
    121124        di_parrent = getDIParent(reply) 
    122125        if di_parrent: 
     
    141144                  'obj':reply_parent, 
    142145                  'organization_name':organization_name} 
     146            subject = '[%s] New comment added'%organization_name 
    143147        else: 
    144148            args = {} 
     
    152156                  'obj':reply_parent, 
    153157                  'organization_name':organization_name} 
     158            subject = '[%s] New comment awaits moderation'%organization_name 
    154159        else: 
    155160            args = {} 
     
    157162    if args: 
    158163        msg = getMsg(context, template, args) 
    159         #__import__("pdb").set_trace() 
    160         context.MailHost.send(str(msg)) 
     164        p_utils = context.plone_utils 
     165        site_props = context.portal_properties.site_properties 
     166        host = p_utils.getMailHost() 
     167        host.secureSend(msg, user_email, admin_email, 
     168                        subject = subject, 
     169                        subtype = 'plain', 
     170                        debug = False, 
     171                        charset = site_props.getProperty('default_charset', 'utf-8'), 
     172                        From = admin_email) 
    161173 
    162174 
  • qPloneComments/branches/plone-3.0/version.txt

    r1103 r1120  
    1 3.0.0 
     13.0.1