This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

A patched mailcap module that conforms to RFC 1524

Project Description

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
Release History

Release History

This version
History Node

1.0.1

History Node

1.0.0

History Node

0.2.0

History Node

0.1.3

History Node

0.1.2

History Node

0.1.1

History Node

0.1.0

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
mailcap_fix-1.0.1-py2.py3-none-any.whl (10.4 kB) Copy SHA256 Checksum SHA256 py2.py3 Wheel Dec 31, 2016
mailcap-fix-1.0.1.tar.gz (6.3 kB) Copy SHA256 Checksum SHA256 Source Dec 31, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting