Asciinema演示: 1 | 2 | 3 | 4
alpine-screenshot
alpine-iphone

另, 文末有我的Example, 可直接拿来快速上手.

我在2019年3月28日于Black Hat Asia上做的相关演讲

谁在用

Linus Torvalds:
From: Linus Torvalds <torvalds@linux-foundation.org>
Newsgroups: fa.linux.kernel
Subject: Re: [git pull][resend] Input updates for 2.6.22-rc7
Date: Fri, 06 Jul 2007 01:11:27 UTC
Message-ID: <fa.IgmANxZoEvqGUWkoZEe414vIYlQ@ifi.uio.no>

On Fri, 6 Jul 2007, Jesper Juhl wrote:
>
> > I'm constantly surprised by just how _many_ ways MUA's find to screw up.
>
> 'pine' actually seems to work pretty damn well once you disable the
> flowed-text "feature".

Yes. And 'alpine', it's modern version, does even better, but you also
need to make sure to disable "downgrade-multipart-to-text".

I've been using alpine for a while now, and it's nice to see it be utf-8
capable and able to handle other charsets well.

So as a former pine user, I can recommend upgrading.

		Linus
Marissa Mayer是这样用的:

March 8, 2006

Marissa Mayer prefers Pine to Gmail

[mayer]Marissa Mayer, VP, Search Products and User Experience at Google confesses to CNN Money that she doesn’t use Gmail for her business mail.

“I don’t feel overwhelmed with information. I really like it. I use Gmail for my personal e-mail – 15 to 20 e-mails a day – but on my work e-mail I get as many as 700 to 800 a day, so I need something really fast. I use an e-mail application called Pine, a Linux-based utility I started using in college. It’s a very simple text-based mailer in a crunchy little terminal window with Courier fonts. I do marathon e-mail catch-up sessions, sometimes on a Saturday or Sunday. I’ll just sit down and do e-mail for ten to 14 hours straight.”

Pine is a mail program developed at the University of Washington. It has a lot of keyboard shortcuts and countless ways to sort, shuffle, and sift through your email.

Hacker News 上有人这样评论:

Pine was the defacto email client for so many universities (including mine);

these kids today don’t know what they were missing!

It was a rare window of human Time On Earth where every single person at my massive nearly 100K-size college used Control-X to send every email.

优点

  • 历史悠久, 从Unix时代就一直在广泛使用, GNU/Nano 即是从 alpine 的前身 pine 中的默认编辑器 pico 派生的
  • 不折腾, 开箱即用, 调一下喜欢的配色即可
  • 所有配置都在一个 TUI 界面里集中配置
  • 不可定制快捷键, 但快捷键久经考验, 越用感觉越科学, 适合快捷键选择恐惧症的人使用
  • 对 IMAP 的支持比较科学
  • 与 BBS 的操作非常相似
  • 原生支持 S/MIME
  • 原生支持 LDAP 通讯录, 并支持 .addressbook 形式的本地通讯录, 且可以将其存储于远程 IMAP 目录内
  • 配置文件可以写入远程 IMAP 文件夹, 从而实现配置漫游
  • alpine 内部可以改 /etc/passwd 里的密码. 可以在 Server 上开设默认 Shell 为 alpine 的账户, 专门用于查收邮件
  • 支持锁屏, 特别适合开在 VPS 的 Tmux/Screen 上

不足

  • 不可定制快捷键, 例如不支持j,k上下 ( 但是体验一下互联网远古时代的习惯也挺好 ._. )
  • 原生不支持 GPG/OpenPGP, 但是可以通过 topal 软件支持
  • 默认不识别 GB18030 编码(但默认支持GBK和GB2312), 接收来自 QQ 邮箱的邮件可能会不识别. 但是我已经向上游提交了一个比较省事偷懒的Patch, 维护者正在进行修复
  • 不支持 LDAPs (636端口, SSL) 已经被我修好了, 见Patch
  • 不支持通过外部 IMAP 同步工具如 offlineimap 或 mbsync , 但貌似有人可以实现, 目前我没有跟进此事 已经支持Maildir, 见Maildir PatchExample
  • 部分由 Outlook 网页版邮箱发出的邮件以QP编码(一堆等号的那种), 中文识别起来貌似有问题

上手

由于其它的教程都已经年久失修, 而且University of Washington已经不维护alpine了.
目前项目是由 Eduardo Chappa chappa@gmx.com 个人在维护.
网址是https://alpineapp.email/alpine/release/, 而且上面有不少教程.

