AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 118527
Accepted
MyOnlyEye
MyOnlyEye
Asked: 2010-03-03 14:52:27 +0800 CST2010-03-03 14:52:27 +0800 CST 2010-03-03 14:52:27 +0800 CST

如何将邮件从 /var/spool/mail/ [user] 移动到用户邮箱?

  • 772

我需要一种方法(脚本)也将除最后 100 条消息之外的所有消息从用户邮件假脱机 (/var/spool/mail/theuser) 移动到用户邮件目录 (/home/theuser/mail) 中的文件/mbox )。是否有捷径可寻?

email exim
  • 1 1 个回答
  • 1665 Views

1 个回答

  • Voted
  1. Best Answer
    quadruplebucky
    2010-03-03T19:28:21+08:002010-03-03T19:28:21+08:00

    这是一个快速而肮脏的开端。没有错误检查,它实际上并没有按原样“移动”任何东西。

    #!/usr/local/bin/bash
    #
    # DIRTY hack to append all but the last 100 messages from each file
    # in a dir of mbox files to like named files in /tmp
    #
    # if an mbox has less than 101 messages, skip it
    #
    # requires formail (from the procmail installation..)
    
    #
    # we're writing in tmp - to write in the user's dir move this 
    # inside the for loop and use $USERMAIL to write the base path
    DESTDIR="/tmp"
    
    for USERMAIL in `ls -1`
    
    do
    MESSAGECOUNT=`cat $USERMAIL | formail -q -s wc | wc -l | sed 's/^[ \t]*//'`
    COPYTHISMANY=`expr $MESSAGECOUNT - 100`
    if [ $COPYTHISMANY -gt 0 ]
    then
    echo "Copying $COPYTHISMANY messages from $USERMAIL to /tmp/$USERMAIL.allbutlast100"
    cat $USERMAIL | formail -$COPYTHISMANY -s cat >> $DESTDIR/$USERMAIL.allbutlast100
    # copy the last 100 to a new file
    cat $USERMAIL | formail +$COPYTHISMANY -s cat >> $DESTDIR/$USERMAIL.last100
    # to replace the original source mbox do something like
    # mv /tmp/$USERMAIL.last100 $USERMAIL
    fi
    done
    
    • 2

相关问题

  • 如何绕过 ISP 的限制性电子邮件政策?

  • SharePoint 传入电子邮件出现“未知别名”错误

  • 电子邮件帐户的角色名称与人名

  • 如何在笔记本电脑上使用 Tobit David?[关闭]

  • 随行人员通过 VPN 连接到 Exchange 2007

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    从 IP 地址解析主机名

    • 8 个回答
  • Marko Smith

    如何按大小对 du -h 输出进行排序

    • 30 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    MikeN 在 Nginx 中,如何在维护子域的同时将所有 http 请求重写为 https? 2009-09-22 06:04:43 +0800 CST
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    0x89 bash中的双方括号和单方括号有什么区别? 2009-08-10 13:11:51 +0800 CST
  • Martin Hope
    Kyle Brandt IPv4 子网如何工作? 2009-08-05 06:05:31 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve