Skip to main content

Latest Version Supported Python versions Build

Note
A fix has now been merged into Python 3.6.0.
This package remains as a backport for previous versions.

Summary

This package patches the python standard library’s mailcap module in order to correctly handle windcard entries.

The bug is documented on the bug tracker here: issue 14977

Installation

$ pip install mailcap-fix

Example

Consider a mailcap file that contains the following two lines

image/*; feh %s
image/jpeg; eog %s

Because the image/* entry is defined first, it should take precedence over the image/jpeg entry when searching for a match. This behavior is defined by RFC 1524. However, the standard library’s implementation will always evaluate wildcard entries last.

Before

>>> import mailcap
>>> d = mailcap.getcaps()
>>> # Incorrectly returns the second entry
>>> mailcap.findmatch(d, 'image/jpeg', filename='test.jpg')
('eog test.jpg', {'view': 'eog %s'})

After

>>> from mailcap_fix import mailcap
>>> d = mailcap.getcaps()
>>> # Correctly returns the wildcard entry
>>> mailcap.findmatch(d, 'image/jpeg', filename='test.jpg')
('feh test.jpg', {'view': 'feh %s', 'lineno': 0})

How it works

The goal of this patch is to conform to RFCC 1524, while preserving as much backwards compatibility as possible and without adding any “magic”.

mailcap_fix adds a new field lineno to each entry in the mailcap dict. This line number is then used to sort entries in descending order when searching for a match. For backwards compatability, if lineno is not present entries will simply not be sorted. Because RFC 1524 defines a whitelist of valid mailcap fieldnames, the addition of lineno should not conflict with any other mailcap fields.

Benchmark

Python 3.4.0
Ubuntu 14.04 LTS 64bit
Intel® Core™ i5-3210M CPU @ 2.50GHz × 4
8 GiB RAM

mailcap.get_caps() - per file

mailcap

mailcap_fix

mailcap_short.txt

0.081881 ms

0.084525 ms

mailcap_long.txt

17.746289 ms

18.407623 ms

mailcap.lookup() - avg function call

mailcap

mailcap_fix

mailcap_short.txt

0.000996 ms

0.003144 ms

mailcap_long.txt

0.000798 ms

0.002731 ms

Metadata

Release files for mailcap-fix 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mailcap-fix 1.0.1
File Size Uploaded Provenance
mailcap-fix-1.0.1.tar.gz 6.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for mailcap-fix 1.0.1
File Interpreter ABI Platform
mailcap_fix-1.0.1-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 16.8 kB

Release files / mailcap-fix-1.0.1.tar.gz

Download URL mailcap-fix-1.0.1.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
113c0b36091ac0b8181c33f2cd4905280e1bb316383d3c3fcae98c6df094910a
BLAKE2b-256 checksum
How to use checksums
c2e555485018f29af549d94e7a52ce9271ec88ff5f5f2f8246bcc7ce13e3897f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / mailcap_fix-1.0.1-py2.py3-none-any.whl

Download URL mailcap_fix-1.0.1-py2.py3-none-any.whl
Size 10.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
fd1371d9599fde5724037a02caede75da1b8b425f10da710d1b7798ac14b2540
BLAKE2b-256 checksum
How to use checksums
0b0d321abc5ca1efb647b51611bda34d6884099d390492c4627dc8b4c2322ff7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for mailcap-fix 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page