Re: base64 message body decode when replying???

Alexander Zangerl <[email protected]>
Newsgroups gmane.mail.exmh.user
Message-ID <[email protected]>
On Mon, 22 Mar 2010 14:19:31 MST, Kevin Cosgrove writes:
>That makes sense.  Has anyone scripted a filter, maybe triggered
>via ~/.mh_profile, which pre-formats the message before handing
>off the content to the actual repl? 

not a standalone filter, but a hook for emacs - should 
that be your editor. if not, feel free to ignore me  :-)

in my replfilter i leave a marker (<--->) at the beginning of the body
and do NOT quote it, just insert it as it is. the marker is for distinguishing
normal drafts (=no hackery required) from replies.

emacs gets the draft, and via mh-letter-mode-hook the prep-reply
function is triggered. this gives the mail a once-over: if pgp encrypted
run it though mc-decrypt (from mailcrypt), then if base64- or qp-encoded 
undo that, and finally insert the quote char. 

the mime headers are completely ignored, so this is somewhat crude but workable.


regards
az

-- 
+ Alexander Zangerl + DSA 42BD645D + (RSA 5B586291)
"I wish there was a knob on the TV to turn up the intelligence.
There's a knob called `brightness', but it doesn't work." -- Gallagher

_______________________________________________
Exmh-users mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/exmh-users
replfilter (application/octet-stream, 180 B) - not displayed
mh-letter-hook (text/x-lisp, 2.4 KB)
(require 'qp)
(add-hook 'mh-letter-mode-hook 'prep-reply)

;; pgp: decrypt replies, per mailcrypt
(defvar pgp-header "-----BEGIN PGP MESSAGE-----" 
  "line which is checked for determining whether this is encrypted or not")

(defun prep-reply ()
  "prepare a reply buffer: decrypt, de-base64, de-quoted-print, insert cite chars.
if this is a blank buffer or not a reply buffer, nothing is done."
  (interactive)
  
  ;; figure out what is where:
  (let ((pos (analyzebody))
	(realbody nil))		;headerend bodybegin quotebegin
    ;; a reply? that hasn't been worked on (we leave a dummy marker via repl's filter)
    (setq realbody (caddr pos))
    (cond (realbody
	   (save-excursion
	     ;; remove the marker line
	     (goto-char realbody)
	     (delete-region realbody (+ 1 (line-end-position)))
	     ;; then check for pgp and attempt decryption. mc-decrypt doesn't throw exceptions.
	     (if (search-forward-regexp pgp-header (point-max) t)
		 (mc-decrypt))
	     ;; then attempt base64
	     (ignore-errors (base64-decode-region realbody (point-max)))
	     ;; and qp-decode
	     (ignore-errors (quoted-printable-decode-region 
			     realbody (point-max)))
	     ;; and finally insert quotes
	     (requote realbody (point-max))
	     )))
    )  
  )



(defun requote (beg end)
  "(re-)inserts '>' reply quotes on all lines between beg and end."
  (let ((m nil))
    (save-excursion
      (goto-char end)
      (setq m (point-marker))		; remember the intended end
      (goto-char beg)			; we assume beg is a line beginning
      (insert ">")
      (while (progn
	       (forward-line 1)
	       (not (>= (point) (marker-position m))))
	(insert ">"))
      )
    )
  )

(defun analyzebody ()
  "search for the start/end of a (reply) body, returns a list of the positions:
end of headers, start of body, start of reply body (if any exists). 
the reply body is indicated by pattern '<--->' on a line by itself.
nils are returned on failure."
  (let ((headerend nil)
	(bodybegin nil)
	(quotebegin nil))
    (save-excursion
      (beginning-of-buffer)
      ;; find the mh header delimiter
      (cond ((re-search-forward "^--------$" (point-max) t)
	     (setq headerend (- (match-beginning 0) 1))	;previous line please
	     (setq bodybegin (+ 1 (match-end 0))) ;next line please
	     (cond ((re-search-forward "^<--->$" (point-max) t)
		    (setq quotebegin (match-beginning 0))
		    ))
	     ))
      )
    (list headerend bodybegin quotebegin)
    )
  )
signature.asc (application/pgp-signature, 197 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkuok5UACgkQpy/2bEK9ZF1Z8gCeJLAkZ3jZM3cp4WEuNL3KFV5A
WGsAn1DYEtiAKPFeK7XBLBg4HIIkrqvR
=RVgh
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.