在主界面依次按下 M S C 进入配置界面,

 imap.gmail.com:993/ssl/user=example@gmail.com

 smtp.gmail.com:587/tls/user=example@gmail.com

设置默认发送者: (否则它可能会尝试以你的 Linux 用户名@邮箱域名来尝试发送)

 Customized Headers = From: 那谁 <example@gmail.com>

完!

仍然不开心的话, 可以调整一下配色: 依次按下 M S K.

新闻组

参考 http://www.washington.edu/pine/faq/news.html

M S C 添加 NNTP 服务器为: news.gmane.io

然后到 L 里, 在 News Collection 里按 A, 添加订阅

如:

  • gmane.announce
  • gmane.linux

可以在配置里, 指定一下最大拉取的新闻数量, 免得过多崩掉

NNTP Range                        = 2000

Tips

  • 在任意输入框内按下 Ctrl + G 可以查看帮助, 帮助在手, 天下我有.
  • S 键: 存储并从原邮箱删除邮件
  • 搜索: W
  • Ctrl + L 刷新屏幕, 同时会检查收件箱
  • A 键: 切换 HTML/PlainText 显示
  • 多选: 按冒号 : 键, 然后按 A (Apply) 键应用
  • ; 键可以按条件选择, 然后再按 A 来做操作
  • 颜色配置中HEADER COLORS里按 A 键, 可以加入如From Cc等字段进行颜色配置
  • 空格键下翻, 减号 - 上翻
  • < 键退回到上一级, 但发现不按 Shift 键效果一样
  • 显示新邮件数量: 把以下三个都勾上 Enable Incoming Folders Collection Enable Incoming Folders Checking Incoming Checking Includes Total, 然后在 List 中把想要看的目录按 A 键加进来.
  • 用搜索引擎搜索问题的时候, alpine的结果可能会比较少, 可以用pine做为关键词
  • 可以使用外部的编辑器如 vim, 按 Ctrl + _ 来切换成外部编辑器. ( 不按 Shift 键也可以)
  • | 键可以把邮件的内容 pipe 到另一个程序
  • 可以结合终端 ASCII 看图软件 cacaview (位于 caca-utils 包里), 来预览邮件附件的照片. 可以把你的终端字符使劲缩小, 从而达到提高分辨率的效果
  • Inbox Zero 原则: 养成定时清空 Inbox 的好习惯
  • 觉得提示声音吵, 可以[X] Suppress Status Message Beeping
  • 要设置一下alternate address, 在里面添加自己的邮箱地址(如scateu@example.com), 这样一方面会使+标记生效, 另一方面, Reply to all的时候就不会在Cc里面有自己了.
  • 转发HTML格式的邮件时, 如果想保留格式, 可以先按V, 显示附件, 在HTML的附件上按F来进行转发.

更多的 Tips , 可以参考 https://alpineapp.email/alpine/alpine-info/tips/index.html

我当前的一些小调整

default-fcc={imap.gmail.com:993/ssl/user=example@gmail.com}Sent
feature-list=enable-background-sending,
       enable-delivery-status-notification,
       convert-dates-to-localtime,
       compose-cancel-confirm-uses-yes,
       no-enable-alternate-editor-implicitly,
       enable-8bit-esmtp-negotiation,
       combined-folder-display,
       expanded-view-of-folders,
       vertical-folder-list,
       prefer-plain-text,
       combined-subdirectory-display,
       no-try-alternative-authentication-driver-first,
       enable-lame-list-mode,
       no-quell-imap-envelope-update,
       no-expose-hidden-config,
       no-enable-verbose-smtp-posting,
       quell-user-lookup-in-passwd-file,
       allow-changing-from,
       single-column-folder-list,
       quell-empty-directories,
       incoming-checking-includes-total,
       enable-incoming-folders-checking,
       enable-incoming-folders,
       no-incoming-checking-uses-recent

customized-hdrs=From: Your Name <example@gmail.com>

editor=vim

disable-these-authenticators=EXTERNAL #阿里云邮专用
color-style=force-xterm-256color

小Bug们

阿里云邮的 IMAP 认证问题

已知阿里云邮的 IMAP 服务器的CAPABILITY输出有问题, 导致 alpine 去尝试使用 AUTHENTICATE EXTERNAL 认证方式, 从而失败.

对策

调出 alpine 的隐藏配置[X] Expose Hidden Config, 把EXTERNAL加到禁用列表里.

 # List of SASL authenticators to disable.
 disable-these-authenticators=EXTERNAL

