jkraemer / mail-gpg

GPG/MIME extension for the Ruby Mail Library
MIT License
69 stars 24 forks source link

Parse decrypted email #62

Open rezamarandi opened 5 years ago

rezamarandi commented 5 years ago

Hi, I have two problem with mail-gpg explain in below first of all i receive email through http payload with Postal gem, the encoded mail is only one file called msg.asc, I created new mail object with msg.asc source in body ..

      def decrypt_message
        return unless mail_object.encrypted?

        response = mail_object.decrypt(password: Rails.application.secrets.pgp_secret_key)
        params[:html_body] = response
        params[:plain_body] = response
      end
      def mail_object
        mail = Mail.new
        mail.body = Base64.decode64(params[:attachments][0][:data])

        mail
      end

Is this the right way for decode ? and second problem is : the result is not a mail object , its just the source of email, something like the structure below: and i couldn't parse this source, any idea about that ?

gpg: encrypted with 2048-bit RSA key, ID 0A8387EEB8F331211, created 2019-06-18
      "reza-dev@stg-consulting.test.de"
gpg: encrypted with 2048-bit RSA key, ID 5CA8644C56CC12BD, created 2019-06-18
      "test-dev-test-de@test.de <test-dev-test-de@test.de>"
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="3c4321aa4bd8591a78df6a5539b7bbb2"

--3c4321aa4bd8591a78df6a5539b7bbb2
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline; filename="msg.txt"

Subject: subject is encrypted too

Why body and subject is encrypted =3F

--3c4321aa4bd8591a78df6a5539b7bbb2
Content-Type: text/plain
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
 filename="Modern.srt"

77u/MQ0KMDA6MDA6MDMsMjM3IC0tPiAwMDowMDowNSw2MzkNCuKAq9qG2LHYpyDYrdix2YEg2YbZ
hduM2LLZhtuM2J8NCuKAq9in2LIg2K/Ys9iqINmF2YYg2LnYtdio2KfZhtuMINmH2LPYqtuM2J8N

--3c5991aa4bd8591a78df6a5539b7aaa2