Read a content file from a P7M

Emanuele Rocca ema at
Fri Mar 20 15:12:44 CET 2009

On 11/03/09 - 05:05, Luca wrote:
> There is standard or sugested way in python to read the content of a P7M file?
> I don't need no feature like verify sign, or sign using a certificate.
> I only need to extract the content file of the p7m (a doc, a pdf, ...)

For PDF files you can just remove the P7M content before %PDF and after

The following snippet converts /tmp/test.p7m into PDF, saving the 
resulting document into /tmp/test.pdf:

import re
from gzip import GzipFile

contents = GzipFile('/tmp/test.p7m').read()

contents_re = re.compile('%PDF-.*%%EOF', re.MULTILINE | re.DOTALL)
contents =

open('/tmp/test.pdf', 'w').write(contents)


More information about the Python-list mailing list