Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't parse incoming messages with Content-Type: application/pkcs7-mime #40

Open
garethrees opened this issue Oct 5, 2017 · 8 comments

Comments

@garethrees
Copy link
Member

http://www.infoprovsechny.cz/request/dokumentace_k_projektu_socialni?nocache=incoming-11330#incoming-11330

screen shot 2017-10-05 at 12 51 26

@garethrees
Copy link
Member Author

@garethrees garethrees removed their assignment Jan 24, 2018
@garethrees garethrees changed the title Unreadable Response Can't parse incoming messages with Content-Type: application/pkcs7-mime Jan 30, 2018
@garethrees
Copy link
Member Author

@garethrees
Copy link
Member Author

Well, here's how you can extract the PDF from one example:

f = File.read('tmp/11378.eml')
m = Mail.new(f)
a = OpenSSL::ASN1.decode(Base64.decode64(m.body.raw_source))
v = a.value[1].value[0].value[2].value[1].value[0].value.map(&:value).join
eml = Mail.new(v)
File.open('tmp/blah.pdf', 'wb') { |f| f.write(eml.attachments.first.decoded) }
File.open('tmp/blah.pdf', &:gets)
# => "%PDF-1.3\r1 0 obj\r<</Type /XObject /Subtype /Image /Name /Im1 /Width 1240 /Height 1753 /Length 108309/ColorSpace /DeviceRGB /BitsPerComponent 8 /Filter [ /DCTDecode ] >> stream\r\xFF\xD8\xFF\xE0\u0000\u0010JFIF\u0000\u0001\u0001\u0001\u0000\x96\u0000\x96\u0000\u0000\xFF\xDB\u0000C\u0000\b\u0006\u0006\a\u0006\u0005\b\a\a\a\t\t\b\n"

@dracos
Copy link
Member

dracos commented Sep 6, 2018

This is a bit nicer (ruby provides no docs for this class, https://stackoverflow.com/a/1999887/669631 was of most help):

...
a = OpenSSL::PKCS7.new(Base64.decode64(m.body.raw_source))
a.verify([], OpenSSL::X509::Store.new, nil, OpenSSL::PKCS7::NOVERIFY) # Don't verify anything!
v = a.data
...

@garethrees
Copy link
Member Author

Now we know how to unwrap the pkcs7-mime, we need to do inject this in to the mail parsing somewhere. I think the best place to start looking is MailHandler.decode_attached_part, but I need to figure out how all the mail parsing works.

@lukaskovarik
Copy link

lukaskovarik commented Jan 3, 2020

Hi, everyone, can we help with resolving this issue? Unfortunately I don't have Ruby dev expertise, but I have a Python team here in Prague, would that be of any help? I realise it's a long shot, but maybe there's some language-independent research to be done, for example?

@garethrees
Copy link
Member Author

Looks like all the tools we need are available to us to correctly parse the content type – its more of a case of integrating them in to Alaveteli.

@lukaskovarik
Copy link

OK, understand. If there's anything we can help with in the future, please do let me know! Thanks again for having a look at this, much appreciated.

@gbp gbp removed their assignment Oct 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants