~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/mail/mailimport.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20080622211713-inlv5k4eifxckelr
ImportĀ upstreamĀ versionĀ 1.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
import email
14
14
from email.Utils import getaddresses, parsedate_tz, mktime_tz
15
15
 
16
 
from MoinMoin import wikiutil, user
 
16
from MoinMoin import user
17
17
from MoinMoin.action.AttachFile import add_attachment, AttachmentAlreadyExists
18
18
from MoinMoin.Page import Page
19
19
from MoinMoin.PageEditor import PageEditor
 
20
from MoinMoin.request.request_cli import Request as RequestCLI
20
21
# python, at least up to 2.4, ships a broken parser for headers
21
22
from MoinMoin.support.HeaderFixed import decode_header
22
23
 
183
184
        generate_summary = True
184
185
        pagename = pagename[1:].lstrip()
185
186
 
186
 
    pagename = wikiutil.normalize_pagename(pagename, request.cfg)
 
187
    pagename = request.normalizePagename(pagename)
187
188
 
188
189
    if choose_html and msg['html']:
189
190
        content = "{{{#!html\n%s\n}}}" % msg['html'].replace("}}}", "} } }")
231
232
 
232
233
    for att in msg['attachments']:
233
234
        i = 0
234
 
        while i < 1000: # do not create a gazillion attachments if something
235
 
                        # strange happens, give up after 1000.
 
235
        while 1:
236
236
            if i == 0:
237
237
                fname = att.filename
238
238
            else:
244
244
                else:
245
245
                    fname = att.filename + new_suffix
246
246
            try:
247
 
                # att.data can be None for forwarded message content - we can
248
 
                # just ignore it, the forwarded message's text will be present
249
 
                # nevertheless
250
 
                if att.data is not None:
251
 
                    # get the fname again, it might have changed
252
 
                    fname, fsize = add_attachment(request, pagename, fname, att.data)
253
 
                    attachments.append(fname)
254
 
                break
 
247
                # get the fname again, it might have changed
 
248
                fname = add_attachment(request, pagename, fname, att.data)
 
249
                attachments.append(fname)
255
250
            except AttachmentAlreadyExists:
256
251
                i += 1
 
252
            else:
 
253
                break
257
254
 
258
255
    # build an attachment link table for the page with the e-mail
259
256
    attachment_links = [""] + [u'''[[attachment:%s|%s]]''' % ("%s/%s" % (pagename, att), att) for att in attachments]
316
313
 
317
314
if __name__ == "__main__":
318
315
    if len(sys.argv) > 1:
319
 
        request_url = sys.argv[1]
 
316
        url = sys.argv[1]
320
317
    else:
321
 
        request_url = None
 
318
        url = 'localhost/'
322
319
 
323
 
    from MoinMoin.web.contexts import ScriptContext
324
 
    request = ScriptContext(url=request_url)
 
320
    request = RequestCLI(url=url)
325
321
 
326
322
    try:
327
323
        import_mail_from_file(request, infile)