我当时用于调试的主要命令有:

 $ openssl s_client -connect imap.gmail.com:993 -crlf
  0 CAPABILITY
  1 LOGIN

 $ alpine -d4
 $ less ~/.pine-debug
阿里云邮的 SMTP 问题

发送时出现:

 >Mail not sent. Sending error: 440 mail from account doesn't conform with authentication (Auth Account:<

调试过程:

 $ alpine -d4
 $ cat .pine-debug1

发现MAIL FROM字段有问题:

 IMAP DEBUG 03:14:17 8/22: MAIL FROM:<scateu@alibaba-inc.com> BODY=8BITMIME
 IMAP DEBUG 03:14:17 8/22: 440 mail from account doesn't conform with authentication (Auth Account:wangkang.wk@alibaba-inc.com|M

对策

于是手动加上

Customized Headers                = From: 王康(五达) <wangkang.wk@alibaba-inc.com>
阿里云邮 Save 邮件的时候会把下一封删除掉

Save 的时候经常会出现一个D, 然后很可怕的把下一封邮件也删除了. 疑似是Bug

对策

[X]  Save Will Not Delete                                                  
Gmail 无法 Undelete

https://productforums.google.com/forum/#!topic/gmail/EX3FKvJFu1w

Deleting from IMAP for Gmail is like archiving. Email disappear from Inbox and goes to All Mail folder. Mail is not really deleted.  So Alphine will not find email in Trash folder to undelete.


If you want deleted mail to go to IMAP Trash folder, Go to Gmail webmail Settings.
In Labs tab, turn on Advanced IMAP controls.
In IMAP settings for Auto-Expunge, set to "Do not automatically expunge messages"
In Labels tab, hide the All Mail folder in IMAP).

Then you can do a delete and mail will go to Trash folder.
QQ邮箱

1. QQ邮箱不支持RLIST指令

参考这篇讨论

IMAP DEBUG 23:46:01 4/5: 00000007 RLIST "" %
IMAP DEBUG 23:46:03 4/5: 00000007 BAD ÃüÁîÎÞЧ»òÕß²»Ö§³Ö

于是, 要在Disable These Authenticators里面, 加上对LOGIN的禁用 这样才能在LIST里面看到所有目录

但是! 这样SMTP的时候, 会提示无法进行Authentication…. shit

2. QQ需要装手机安全中心

需要新建一个应用程序密码登录

打印

Mac OS X: M S Plpr, 然后按%打印即可.

可以把配置改为以下这样, 加上边距:

printer=lpr-a4 [] lpr -o media=A4 -o page-left=36 -o page-right=36 -o page-top=36 -o page-bottom=36
personal-print-command=lpr-a4 [] lpr -o media=A4 -o page-left=36 -o page-right=36 -o page-top=36 -o page-bottom=36

iOS 上使用

文章开头的照片, 是在iPhone上ssh到自己的服务器使用alpine.

键盘的搜索关键字”iPhone 侧滑 蓝牙 键盘”, 大约90块钱.

Terminal我对比了一下: (iOS)

  • Prompt 收费, 漂亮, 开发活跃度高, 但中文支持有点问题
  • vssh 收费, 中文支持没问题, 基于Putty的代码, 开发活跃度低
  • serverauditor 免费, 中文支持貌似有问题

所以我现在iPhone上买了Prompt和vssh

另外, 以上均不支持mosh.mit.edu提供的mosh.

据说Prompt正在支持mosh, 但是由于mosh是GPL的, 而Prompt不想开源

而安卓上有客户端支持, 这对于在地铁上信号经常断很有用

不过服务器上的alpine是跑在tmux里的, 断了再连一下也还能忍

在地铁上试了一下, 一个大妹子见状对她男朋友大喊一声:”快看啊有码农在地铁上写代码啊! “

还是挺不错的.

Android上使用: Termux

Termux是一个在Android上无需Root环境提供Linux环境的项目。

2017年10月之后,已经提供了Alpine包

直接

pkg install alpine

即可。

Patch及示例

我的一些Patch以及Example见: https://github.com/scateu/alpine-patches

另外, 为Mac OS X提供了集成上述3个Patch的Homebrew文件. 暂时先这样用好了, 等上游版本稳定了, 争取把上游的brew formula改掉.

或者直接这样子: (2017-03-20 更新: 换行和LDAPS两个Patch已经集成到上游的2.21里)

$ brew install https://github.com/scateu/alpine-patches/raw/master/brew/alpine.rb  --with-maildir-patch --with-gb18030-patch

示例配置: (自行把里面的TODO字样改掉)

Debian中导入Patch的方法

