From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kaloian Doganov Newsgroups: gmane.emacs.help Subject: Re: rmail and quoted-printable Date: Tue, 05 Sep 2006 19:32:45 +0300 Message-ID: <87u03mtgsy.fsf@doganov.org> References: <87odu0cz0k.fsf@zogzog.gnu-rox.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1157474007 1264 80.91.229.2 (5 Sep 2006 16:33:27 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 5 Sep 2006 16:33:27 +0000 (UTC) Cc: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Sep 05 18:33:24 2006 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1GKdrR-0004sL-C5 for geh-help-gnu-emacs@m.gmane.org; Tue, 05 Sep 2006 18:33:17 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GKdrQ-0002gq-P8 for geh-help-gnu-emacs@m.gmane.org; Tue, 05 Sep 2006 12:33:16 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GKdrA-0002cP-3x for help-gnu-emacs@gnu.org; Tue, 05 Sep 2006 12:33:00 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GKdr6-0002XM-FH for help-gnu-emacs@gnu.org; Tue, 05 Sep 2006 12:32:59 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GKdr5-0002Wg-Vl for help-gnu-emacs@gnu.org; Tue, 05 Sep 2006 12:32:56 -0400 Original-Received: from [193.68.3.118] (helo=eos.openintegra.com) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1GKe1r-0006tc-35; Tue, 05 Sep 2006 12:44:03 -0400 Original-Received: from localhost.localdomain ([127.0.0.127]) by eos.openintegra.com (8.13.1/8.13.6) with ESMTP id k85GWnDR030413 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO); Tue, 5 Sep 2006 19:32:51 +0300 Original-Received: from kaloian by localhost.localdomain with local (Exim 4.63) (envelope-from ) id 1GKdqv-0004lP-6P; Tue, 05 Sep 2006 19:32:45 +0300 Original-To: Xavier Maillard In-Reply-To: <87odu0cz0k.fsf@zogzog.gnu-rox.org> (Xavier Maillard's message of "Fri, 01 Sep 2006 00:37:47 +0200") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:37165 Archived-At: Xavier Maillard 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))))))