Procmail to automatically make new folders to store emails from new senders

混江龙づ霸主 提交于 2019-12-02 08:07:11

It's not clear what you expect the folder to be called, and what mailbox format you're using; but assuming maildir folders named by the sender's email terminus, try

Who=`formail -rtzxTo:`
:0
* ? mkdir -p "$Who"
$Who/

For an mbox folder, you don't need the directory check at all, because the folder is just a single text file, and you'd drop the final slash from the folder name. Mbox needs locking, so add a second colon after the zero.

Who=`formail -rtzxTo:`
:0:
$Who

Getting formail to create a reply and then extracting the To: header of the generated reply is a standard but slightly unobvious way to obtain just the email terminus for the sender of the input message.

The shell snippet mkdir -p dir creates dir if it doesn't already exist, and is a harmless no-op otherwise.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!