$ sudo apt-get build-dep alpine
$ apt-get source alpine
$ cd alpine-2.10+dfsg
$ patch -p1 < 0001-Add-a-require-ldapssl-on-connection-switch-to
-suppor.patch

同理把其它两个导入,待Patch成功之后:

$ dpkg-buildpackage -us -uc

会生成对应的.deb包
最后

$ cd ..
$ sudo dpkg -i alpine_2.10+dfsg-1_amd64.deb

Windows 版本

https://github.com/scateu/alpine-patches/releases

在Windows上的编译指南可以参考我的另一篇指南.

附: Pine发布时的邮件

PINE ELECTRONIC MAIL
It's somewhat out of the bag, but just to make it official...

Cheers!

Michael Seibel
Networks and Distributed Computing              mi...@cac.washington.edu
University of Washington, Seattle               (206) 543 - 0359

-------------------------


                         PINE ELECTRONIC MAIL

BACKGROUND

Pine is a mailer developed by the University of Washington Office of
Computing and Communications. It has been designed for ease-of-use and
with the novice computer user in mind. It is based on Internet mail
protocols (e.g. RFC-822, SMTP, IMAP, and MIME) and currently runs on a
variety of UNIX platforms.

The guiding principles for achieving ease-of-use in Pine were: careful
limitation of features, one-character mnemonic commands, always-present
command menus, immediate user feedback, and high tolerance for user
mistakes. It is intended that Pine can be learned by exploration rather
than reading manuals.  Feedback from the University of Washington
community and a growing number of Internet sites has been encouraging.

A stand-alone version of Pico, Pine's message composition editor, is also
available. It is a very simple and easy to use text editor with text
justification and a spelling checker.


FEATURES

   - Mail index showing a message summary which includes the status,
     sender, size, date and subject of messages.

   - View and process mail with the following commands:  forward, reply,
     save, export, print, delete, capture address and search.

   - Address book for saving long complex addresses and personal
     distribution lists under a nickname.

   - Multiple folders and folder management screen for filing messages.

   - Message composer with easy-to-use editor and spelling checker.
     The message composer also assists entering and formatting
     addresses and provides direct access to the address book.

   - Online help specific to each screen and context.

   - Supports access to remote mail repositories via the IMAP2 protocol
     defined in RFC-1176.

