Gnus development mailing list
 help / color / mirror / Atom feed
From: Florian Weimer <fw@s.netic.de>
Subject: Re: MML, message-send-hook and automatically GnuPG-signing messages.
Date: 16 Jan 2000 09:14:50 +0100	[thread overview]
Message-ID: <87d7r25t6t.fsf@deneb.cygnus.argh.org> (raw)
In-Reply-To: <wtnpuv5wurx.fsf@licia.dtek.chalmers.se>

Jonas Steverud <d4jonas@dtek.chalmers.se> writes:

> I use mc-bbdb.el to automatically encrypt to some people (using
> Mailcrypt and depening on what a special field in the BBDB is saying)
> and this adds mc-bbdb-auto-encrypt-send to message-send-hook. I also
> had until just recently

> What is the best way of solving this?
> 
> 1. Force evaluate MML before my encryption (either by hand or by
>    adding something to message-send-hook). Kludge?
> 
> 2. Add the sign/encrypt parts *after* the MML evaluation, but how is
>    this done? I think this is preferred since encryption and signing
>    should go after all other mail processing is finished and right
>    before the mail actually goes away.

3.  Use `mml-generate-multipart-alist'. Example (untested with current
    Gnus version):

(setq mml-generate-multipart-alist
  '(("signed" . rfc2015-generate-signed-multipart)
    ("encrypted" . rfc2015-generate-encrypted-multipart)))

(defun rfc2015-generate-enclosed-parts-and-funcall (cont func)
  "Generate the the parts in a temporary buffer and call FUNC.
Returns the result of FUNC."
  ;; Descend one level.
  (setq cont (cddr cont))
  (if (> (length cont) 1)
      ;; multipart/signed may not to contain more than one part.
      ;; Add an intermediate multipart/mixed if necessary.
      (setq cont (append '(multipart (type . "mixed")) cont))
    ;; Descend to the contained part.
    (setq cont (car cont)))
  ;; Generate contained parts and signature.  Do not include the
  ;; enclosing MIME boundaries in the signature.
  (with-temp-buffer
    ;; Generate subparts.
    (mml-generate-mime-1 cont)
    ;; Make sure that last line ends with <LF>.
    (goto-char (point-max))
    (unless (bolp)
      (insert "\n"))
    (funcall func)))

(defun rfc2015-generate-signed-multipart (cont)
  (let* ((mml-boundary (mml-compute-boundary cont))
         ;; Make sure that the enclosed parts are encoded in the safest way.
         (quoted-printable-encode-from t)
         (mm-encode-no-7/8bit t)
         (parts-and-signature
          (rfc2015-generate-enclosed-parts-and-funcall
           cont
           (lambda ()
             (cons 
              (buffer-string)
              (rfc2015-gpg-sign (current-buffer))))))
         (parts (car parts-and-signature))
         (signature (cdr parts-and-signature)))
    (insert (format "Content-Type: multipart/signed; boundary=\"%s\";\n"
                    mml-boundary)
            "\tmicalg=pgp-md5; protocol=\"application/pgp-signature\"\n"
            "\n"
            "\n--" mml-boundary "\n")
    ;; Insert generated parts and signature.
    (insert parts)
    (insert "\n--" mml-boundary "\n"
            "Content-Type: application/pgp-signature\n"
            "\n"
            signature
            "\n--" mml-boundary "--\n")))

(defun rfc2015-generate-encrypted-multipart (cont)
  (let* ((mml-boundary (mml-compute-boundary cont))
         (encrypted-parts
          (rfc2015-generate-enclosed-parts-and-funcall
           cont
           (lambda ()
             (rfc2015-gpg-encrypt)
             (buffer-string)))))
    (insert (format "Content-Type: multipart/encrypted; boundary=\"%s\";\n"
                    mml-boundary)
            "\tprotocol=\"application/pgp-encrypted\"\n"
            "\n"
            "\n--" mml-boundary "\n"
            "Content-Type: application/pgp-encrypted\n"
            "\n"
            "Version: 1\n")
    (insert "\n--" mml-boundary "\n"
            "Content-Type: application/octet-stream\n"
            "\n"
            encrypted-parts
            "\n--" mml-boundary "\n")))




       reply	other threads:[~2000-01-16  8:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <wtnpuv5wurx.fsf@licia.dtek.chalmers.se>
2000-01-16  8:14 ` Florian Weimer [this message]
     [not found]   ` <wtn3drwabws.fsf@licia.dtek.chalmers.se>
2000-01-17 21:42     ` Kai Großjohann
2000-01-18  5:26     ` Florian Weimer
     [not found]       ` <wtnr9ffbrbs.fsf@licia.dtek.chalmers.se>
2000-01-18 11:39         ` Florian Weimer
     [not found]           ` <wtn1z7f8rl8.fsf@licia.dtek.chalmers.se>
2000-01-18 13:50             ` Florian Weimer
     [not found]               ` <wtn7lh7id3y.fsf@licia.dtek.chalmers.se>
2000-01-18 19:12                 ` Florian Weimer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87d7r25t6t.fsf@deneb.cygnus.argh.org \
    --to=fw@s.netic.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).