"""Create a message for posting and/or mailing.""" # meoWWW # Copyright 1999 G.J. Andruk # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or (at # your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. import config, os, sys, string, cgi, urllib, rfc822, mimetools, re from mimify import mime_decode_header from StringIO import StringIO OF=sys.stdout cfg = config.config() NL = '\015\012' scriptname = os.environ['SCRIPT_NAME'] reqinfo = string.split(urllib.unquote_plus(os.environ['QUERY_STRING'])) reqhash = {} for opt in ('group', 'article', 'msgid', 'mail'): reqhash[opt] = '' for option in reqinfo: if option[0:2] == 'g=': reqhash['group'] = string.split(option[2:], ',')[0] elif option[0:2] == 'a=': reqhash['article'] = option[2:] elif option[0:2] == 'm=': reqhash['msgid'] = option[2:] elif option == 'mail': reqhash['mail'] = 'yup' rh = cfg.connect() if reqhash['msgid'] or (reqhash['article'] and reqhash['group']): if reqhash['msgid']: art = rh.article('<%s>' % reqhash['msgid'])[3] else: rh.group(reqhash['group']) art = rh.article(reqhash['article'])[3] inhead = 1 for line in range(len(art)): if inhead: if art[line] == '': inhead = 0 else: if art[line]: art[line] = '> ' + art[line] artbuf = StringIO(string.join(art, '\n')) artmsg = rfc822.Message(artbuf) else: art = '' artmsg = None if artmsg: replyaddr = artmsg.getheader('reply-to') if not replyaddr: replyaddr = artmsg.getheader('from') else: replyaddr = '' replyaddr = cgi.escape(string.replace(replyaddr, '\n', ''), 1) if reqhash['mail']: dopost = '' domail = ' checked' else: dopost = ' checked' domail = '' OF.write('Content-Type: text/html' + NL + NL + '%s - compose%s' % (config.name, cfg.body)) if artmsg: if reqhash['mail']: OF.write('

Write a Private Reply

') else: OF.write('

Write a Public Followup

') else: OF.write('

Write a New Message

') OF.write("""

1. Fill in your headers.

""" % scriptname + NL) OF.write(""" ') if artmsg: try: grouplist = cgi.escape(artmsg.getheader('followup-to'), 1) if grouplist == 'poster': domail = ' checked' dopost = '' raise ValueError except: try: grouplist = cgi.escape(artmsg.getheader('newsgroups'), 1) except: grouplist = '' else: grouplist = cgi.escape(reqhash['group'], 1) grouplist = string.join(string.split(grouplist), '') while string.find(grouplist, ',,') != -1: grouplist = string.replace(grouplist, ',,', ',') if reqhash['mail']: OF.write('You need to fill in all the fields below.' + NL) else: OF.write("""You need to fill in From: and Subject:, and fill in and check least one of To: or Newsgroups:.""" + NL) if domail: OF.write('

NOTE: Followups have been set to be mailed to the' ' original poster.' + NL) modgroups = [] for froup in string.split(grouplist, ','): haswild = 0 for wildchar in '\\?*[]': if wildchar in grouplist: haswild = 1 break if not haswild: try: modflag = rh.list(('ACTIVE', froup))[1][0][-1] except: modflag = 'y' if modflag == 'm': modgroups.append(froup) if modgroups != []: OF.write(('

NOTE: If you include %s in your ' 'Newsgroups: header, your article will be mailed ' 'to the moderators and not appear ' 'unless/until they approve it.%s') % (cgi.escape(string.join(modgroups, ', ')), NL)) if artmsg: try: subject = artmsg.getheader('subject') if string.lower(subject[0:3]) != 're:': subject = 'Re: ' + subject subject = cgi.escape(string.replace(subject, '\n', ''), 1) except: subject = '(unknown subject)' else: subject = '' OF.write(("""

         From: 
      Subject: """
         % subject) + NL)

if reqhash['mail']:
    OF.write('' % grouplist)
else:
    OF.write(('   Newsgroups: ')
             % (grouplist, dopost) + NL)

OF.write('' % grouplist)
OF.write('           To: '
         % replyaddr)
if reqhash['mail']:
    OF.write('' + NL)
else:
    OF.write(('') % domail
    + NL)

if reqhash['mail']:
    OF.write('')
    OF.write('')
else:
    OF.write('  Followup-To: '
             + NL)
    OF.write(' Organization: ')
OF.write("""

2. Enter your message.


3. Send it on its way.

Please make sure your (and your recipient's) address is correct. "Spam block" addresses and mail don't mix.
If you didn't mean to send mail, press your browser's back button.""") else: OF.write("""

3. Read the Fine Print.

This form posts news to thousands of machines throughout the entire civilized world. Your message may cost the net hundreds if not thousands of dollars to send everywhere. Please be sure you know what you are doing.
If you are not sure you know what you are doing, press your browser's back button. """) if artmsg: try: references = string.join(string.split(artmsg.getheader('references'))) except: references = '' try: references = references + ' ' + artmsg.getheader('message-id') except: pass else: references = '' OF.write(('' % cgi.escape(references, 1)) + NL) OF.write('
' + NL)