Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exception with Message.get_filename() #39414

Closed
customdesigned mannequin opened this issue Oct 15, 2003 · 3 comments
Closed

exception with Message.get_filename() #39414

customdesigned mannequin opened this issue Oct 15, 2003 · 3 comments
Assignees
Labels
stdlib Python modules in the Lib dir

Comments

@customdesigned
Copy link
Mannequin

customdesigned mannequin commented Oct 15, 2003

BPO 824417
Nosy @warsaw
Files
  • test1: test input for scriptlet
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/warsaw'
    closed_at = <Date 2003-11-21.16:29:29.000>
    created_at = <Date 2003-10-15.21:39:27.000>
    labels = ['library']
    title = 'exception with Message.get_filename()'
    updated_at = <Date 2003-11-21.16:29:29.000>
    user = 'https://bugs.python.org/customdesigned'

    bugs.python.org fields:

    activity = <Date 2003-11-21.16:29:29.000>
    actor = 'barry'
    assignee = 'barry'
    closed = True
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2003-10-15.21:39:27.000>
    creator = 'customdesigned'
    dependencies = []
    files = ['1073']
    hgrepos = []
    issue_num = 824417
    keywords = []
    message_count = 3.0
    messages = ['18645', '18646', '18647']
    nosy_count = 2.0
    nosy_names = ['barry', 'customdesigned']
    pr_nums = []
    priority = 'normal'
    resolution = 'out of date'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue824417'
    versions = ['Python 2.2']

    @customdesigned
    Copy link
    Mannequin Author

    customdesigned mannequin commented Oct 15, 2003

    The following scriptlet:
    -----------t.py-----------------

    import sys
    import email
    
    msg = email.message_from_file(sys.stdin)
    for part in msg.walk():
      print part.get_params()
      print part.get_filename()

    gets an exception when fed the attached email
    (extracted from a real life non-spam message).

    $ python2 t.py <test1
    [('multipart/mixed', ''), ('boundary',
    '=-mkF0Ur/S0HaYfa60OEsM')]
    None
    [('multipart/alternative', ''), ('boundary',
    '=-VowfKaQaEHb81enMCUlR')]
    None
    [('text/plain', '')]
    None
    [('text/html', ''), ('charset', 'utf-8')]
    None
    [('application/rtf', ''), ('name', (None, None, '14676
    World Transportation Systems OF, from arrival TIA
    terminal to door and from Durres port to TIA.rtf'))]
    Traceback (most recent call last):
      File "t.py", line 7, in ?
        print part.get_filename()
      File "/usr/lib/python2.2/email/Message.py", line 711,
    in get_filename
        return unicode(newvalue[2], newvalue[0])
    TypeError: unicode() argument 2 must be string, not None

    @customdesigned customdesigned mannequin closed this as completed Oct 15, 2003
    @customdesigned customdesigned mannequin assigned warsaw Oct 15, 2003
    @customdesigned customdesigned mannequin added the stdlib Python modules in the Lib dir label Oct 15, 2003
    @customdesigned customdesigned mannequin closed this as completed Oct 15, 2003
    @customdesigned customdesigned mannequin assigned warsaw Oct 15, 2003
    @customdesigned customdesigned mannequin added the stdlib Python modules in the Lib dir label Oct 15, 2003
    @customdesigned
    Copy link
    Mannequin Author

    customdesigned mannequin commented Oct 15, 2003

    Logged In: YES
    user_id=142072

    The documentation for the get_param method suggests the
    following code when the value is a tuple:

                param = msg.get_param('foo')
                if isinstance(param, tuple):
                    param = unicode(param[2], param[0])

    The get_filename method follows this advice, but it doesn't
    work when the encoding is None.

    I fixed this by changing Message.get_filename to this:

      def get_filename(self, failobj=None):
          """Return the filename associated with the payload if
    present.
        
          The filename is extracted from the Content-Disposition
    header's
          `filename' parameter, and it is unquoted.
          """
          missing = []
          filename = self.get_param('filename', missing,
    'content-disposition')
          if filename is missing:
              return failobj
          if isinstance(filename, TupleType):
              # It's an RFC 2231 encoded parameter
              newvalue = _unquotevalue(filename)
              if newvalue[0]:
                return unicode(newvalue[2], newvalue[0])
              return unicode(newvalue[2])
          else:
              newvalue = _unquotevalue(filename.strip())
              return newvalue

    @warsaw
    Copy link
    Member

    warsaw commented Nov 21, 2003

    Logged In: YES
    user_id=12800

    This has been fixed in cvs for Python 2.2.4 if that ever
    gets released. It also works fine for Python 2.3.2.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant