Note: This is a public test instance of Red Hat Bugzilla. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback at bugzilla.redhat.com.
Bug 663674 - BugzillaBase.openattachment fails with UTF-8 attachment file names (patch included)
Summary: BugzillaBase.openattachment fails with UTF-8 attachment file names (patch inc...
Keywords:
Status: ASSIGNED
Alias: None
Product: Fedora
Classification: Fedora
Component: python-bugzilla
Version: 14
Hardware: Unspecified
OS: Unspecified
low
medium
Target Milestone: ---
Assignee: Cole Robinson
QA Contact: Fedora Extras Quality Assurance
URL: http://example.com
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2010-12-16 15:28 UTC by Karel Klíč
Modified: 2023-09-06 16:01 UTC (History)
2 users (show)

Fixed In Version: 2023-09-06 10:33:38.178702
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2023-09-06 14:33:39 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)
Proposed patch (1.36 KB, application/octet-stream)
2010-12-16 15:28 UTC, Karel Klíč
no flags Details
Better proposed patch (1.32 KB, patch)
2010-12-21 17:57 UTC, Karel Klíč
no flags Details | Diff
An empty test file with a utf-8 filename (45 bytes, text/plain)
2011-06-01 18:57 UTC, Will Woods
no flags Details

Description Karel Klíč 2010-12-16 15:28:01 UTC
Created attachment 469147 [details]
Proposed patch

I downloaded some attachments and got a traceback:
> # here bz is a RHBugzilla object
> file = bz.openattachment(attachment_id)
File "/usr/lib/python2.7/site-packages/bugzilla/base.py", line 681, in openattachment
    (dummy,filename) = filename_parm.split('=')
ValueError: too many values to unpack


The filename_parm contained the following string:
filename="=?UTF-8?Q?Meteorologick=C3=A9=20zpr=C3=A1vy=205=5F04?=.pdf"

So the problem was that the filename contained '=' characters and the code wasn't expecting this. This was fixed by limiting the split count:
    (dummy,filename) = filename_parm.split('=', 1)

This way the filename became "right":
=?UTF-8?Q?Meteorologick=C3=A9=20zpr=C3=A1vy=205=5F04?=.pdf

I saw a comment in the openattachment() method about RFC 2045. email.header.decode_header() function from standard Python library can decode RFC 2045 strings. Unfortunately the simplest way fails:
email.header.decode_header("=?UTF-8?Q?Meteorologick=C3=A9=20zpr=C3=A1vy=205=5F04?=.pdf")

email.header.decode_header() was not able to handle the ".pdf" suffix after the encoded sequence. This is discussed in Python upstream: http://bugs.python.org/issue1079. Some Python developers seem to think this is not a bug on Python side. However, this is what we get from Bugzilla.

So the easiest solution was to transform one encoded sequence at a time:
# email.header.decode_header cannot handle strings not ending with '?=',
# so let's transform one =?...?= part at a time
while True:
    match = re.search("=\?.*?\?=", filename)
    if match is None:
        break
    filename = filename[:match.start()] + email.header.decode_header(match.group(0))[0][0] + filename[match.end():]

After that change the file name of the attachment was ok:
Meteorologické zprávy 5_04.pdf

How reproducible:
always

Steps to Reproduce:
Try to download the second attachment of bug #586615 using python-bugzilla
  
Actual results:
Exception is thrown

Expected results:
Attachment downloaded with proper file name.



Please consider the attached patch. It makes it possible to work with attachments with UTF-8 names that are returned by Red Hat Bugzilla.

Comment 1 Karel Klíč 2010-12-21 17:57:36 UTC
Created attachment 470041 [details]
Better proposed patch

Comment 2 Karel Klíč 2010-12-21 17:59:35 UTC
I saw this approach in pymailheaders, it's much better solution.

Comment 3 Will Woods 2011-06-01 18:57:50 UTC
Created attachment 502352 [details]
An empty test file with a utf-8 filename

This file is being used to test fixes for this bug.

Comment 4 Will Woods 2011-06-01 21:30:30 UTC
Fix pushed to git master:

http://git.fedorahosted.org/git/?p=python-bugzilla.git;a=commitdiff;h=38d0834

Comment 5 Cole Robinson 2012-02-04 22:39:28 UTC
F14 is EOL. Doesn't look like this fix ended up there, but it the fixed version is in F16.

Comment 8 Cole Robinson 2021-07-20 13:19:44 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 10 Cole Robinson 2021-07-20 13:19:50 UTC
yet another test comment 2021-07-20 09:19:49.683412

Comment 13 Cole Robinson 2021-07-20 13:21:41 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 15 Cole Robinson 2021-07-20 13:21:47 UTC
yet another test comment 2021-07-20 09:21:47.034172

Comment 18 Cole Robinson 2021-07-20 13:27:48 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 20 Cole Robinson 2021-07-20 13:27:54 UTC
yet another test comment 2021-07-20 09:27:53.643243

Comment 23 Cole Robinson 2021-07-20 13:30:52 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 25 Cole Robinson 2021-07-20 13:30:58 UTC
yet another test comment 2021-07-20 09:30:57.554661

Comment 28 Cole Robinson 2021-07-27 17:14:55 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 30 Cole Robinson 2021-07-27 17:15:02 UTC
yet another test comment 2021-07-27 13:15:01.352792

Comment 33 Cole Robinson 2021-07-27 17:17:49 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 35 Cole Robinson 2021-07-27 17:17:56 UTC
yet another test comment 2021-07-27 13:17:56.040323

Comment 38 Cole Robinson 2021-07-27 17:22:02 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 40 Cole Robinson 2021-07-27 17:22:08 UTC
yet another test comment 2021-07-27 13:22:08.061354

Comment 43 Cole Robinson 2021-07-27 17:24:49 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 45 Cole Robinson 2021-07-27 17:24:56 UTC
yet another test comment 2021-07-27 13:24:55.379265

Comment 48 Cole Robinson 2021-10-04 16:29:24 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 50 Cole Robinson 2021-10-04 16:29:33 UTC
yet another test comment 2021-10-04 12:29:32.734023

Comment 53 Cole Robinson 2021-10-04 16:33:04 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 55 Cole Robinson 2021-10-04 16:33:13 UTC
yet another test comment 2021-10-04 12:33:12.371803

Comment 58 Cole Robinson 2021-10-04 16:59:47 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 60 Cole Robinson 2021-10-04 16:59:55 UTC
yet another test comment 2021-10-04 12:59:54.195091

Comment 63 Cole Robinson 2021-10-04 17:03:56 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 65 Cole Robinson 2021-10-04 17:04:04 UTC
yet another test comment 2021-10-04 13:04:03.585397

Comment 68 Cole Robinson 2021-10-05 16:36:04 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 70 Cole Robinson 2021-10-05 16:36:12 UTC
yet another test comment 2021-10-05 12:36:11.970878

Comment 73 Cole Robinson 2021-10-05 16:40:03 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 75 Cole Robinson 2021-10-05 16:40:12 UTC
yet another test comment 2021-10-05 12:40:11.176287

Comment 78 Cole Robinson 2021-10-05 17:11:39 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 80 Cole Robinson 2021-10-05 17:11:48 UTC
yet another test comment 2021-10-05 13:11:47.362440

Comment 83 Cole Robinson 2021-10-05 17:21:35 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 85 Cole Robinson 2021-10-05 17:21:46 UTC
yet another test comment 2021-10-05 13:21:45.806397

Comment 88 Cole Robinson 2021-10-05 17:25:29 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 90 Cole Robinson 2021-10-05 17:25:37 UTC
yet another test comment 2021-10-05 13:25:36.996477

Comment 93 Cole Robinson 2021-10-05 17:27:35 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 95 Cole Robinson 2021-10-05 17:27:44 UTC
yet another test comment 2021-10-05 13:27:43.987856

Comment 98 Cole Robinson 2021-10-05 17:31:38 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 100 Cole Robinson 2021-10-05 17:31:47 UTC
yet another test comment 2021-10-05 13:31:46.053204

Comment 103 Cole Robinson 2021-10-05 17:58:41 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 105 Cole Robinson 2021-10-05 17:58:49 UTC
yet another test comment 2021-10-05 13:58:48.537038

Comment 108 Cole Robinson 2021-10-05 18:03:06 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 110 Cole Robinson 2021-10-05 18:03:15 UTC
yet another test comment 2021-10-05 14:03:14.169375

Comment 113 Cole Robinson 2021-10-05 18:17:40 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 115 Cole Robinson 2021-10-05 18:17:48 UTC
yet another test comment 2021-10-05 14:17:47.463302

Comment 118 Cole Robinson 2021-10-05 18:21:13 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 120 Cole Robinson 2021-10-05 18:21:22 UTC
yet another test comment 2021-10-05 14:21:21.152302

Comment 123 Cole Robinson 2021-10-05 18:31:29 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 125 Cole Robinson 2021-10-05 18:31:37 UTC
yet another test comment 2021-10-05 14:31:36.947878

Comment 128 Cole Robinson 2021-10-05 18:35:13 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 130 Cole Robinson 2021-10-05 18:35:23 UTC
yet another test comment 2021-10-05 14:35:21.847640

Comment 133 Cole Robinson 2021-10-05 19:09:29 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 135 Cole Robinson 2021-10-05 19:09:38 UTC
yet another test comment 2021-10-05 15:09:37.014918

