Formulator / python / string question

Bas Leeflang <[email protected]>
Newsgroups gmane.comp.web.zope.silva.devel
Organization Bijvoet Center
Message-ID <[email protected]>
Hi,

I am trying to have a python scrypt to send the results from a 
formulator form to both an e-mail recipient and a MySQL database. The 
latter works fine. However, the e-mail gives me problems. Please 
checkout the following part from the script:

    # Can we connect to the MailHost?
    try:
      mailhost = getattr(context, context.superValues('Mail Host')[0].id)
    except:
      raise AttributeError, "Can't find a Mail Host object."

    mTo = address[1] + ', ' + result['email']
    mFrom = result['email']
    mSubj = '** NMRDG; 8 October 2004; Utrecht **'
    message = []
    message.append('This email has been automatically sent to you from 
the server.')
    message.append('** NMRDG meeting **')
    message.append('** 8 October 2004 **\n\n')
    for field in form.get_fields():
      message.append(string.ljust(field.get_value('title') + ": ", 28) + 
result[field.id])

    mMsg = '\n'.join(message)
    mailhost.send(mMsg, mto=mTo, mfrom=mFrom, subject=mSubj)
    # enter the data into the database
    context.nmrdg_db_insert(salutation=result['salutation'], 
.....skipped......)
    return printed

When I leave out the 'for field... part that essentially readsout the 
form results' I get a normally formated e-mail:

This email has been automatically sent to you from the server.
** NMRDG meeting **
** 8 October 2004 **

(Obviously without the relevant data). However when I include
    for field in form.get_fields():
      message.append(string.ljust(field.get_value('title') + ": ", 28) + 
result[field.id])
the entire mMsg in the e-mail gets reformatted. What basically happens 
is that each character is followed by 3 spaces. OK everything is 
there... But it is virtually unreadible.:

T   h   i   s       e   m   a   i   l       h   a   s       b   e   e   n       a   u   t   o   m   a   t   i   c   a   l   l   y       s   e   n   t       t   o       y   o   u       f   r   o   m       t   h   e       s   e   r   v   e   r   .   
   *   *       N   M   R   D   G       m   e   e   t   i   n   g       *   *   
   *   *       8       O   c   t   o   b   e   r       2   0   0   4       *   *   
   
   
   S   a   l   u   t   a   t   i   o   n   :                                                                       M   r   
   T   i   t   l   e   :                                                                                           D   r   
   L   a   s   t       N   a   m   e   :                                                                           L   e   e   f   l   a   n   g   


Could anyone clarify this to me?

Cheers,
Bas
   F   i   r   s   t       N   a   m   e   :                                                                       B   a   s       R   



-- 
Dr. Bas R. Leeflang
Bijvoet Center for Biomolecular Research Tel : +31.30.253.3498
Utrecht University                       Fax : +31.30.254.0980
Padualaan 8, NL-3584 CH  Utrecht         Email: [email protected]
The Netherlands                          http://www.bijvoet-center.nl
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.