all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Kaloian Doganov <kaloian@doganov.org>
Cc: help-gnu-emacs@gnu.org
Subject: Re: rmail and quoted-printable
Date: Tue, 05 Sep 2006 19:32:45 +0300	[thread overview]
Message-ID: <87u03mtgsy.fsf@doganov.org> (raw)
In-Reply-To: <87odu0cz0k.fsf@zogzog.gnu-rox.org> (Xavier Maillard's message of "Fri, 01 Sep 2006 00:37:47 +0200")

Xavier Maillard <zedek@gnu.org> writes:

    I can't find an elegant solution to deal with all these mails sent
    with QP encoded body.

This doesn't qualify as 'elegant', but I've used this function, which
detects and handles both base64 and quoted-printable:

(defun mime-decode ()
  (interactive)
  (save-excursion
	(re-search-forward "^--[^\n]+")
	(beginning-of-line)
	(let ((string (buffer-substring-no-properties
				   (point) (save-excursion (end-of-line) (point))))
		  (buf (current-buffer))
		  start end meta-start)
	  (setq meta-start (point))
	  (search-forward "\n\n")
	  (setq start (point))
	  (search-forward string)
	  (beginning-of-line)
	  (setq end (point))
	  (let ((source-buffer (current-buffer))
			(target-buffer (get-buffer-create "*foo*")))
		(save-excursion
		  (set-buffer target-buffer)
		  (erase-buffer))
		(append-to-buffer target-buffer start end)
		(save-excursion
		  (goto-char meta-start)
		  (search-forward "\n\n" nil t)
		  (let ((mime-charset
				 (if (and rmail-decode-mime-charset
						  (save-excursion
							(let ((case-fold-search t))
							  (re-search-backward
							   rmail-mime-charset-pattern
							   meta-start t))))
					 (intern (downcase (match-string 1)))))
				(mime-encoding
				 (save-excursion
				   (if (let ((case-fold-search t))
						 (re-search-backward
						  "^content-transfer-encoding:\\(\n?[\t ]\\)*\\([-a-z0-9]+\\)\\(\n?[\t ]\\)*"
						  meta-start t))
					   (intern (downcase (match-string 2)))
					 nil))))					 
			(message "Detected charset: %s, encoding: %s" mime-charset mime-encoding)
			(save-excursion
			  (set-buffer target-buffer)
			  (cond ((string= mime-encoding "base64")
					 (base64-decode-region (point-min) (point-max)))
					((string= mime-encoding "quoted-printable")
					 (quoted-printable-decode-region (point-min) (point-max))))
			  (rmail-decode-region (point-min) (point-max) mime-charset)
			  (goto-char (point-min))))
		  (switch-to-buffer target-buffer))))))

      parent reply	other threads:[~2006-09-05 16:32 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-31 22:37 rmail and quoted-printable Xavier Maillard
2006-09-01 14:40 ` Kevin Rodgers
     [not found] ` <mailman.6139.1157121909.9609.help-gnu-emacs@gnu.org>
2006-09-01 22:05   ` maillaxa
2006-09-02  1:57     ` Barry Margolin
2006-09-02  9:48     ` Eli Zaretskii
2006-09-02 15:58       ` Xavier Maillard
2006-09-02 16:48         ` Eli Zaretskii
2006-09-02 17:36           ` Xavier Maillard
2006-09-02 21:08             ` Eli Zaretskii
2006-09-02 21:50               ` Xavier Maillard
     [not found]             ` <mailman.6172.1157231314.9609.help-gnu-emacs@gnu.org>
2006-09-03  1:41               ` Barry Margolin
2006-09-03 21:39                 ` Xavier Maillard
2006-09-03 22:37                 ` Jesper Harder
     [not found]                 ` <mailman.6223.1157323058.9609.help-gnu-emacs@gnu.org>
2006-09-07 16:04                   ` Miles Bader
2006-09-07 20:23                     ` Eli Zaretskii
2006-09-05 16:32 ` Kaloian Doganov [this message]

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=87u03mtgsy.fsf@doganov.org \
    --to=kaloian@doganov.org \
    --cc=help-gnu-emacs@gnu.org \
    /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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.