Comment 138 Cole Robinson 2021-10-05 19:13:00 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 140 Cole Robinson 2021-10-05 19:13:09 UTC
yet another test comment 2021-10-05 15:13:08.355873

Comment 143 Cole Robinson 2021-10-05 19:27:52 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 145 Cole Robinson 2021-10-05 19:28:01 UTC
yet another test comment 2021-10-05 15:28:00.197072

Comment 148 Cole Robinson 2021-10-05 19:31:28 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 150 Cole Robinson 2021-10-05 19:31:37 UTC
yet another test comment 2021-10-05 15:31:36.144834

Comment 153 Cole Robinson 2021-10-05 20:28:26 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 155 Cole Robinson 2021-10-05 20:28:34 UTC
yet another test comment 2021-10-05 16:28:33.760204

Comment 158 Cole Robinson 2021-10-05 20:31:54 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 160 Cole Robinson 2021-10-05 20:32:02 UTC
yet another test comment 2021-10-05 16:32:02.011083

Comment 163 Cole Robinson 2021-10-05 20:35:49 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 165 Cole Robinson 2021-10-05 20:35:58 UTC
yet another test comment 2021-10-05 16:35:57.763935

Comment 168 Cole Robinson 2021-10-05 20:38:02 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 170 Cole Robinson 2021-10-05 20:38:11 UTC
yet another test comment 2021-10-05 16:38:10.282104

Comment 173 Cole Robinson 2021-10-05 20:41:29 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 175 Cole Robinson 2021-10-05 20:41:37 UTC
yet another test comment 2021-10-05 16:41:36.489929

Comment 178 Cole Robinson 2022-01-12 17:59:21 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 180 Cole Robinson 2022-01-12 17:59:29 UTC
yet another test comment 2022-01-12 12:59:28.919806

Comment 183 Cole Robinson 2022-01-12 18:02:46 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 185 Cole Robinson 2022-01-12 18:02:53 UTC
yet another test comment 2022-01-12 13:02:52.377644

Comment 188 Cole Robinson 2022-02-03 16:23:48 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 190 Cole Robinson 2022-02-03 16:23:56 UTC
yet another test comment 2022-02-03 11:23:55.625561

Comment 193 Cole Robinson 2022-02-03 16:27:21 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 195 Cole Robinson 2022-02-03 16:27:29 UTC
yet another test comment 2022-02-03 11:27:28.601521

Comment 198 Cole Robinson 2023-08-20 11:22:15 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 200 Cole Robinson 2023-08-20 11:22:21 UTC
yet another test comment 2023-08-20 07:22:21.123603

Comment 203 Cole Robinson 2023-08-20 11:24:18 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 205 Cole Robinson 2023-08-20 11:24:25 UTC
yet another test comment 2023-08-20 07:24:24.694688

Comment 208 Cole Robinson 2023-08-20 11:47:04 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 210 Cole Robinson 2023-08-20 11:47:11 UTC
yet another test comment 2023-08-20 07:47:10.336139

Comment 213 Cole Robinson 2023-08-20 11:50:07 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 215 Cole Robinson 2023-08-20 11:50:14 UTC
yet another test comment 2023-08-20 07:50:13.659206

Comment 218 Cole Robinson 2023-08-20 12:56:22 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 220 Cole Robinson 2023-08-20 12:56:29 UTC
yet another test comment 2023-08-20 08:56:28.929181

Comment 223 Cole Robinson 2023-08-20 13:00:04 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 225 Cole Robinson 2023-08-20 13:00:11 UTC
yet another test comment 2023-08-20 09:00:10.238414

Comment 228 Cole Robinson 2023-08-20 13:09:47 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 230 Cole Robinson 2023-08-20 13:09:55 UTC
yet another test comment 2023-08-20 09:09:54.266056

Comment 233 Cole Robinson 2023-08-20 13:12:47 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 235 Cole Robinson 2023-08-20 13:12:54 UTC
yet another test comment 2023-08-20 09:12:53.195402

Comment 238 Cole Robinson 2023-09-05 15:33:14 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 240 Cole Robinson 2023-09-05 15:33:25 UTC
yet another test comment 2023-09-05 11:33:24.335237

Comment 243 Cole Robinson 2023-09-05 15:37:15 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 245 Cole Robinson 2023-09-05 15:37:26 UTC
yet another test comment 2023-09-05 11:37:25.916504

Comment 248 Cole Robinson 2023-09-06 14:30:28 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 250 Cole Robinson 2023-09-06 14:30:35 UTC
yet another test comment 2023-09-06 10:30:34.941603

Comment 253 Cole Robinson 2023-09-06 14:33:33 UTC

*** This bug has been marked as a duplicate of bug 461686 ***

Comment 255 Cole Robinson 2023-09-06 14:33:41 UTC
yet another test comment 2023-09-06 10:33:40.847759


Note You need to log in before you can comment on or make changes to this bug.