Subject: [sup-talk] [PATCH] Pipe message/attachement to shell command

From: [email-masked] (Marcus Williams)
Date: Fri, 09 Nov 2007 15:33:35 +0000

Hi -

On the back of Eyal's patch heres a patch to pipe a message or
attachment to a shell command via '|' in thread view mode.

William, in the code it says that message.raw_message is slow but
thats the only way I could do it without creating a string via
each_raw_message_line. Is there a better way than this?

Marcus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pipe-patch
Type: application/octet-stream
Size: 1467 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/sup-talk/attachments/20071109/4a0fc011/attachment.obj

---

From: [email-masked] (William Morgan)
Date: Mon, 12 Nov 2007 09:55:54 -0800

> each_raw_message_line. Is there a better way than this?

Hey, this is another reason to use open3 instead of Session. You need to
have access to use the stdin filehandle in order to use
#each_raw_message_line. (There's no speed difference for IMAP, but for
Maildir and mbox, it's quite large. Maildir could be sped up, but mbox
fundamentally not.)

BTW, that first argument to BufferManager#ask should ideally be a symbol
of some sort rather than nil. History is shared amongst all invocations
with the same symbol.

-- 
William <wmorgan-sup at masanjin.net>

---

From: [email-masked] (Marcus Williams)
Date: Mon, 12 Nov 2007 22:06:01 +0000

> Maildir and mbox, it's quite large. Maildir could be sped up, but mbox

Attached is a patch for the shell/pipe code so that it uses open3.
Just realised I've not moved shell method into sup in this patch, but
its a start!

Marcus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: open3-diffs
Type: application/octet-stream
Size: 3068 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/sup-talk/attachments/20071112/0add038a/attachment.obj

---

From: [email-masked] (Marcus Williams)
Date: Tue, 13 Nov 2007 11:58:27 +0000

> Just realised I've not moved shell method into sup in this patch, but

Mmmm. Seem to be having some buffering problems with open3 on slightly
longer messages. The pipe stuff blocks because of it.

Will have to resubmit when I figure it out.

Marcus

---

From: [email-masked] (Marcus Williams)
Date: Wed, 14 Nov 2007 09:40:23 +0000

> Will have to resubmit when I figure it out.

Ok, heres the new one. I think in the pipe to command case, the
session gem is probably the best way to go (although I've not use it
here) because it handles the blocking problems for you.

This patch will:

* return an error correctly if the command returns an error initially
(like a usage error, or missing file etc)
* pipes the mail/attachment to the command
* read either stdout OR stderr, whichever is ready first and display that.

The last step is where the problem lies. If a command produces both I
cant figure out what to do with it, should it display two separate
buffers, one with errors and one with output? What happens if the
context of the error is important (ie where it is in the output
stream)?

I'm pretty sure this is an edge case, as the majority of usages of
this would be to pipe through a spam filter, or a file viewer (like
textviewer.sh from claws mail or antiword) and this patch works fine
in those cases.

Anyone any comments?

Marcus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: open3-diffs
Type: application/octet-stream
Size: 3524 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/sup-talk/attachments/20071114/5d29ac10/attachment.obj

---

From: [email-masked] (Marcus Williams)
Date: Mon, 26 Nov 2007 20:57:05 +0000

> here) because it handles the blocking problems for you.

Here we go again. Attached is the shell patch (pipe to follow) as a
patch to bin/sup instead of in the scroll mode.

Marcus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: shell-patch
Type: application/octet-stream
Size: 1221 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/sup-talk/attachments/20071126/bd47d15c/attachment-0001.obj

---

From: [email-masked] (Marcus Williams)
Date: Mon, 26 Nov 2007 21:01:22 +0000

> patch to bin/sup instead of in the scroll mode.

... and here is the pipe patch.

Marcus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pipe-patch
Type: application/octet-stream
Size: 1926 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/sup-talk/attachments/20071126/4a9e950a/attachment.obj

---

From: [email-masked] (William Morgan)
Date: Sun, 09 Dec 2007 22:24:21 -0800

> ... and here is the pipe patch.

Committed! Thanks!