Gnus development mailing list
 help / color / mirror / Atom feed
* saving inline images
@ 2012-12-20  9:31 Ivan Kanis
  2012-12-21  0:15 ` Katsumi Yamaoka
  0 siblings, 1 reply; 4+ messages in thread
From: Ivan Kanis @ 2012-12-20  9:31 UTC (permalink / raw)
  To: ding

Hi,

I am trying to save inline html images. Can't find out how to do it. I
tried all the K keys. Has anyone managed to do that? I can find a sample
mail if you need an example.

Take care,
-- 
Ivan Kanis
http://ivan.kanis.fr

かっこ悪くたっていいのだ、かっこ悪さを恐れてはいけない、恥ずかしがって
はいけない、どんなかっこうでも真剣に生きる姿は美しいのだ。
 【千秋 実】

「James Brown - Get Up, Get Into It And Get Involved (Mono)」を聞いている。

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: saving inline images
  2012-12-20  9:31 saving inline images Ivan Kanis
@ 2012-12-21  0:15 ` Katsumi Yamaoka
  2012-12-21  8:11   ` Ivan Kanis
  0 siblings, 1 reply; 4+ messages in thread
From: Katsumi Yamaoka @ 2012-12-21  0:15 UTC (permalink / raw)
  To: ding

ivan.kanis@googlemail.com wrote:
> I am trying to save inline html images. Can't find out how to do it. I
> tried all the K keys. Has anyone managed to do that? I can find a sample
> mail if you need an example.

If you're talking about an html article that shr.el renders, you
can use the `i' command on an image.  It launches an external
browser and displays an image in it, so you'll be able to save
it by using browser's command.

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.  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.

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.
My only worry is that it may require renaming shr.el to chr.el
(S-a simple, C-a ...).

> かっこ悪くたっていいのだ、かっこ悪さを恐れてはいけない、恥ずかしがって
> はいけない、どんなかっこうでも真剣に生きる姿は美しいのだ。
>  【千秋 実】

Yes, that's right!

> 「James Brown - Get Up, Get Into It And Get Involved (Mono)」を聞いている。

In natural Japanese, we'd say: 「...」を聴きながら…  ;-)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: saving inline images
  2012-12-21  0:15 ` Katsumi Yamaoka
@ 2012-12-21  8:11   ` Ivan Kanis
  2012-12-21 14:33     ` Andreas Schwab
  0 siblings, 1 reply; 4+ messages in thread
From: Ivan Kanis @ 2012-12-21  8:11 UTC (permalink / raw)
  To: Katsumi Yamaoka; +Cc: ding

[-- Attachment #1: Type: text/plain, Size: 1866 bytes --]

Hello Katsumiさん、

Katsumi Yamaoka <yamaoka@jpl.org> 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 <return> 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: 「...」を聴きながら…  ;-)

Thank you for correcting my Japanese!


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: extract-inline-attachment.py --]
[-- Type: text/x-python, Size: 2047 bytes --]

#!/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:

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: saving inline images
  2012-12-21  8:11   ` Ivan Kanis
@ 2012-12-21 14:33     ` Andreas Schwab
  0 siblings, 0 replies; 4+ messages in thread
From: Andreas Schwab @ 2012-12-21 14:33 UTC (permalink / raw)
  To: Ivan Kanis; +Cc: Katsumi Yamaoka, ding

Ivan Kanis <ivan.kanis@googlemail.com> writes:

> And I have to do the K b sequence for each image...

Typing just b should work as well.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-12-21 14:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-20  9:31 saving inline images Ivan Kanis
2012-12-21  0:15 ` Katsumi Yamaoka
2012-12-21  8:11   ` Ivan Kanis
2012-12-21 14:33     ` Andreas Schwab

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).