Re: Read a content file from a P7M

Discussion in 'Python' started by Emanuele Rocca, Mar 20, 2009.

  1. 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
    Emanuele Rocca, Mar 20, 2009
    #1
    1. Advertising

  2. 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.
    Michael Ströder, Mar 20, 2009
    #2
    1. Advertising

  3. Emanuele Rocca

    jumpjack

    Joined:
    Oct 25, 2007
    Messages:
    2
    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?
    jumpjack, Jul 16, 2012
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vittorio
    Replies:
    0
    Views:
    1,059
    Vittorio
    Jan 14, 2004
  2. hazz
    Replies:
    6
    Views:
    49,385
    SkyUCHC
    Jun 9, 2010
  3. Luca
    Replies:
    0
    Views:
    296
  4. Luca
    Replies:
    1
    Views:
    717
    Michael Ströder
    Mar 20, 2009
  5. Luca
    Replies:
    0
    Views:
    511
Loading...

Share This Page