Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Read a content file from a P7M

Reply
Thread Tools

Re: Read a content file from a P7M

 
 
Emanuele Rocca
Guest
Posts: n/a
 
      03-20-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
%%EOF.

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 = contents_re.search(contents).group()

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

HTH.
ciao,
ema
 
Reply With Quote
 
 
 
 
Michael Ströder
Guest
Posts: n/a
 
      03-20-2009
Emanuele Rocca wrote:
> 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
> %%EOF.


If the .p7m is a S/MIME message then it might be encrypted. So you have
to decrypt it. It could also be a opaque-signed S/MIME message. But
still I'd use a decent S/MIME module to extract the stuff therein.

Ciao, Michael.
 
Reply With Quote
 
 
 
 
jumpjack jumpjack is offline
Junior Member
Join Date: Oct 2007
Posts: 2
 
      07-16-2012
Sorry for digging up such an old thread, but I googled for days with no luck.

I have a filename.pdf.tsd file, which I'm said to contain a pdf signed with p7m but is corrupt, or no more compatible with the updated program used to create it.
Acrobat can't read the file at all.
PDF xChange reader can read the PDF contents but can't read the signatures.

How coul I extract the signed pdf from the TSD file?

I can't even find info on TSD file format, so I'm really in trouble to figure out how to handle it.
Could I extract signature and timestamp data from the tsd file by manually looking at it with an hex viewer?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
error: Only Content controls are allowed directly in a content page that contains Content controls. hazz ASP .Net 6 06-09-2010 01:54 PM
Re: Read a content file from a P7M Luca Python 0 08-28-2009 01:33 PM
Re: Read a content file from a P7M Luca Python 1 03-20-2009 03:51 PM
Read a content file from a P7M Luca Python 0 03-11-2009 04:05 PM
ParsingException reading P7M file Vittorio Java 0 01-14-2004 10:45 AM



Advertisments