通过 SSH 使用 Mutt,但附件怎么办?
如果您向Linux Journal投稿了一篇文章,但尚未收到回复,其中一个原因是我们的拒稿信有时会有点长。 这是一个例子。
尊敬的(投稿人):
我不得不拒绝您的 Mutt 文章。
是的,能够通过 ssh 轻松地在任何服务器上获取您的邮件很酷,并且能够指定您选择的应用程序来查看 MIME 附件也很酷。
但是,将两者结合起来怎么样? 您不能指望人们仅仅因为您出差就停止向您发送附件。
当您在远程服务器上的帐户中阅读邮件时(也许是一个非常远程的服务器,通过慢速线路与您分离),并且您收到附件时,整个“Mutt 加上查看器”的概念就崩溃了。 我经常遇到这种情况,尤其是文章的图片。
您的选择基本上是保存图像并将其 scp 回到您的桌面机器,将其反弹到设置为在 localhost 上使用 GUI 邮件客户端的备用帐户,或者通过 ssh 连接运行基于 X 的图像查看器。 这三种方法都很笨。 如果您的连接速度很快,最后一种方法最容易,但您必须发送整个 X 协议,而不是仅发送压缩图像,而且它可能很慢,特别是对于 PDF。
那么,如何在远程 Mutt 中有效地处理附件? 我真的很想知道,因为我收到的照片越多,我就越考虑这个问题。
我喜欢“只将您的电子邮件地址提供给喜欢文本甚至 ASCII 艺术的文学 UNIX 老手”的方法,但这是第二好的选择。
重要提示:除非您控制并信任运行 Mutt 的系统和您的本地系统,否则您不应尝试这样做。 这样做,运行 Mutt 的系统上的坏人可能会看到您的附件。 更好的版本可以保护您的附件免受两端恶意用户的侵害。
首先,设置一个 ssh 隧道。 我把它放在我的 .ssh/config 中
ProtocolKeepAlives 30 Host mail Protocol 2 EscapeChar none ForwardX11 yes PasswordAuthentication no LocalForward 8088 localhost:8088
重要部分是 LocalForward 行; 当我建立与主机“mail”的 ssh 连接时,我会获得一个从 localhost 的 8088 端口到 mail 上的 8088 端口的 ssh 隧道。 您还需要启用 ForwardX11,因为此方法确实对一件小事使用了 X。
其次,我们知道哪个程序可以处理我们感兴趣的任何 MIME 类型? 我们的 Mozilla 网络浏览器。 但它就在我们的膝盖上,在客户端。 没关系; 我们将它指向 http://localhost:8088/,它被隧道传输到附件所在的“mail”。
因此,我们让 Mozilla 与附件所在的主机建立安全连接,但我们是否需要编写一个 Web 服务器来提供附件? 当然。 这是一个适合演示该想法的脚本,但要使其在多用户系统上有用,还需要做一些工作。
#!/bin/sh # spewtomoz.sh # You shouldn't install this dumb script for all users because it only # uses one pipe and one port. Have it pick a better name for the pipe, # and set the port from an environment variable. TEMP="/tmp/spewtomoz" PORT=8088 rm -f $TEMP mkfifo --mode=600 $TEMP # netcat is the fun part of this script. # -l: listen for an incoming connection # -q 1: wait 1s after EOF and quit # -s 127.0.0.1 only use the lo interface # -p $PORT use $PORT netcat -l -q 1 -s 127.0.0.1 -p $PORT < $TEMP &> /dev/null & # send the HTTP headers, followed by a blank line. echo "HTTP/1.1 200 OK" >> $TEMP echo -n "Content-type: " >> $TEMP file -bni $1 2> /dev/null >> $TEMP echo >> $TEMP # Get started sending the file... cat $1 >> $TEMP & # Wait a second and tell the user's Mozilla, wherever it is, to start # viewing the file. This works over the X protocol. # (the date is to blow the cache and may not be necessary) sleep 1 && gnome-moz-remote http://localhost:$PORT/`date +%s` # end spewtomoz.sh
剩下的就是让 Mutt 使用此脚本作为 MIME 附件的处理程序。 这意味着我们将不得不给 Mutt 一个备用的 mailcap 文件。 将此放入您的 .muttrc 文件中
set mailcap_path="~/.mutt-mailcap"
并将此放入 ~/.mutt-mailcap 中
text/*; spewtomoz.sh %s application/*; spewtomoz.sh %s image/*; spewtomoz.sh %s audio/*; spewtomoz.sh %s
现在,当您重新启动 Mutt 并选择附件时,它将在您的 Mozilla 浏览器中打开,如果 Mozilla 了解附件的 MIME 类型; 如果没有,Mozilla 将启动一个辅助应用程序,例如 Abiword 或 xpdf。
我对这种处理附件的方法并不完全满意,而且我还没有在非常慢的连接上尝试过它,但它比我见过的其他替代方案要好。 例如,如果您收到隔行扫描图像,它应该在加载时显示,从而节省您一些时间。
一篇好的 Mutt 文章必须处理这个问题。 我欢迎任何更好的方法建议。
Don Marti 是Linux Journal的主编。
电子邮件: dmarti@ssc.com