From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/82634 Path: news.gmane.org!not-for-mail From: Ivan Kanis Newsgroups: gmane.emacs.gnus.general Subject: Re: saving inline images Date: Fri, 21 Dec 2012 09:11:07 +0100 Message-ID: <87vcbvx1t0.fsf@googlemail.com> References: <87bodpkr39.fsf@kanis.fr> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1356077507 23995 80.91.229.3 (21 Dec 2012 08:11:47 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 21 Dec 2012 08:11:47 +0000 (UTC) Cc: ding@gnus.org To: Katsumi Yamaoka Original-X-From: ding-owner+M30900@lists.math.uh.edu Fri Dec 21 09:12:02 2012 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from util0.math.uh.edu ([129.7.128.18]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Tlxi4-0002Uv-EW for ding-account@gmane.org; Fri, 21 Dec 2012 09:12:00 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by util0.math.uh.edu with smtp (Exim 4.63) (envelope-from ) id 1TlxhU-0005ov-47; Fri, 21 Dec 2012 02:11:24 -0600 Original-Received: from mx1.math.uh.edu ([129.7.128.32]) by util0.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1TlxhS-0005of-Bn for ding@lists.math.uh.edu; Fri, 21 Dec 2012 02:11:22 -0600 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx1.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) (envelope-from ) id 1TlxhQ-0006Kh-AC for ding@lists.math.uh.edu; Fri, 21 Dec 2012 02:11:21 -0600 Original-Received: from mail-wi0-f172.google.com ([209.85.212.172]) by quimby.gnus.org with esmtp (Exim 4.72) (envelope-from ) id 1TlxhO-0006PE-Hm for ding@gnus.org; Fri, 21 Dec 2012 09:11:18 +0100 Original-Received: by mail-wi0-f172.google.com with SMTP id o1so4827446wic.5 for ; Fri, 21 Dec 2012 00:11:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:references:face:x-hashcash:x-hashcash :date:in-reply-to:message-id:user-agent:mime-version:content-type; bh=ode5pO0Ie+eUn8pt9IVVrZ7brru2HtqF0ycshWTJ7uE=; b=OKzDVPaOEufn5kENWCEyEclQyKKq+RzMtYKkp7F1EFoGWkjzUEUl+LVKvzIRitmFh2 O+tMXwELKhxtwazFm2q0M8/7Ed7TwTDixLZoCFqzfuVlyX+kpeVaX+awdUwUJh78UUsY Js9ArgBl3Ehk25EaFzGkrKvQLiofIwLYWCN4lNj2/9Ug8oJU4x9hwnUoebZGSQ5WT8Y3 Clm6tAxDSlbHl1Z/KAH9wHsN5grdm2RlteMZUBQyD527q6NMH3xQNGdAZKImtXAPqMRz ZXZzQPnLPRMsZ6wfmA9IjSvbzUDj9GXaagjffWycgZw1PIWjoxcAf9iiMUjc91m62IDg zGCQ== X-Received: by 10.194.82.168 with SMTP id j8mr21987391wjy.15.1356077473170; Fri, 21 Dec 2012 00:11:13 -0800 (PST) Original-Received: from tao (lns-c10k-ft-02-t2-89-83-137-164.dsl.sta.abo.bbox.fr. [89.83.137.164]) by mx.google.com with ESMTPS id h19sm28719179wiv.7.2012.12.21.00.11.09 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 21 Dec 2012 00:11:11 -0800 (PST) Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAAXNSR0IArs4c6QAAAB5QTFRF IBkXUxMTOCwoTC4qcUY8iFxQmmper31txpaJ/v/8aKZ1oAAAAcVJREFUOMt100tu2zAQAFDCXnUZ oAcIqG68LZULVLQBbwuSiffm6AIRRyeotAySJoVu2+FPpJWWC3/4NKOZocSW/yxWfnJ2+Bdwzhj7 8gleWVy7DXC2rkMNr2V/zRbghXIwthf3VbIA9Ffc71vZCSFyCEsBggtNS8ludwvfmhYA0Vn9o4DP zMWxR7+cPWzAYFzwM0ModtdmcDbDS6i/hT7L+RZof5yCXGrYe5jn2YO6BYMjgY+51tCIAqHgBLwR pwLnGuRjAKyBJkuN4yd4U92uCY1vUr2D/c5b8DuxyQwfOHUeaLqDJhnkkuGXbB56h2C1IVBdgncc bBi6feroa9B6jUDojnQPQKupbyXyeeCE1oT7Oqrt+SnfY3mkiyGA/3AmD3H5g32CcBx6hY8pRkwJ 9PpcjRGobUfprFnhAa1vepwcgMOhwG+pdSgKHFU9HAvoAH6XUl7lDUCCq5Qb6GMbVm3Aj++qDYCt wdBc/YHgOFCmS3mjDMRcSE2qY4E3Q3PVIQRQmeodNH4QEbRUFZzW+VotzwX4yTcRTySOML1qjcE5 hTirVqDHkMAP0PjAywp3d18JZtqzvr9zDYD+GaSKtE6Zlr/DLPNFmOcvBAAAAABJRU5ErkJggg== X-Hashcash: 1:20:121221:ding@gnus.org::rXQytW+smPbqrjPq:00000gPl X-Hashcash: 1:20:121221:yamaoka@jpl.org::z1ioZ4Bk1wXXbZhD:002sJA In-Reply-To: (Katsumi Yamaoka's message of "Fri, 21 Dec 2012 09:15:28 +0900") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-Spam-Score: -2.0 (--) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:82634 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello Katsumi=E3=81=95=E3=82=93=E3=80=81 Katsumi Yamaoka wrote: > However, if an image is attached to the mail (i.e., it is a MIME > part of the mail, that is called a cid image), the `i' command > (currently) doesn't support it. That's exactly what I am talking about. I came up with a solution to my need. I am posting here in case someone else needs it. I don't like it because it involves Python and the function is hard coded with the nnml backend. (defun ivan-gnus-save-attachment () "Save all atachments include cid inline attachments." (interactive) (let ((output-buffer (get-buffer-create "output")) (file-name (nnml-article-to-file (gnus-summary-article-number)))) (switch-to-buffer output-buffer) (erase-buffer) (insert "The following files were extracted:\n\n") (call-process "extract-inline-attachment.py" nil output-buffer t file-name))) I have attached the python script. I would rather do it all in elisp but whenever I look at gnus code my brain melts ;) > In that case, you can use the `C-d' command on a summary buffer to > dissect the mail into some parts. And you can easily find an image > among them and save it to a file in an ordinary way. I didn't know that command. Nice! However it gets too long with multiple images. C-d C-n C-n C-n C-n K b C-o C-n o ~/tmp/foo.png RET And I have to do the K b sequence for each image... > Maybe the `i' command (shr-browse-image) needs to be improved so > as to support cid images. Also the `o' command (shr-save-contents) > had better support saving both external and cid images as well. That would be nice. > My only worry is that it may require renaming shr.el to chr.el Why? > In natural Japanese, we'd say: =E3=80=8C...=E3=80=8D=E3=82=92=E8=81=B4=E3= =81=8D=E3=81=AA=E3=81=8C=E3=82=89=E2=80=A6 ;-) Thank you for correcting my Japanese! --=-=-= Content-Type: text/x-python Content-Disposition: attachment; filename=extract-inline-attachment.py #!/usr/bin/env python # -*- coding: utf-8 -*- import email import mimetypes import os import os.path import sys def usage (): print print "Usage:" print print sys.argv[0] + " file" print print "Extract inline attachment of mail and put them in ~/tmp" print print "Argument file is message to be parsed." sys.exit(1) if len(sys.argv) != 2: usage() fp = open (sys.argv[1]) msg = email.message_from_file(fp) fp.close() counter = 1 for part in msg.walk(): # multipart/* are just containers if part.get_content_maintype() == 'multipart': continue # Applications should really sanitize the given filename so that an # email message can't be used to overwrite important files filename = part.get_filename() if not filename: ext = mimetypes.guess_extension(part.get_content_type()) if not ext: # Use a generic bag-of-bits extension ext = '.bin' filename = 'part-%03d%s' % (counter, ext) counter += 1 filename = os.path.expanduser ("~/tmp/" + filename) print filename fp = open(filename, 'wb') fp.write(part.get_payload(decode=True)) fp.close() # Copyright (C) 2012 Ivan Kanis # Author: Ivan Kanis # # This program is free software ; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation ; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY ; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program ; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # vi:et:sw=4:ts=4: # Local Variables: # compile-command: "python foo.py" # End: # # vi:et:sw=4:ts=4: --=-=-=--