## Controller Script Python "validate_anon_reply"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind state=state  
##bind subpath=traverse_subpath
##parameters=subject=''
##title=validates the email adresses

request = context.REQUEST
mtool = context.portal_membership

if not subject:
    state.setError('subject',
                   'Please include a message subject.',
                   'subject_required')

# we only care about send_from_address if the user is anonymous
if mtool.isAnonymousUser():
    send_from_address = request.get('send_from_address', '')
    plone_utils=context.plone_utils
    if not send_from_address or \
           not plone_utils.validateEmailAddresses(send_from_address):
        state.setError('send_from_address',
                       'Please submit a valid email address.',
                       'email_required')

if state.getErrors():
    return state.set(status='failure', portal_status_message='Please correct the indicated errors.')
else:
    return state