NEAR-TERM PLANS

   - Integral SMTP support for easy installation on Unix workstations.
     (This is desirable when Pine is used as an IMAP client of a shared
     mail server, since it obviates the need for installing and configuring
     sendmail on each workstation.)

   - Support for multi-part mail conforming to proposed MIME Internet
     standard, allowing sending of sounds, graphics such as GIF and
     TIFF files, and binary files such as spreadsheets.

   - Permit a user-specified editor for message composition.

   - Port Pine to MS-DOS  (Stanford's Mailstrom is recommended for Macs.)

AVAILABILITY

Pine and Pico, including source code, are freely available via anonymous
FTP from ftp.cac.washington.edu on the Internet. Other provisions for
distribution have not been made. From the Internet, you may try out Pine
and leave comments by telneting to "demo.cac.washington.edu" and logging
in as "pinedemo". To join the Pine mailing list for announcements send a
request to "pine-inf...@cac.washington.edu".

Pine is very portable and runs on a variety of UNIX machines including
DECstations, NeXTs, VAX's and Suns. Pine was originally based on Elm,
but it has evolved much since, ("Pine Is No-longer Elm").

For further information send e-mail to pi...@cac.washington.edu. Pine is
the work of Mike Seibel, Mark Crispin, and Laurence Lundblade at the
University of Washington.

92.3.24

参考链接

HTML渲染

使用w3m来阅读带有表格的HTML内容: 见邮件列表
- |先pipe到w3m -T text/html , 再加上Ctrl-Y的Free Output模式

或者在.mailcap里写上:

text/html; w3m -T text/html '%s'; needsterminal

然后遇到HTML渲染问题, 就按V显示附件, 在HTML的附件上回车, 这样比较直接.

缺点

  • 这样会导致邮件里面自己的URL, 也会被强制用w3m来打开, 原来是可以用firefox打开的. 即使设置了URL-viewers也不行.
    • 其实你本来不写这个mailcap, HTML附件用Firefox打开也行, 只不过中文有问题. 而且你也没机会改编码, 因为邮件的HTML文件是被临时放到了/tmp/里面, 打开Firefox的瞬间就被删除了. 只能先export
      • 貌似在Firefox里, 把Text-encoding Auto-detect设置成Japanese就好了
  • 按q退出w3m之后, 还需要按回车(再等一小会)或Ctrl-C快速退回来

好处

  • w3m是可以显示图片哒!

Contribution

Version 2.21 includes several new features and bug fixes.

  • Unix-Alpine: Connect securely to a LDAP server on a secure port. Based on a contribution by Wang Kang.
  • HTML messages that contain UTF-8 may wrap at the wrong position, making Alpine not display the correct character at the position that wrapping is done. Reported by Wang Kang.

Android

经过努力和一些PatchTermux上已经收录了了Alpine。

补充优化

2018-01-05

防止对端结束连接:

Incoming Check Interval             = 30   

用熟了之后可以把最下面的两栏关掉: (需要的时候按Ctrl-G仍然有帮助)

disable-keymenu

按Thread排序效果最好,如果服务器那边刚好支持相应的IMAP操作时,效率比较高。
否则是要把邮件头一个一个拉回来再按Thread排序的,很费时间。

OrderedSubj方式排序比较折中,可堪一用。只按标题作个’伪’Thread,通常来说够用了。特别在是NNTP看新闻组的时候。

NNTP 使用

写了一篇单独的文章

在电子墨水屏上使用

我的设备有两台:

  • Boox Max 1代 (Android 4.4 有蓝牙,但不支持OTG)
  • Boox C67ML Carta 2+ (无蓝牙… 但支持OTG,需要用带充电的OTG线)
    • 开启A2模式,可以牺牲一半的分辨率,提高一倍的刷新率,效果很不错。

App:

  • JuiceSSH: 选VT100终端(黑白), 浅色配色,禁用弹出键盘,字号20左右
  • 横屏问题:
    • 装一个Rotation Control,点一下系统屏幕正上方的时间,会出来个菜单,手动调屏幕方向即可。
      • 可以设置开机自启动
    • Boox电子书里面的PDF阅读器不受影响。
  • 需要关掉WiFi 15分钟后关闭

有啥要看的,在电脑上tmux att然后w3m blahblah.com,电子墨水屏上就可以用了,很方便。

让Status消息快点消失

心快如我,status栏里的消息要等那么久才能消失,经常会block住我的思路。

Status Message Delay                = -1

即可。

为什么设置为-1?

可能看代码更方便一些,帮助写的好乱哇...
alpine/status.c

void
q_status_message(int flags, int min_time, int max_time, char *message)
{
    SMQ_T *new, *q;
    char  *clean_msg;
    size_t mlen;

    status_message_lock();

    /*
     * If there is already a message queued and
     * new message is just informational, discard it.
     */
    if(flags & SM_INFO && new_info_msg_need_not_be_queued()){
        status_message_unlock();
        return;
    }

    /*
     * By convention, we have min_time equal to zero in messages which we
     * think are not as important, so-called comfort messages. We have
     * min_time >= 3 for messages which we think the user should see for
     * sure. Some users don't like to wait so we've provided a way for them
     * to live on the edge.
     *    status_msg_delay == -1  => min time == MIN(0, min_time)
     *    status_msg_delay == -2  => min time == MIN(1, min_time)
     *    status_msg_delay == -3  => min time == MIN(2, min_time)
     *    ...
     */
    if(ps_global->status_msg_delay < 0)
      min_time = MIN(-1 - ps_global->status_msg_delay, min_time);

多年的夙愿啊~ 算是比较优雅的解决方案了。

IETF提供的Public IMAP访问Archive

2019/01/20更新

https://trac.tools.ietf.org/group/tools/trac/wiki/Imap

可以单独作为Incoming Folders订阅,如订阅stir

incoming-folders="{imap.ietf.org/anonymous/notls}Shared Folders/stir"

(缺点是无法在Alpine里用匿名用户list出所有目录.. 可能是IETF这个IMAP的结构就是这样设计的,Shared Folders里都是unsubscribed状态)

还可以把IETF作为一个Folder Collection,Path设成Shared Folders
这样按G(Goto),选到这个IETF的Collection,然后敲WG的名字,体验也还行。

如果不想用匿名用户,可以去https://datatracker.ietf.org上注册个账户。

RFC1922

RFC1922: Chinese Character Encoding for Internet Messages

作者中有胡道元教授和MRC(M. Crispin),而后者是在UW工作的时候发明了IMAP,或许也是PINE的开发者之一。

参看 CNNIC披露由中国发出的第一封电子邮件原文 - 新浪网 2003

Windows上的编译

请参看 Windows下编译Alpine邮件客户端