【问题标题】:Unable to store Postfix output mail format properly无法正确存储 Postfix 输出邮件格式
【发布时间】:2014-10-21 00:46:54
【问题描述】:

我想将收到的电子邮件存储为 *.msg 文件,我尝试使用以下外部传递方法;这运作良好,但我收到的邮件是一个大的纯文本字符串。

foofoofoo unix -      n       n       -       -       pipe
  flags=F user=www-data argv=/mle/scripts/parse_postfix.sh ${sender} ${recipient}

我的 parse_postfix.sh 包含以下代码;

#!/bin/bash

mail=$(cat);

ddate=`date +%Y%m%d_%H%M%S`
msg_file=${ddate}.msg
path=/mle/spool/${code}
echo $mail > ${path}/${msg_file};

此方法的输出是一个大字符串,我无法使用 MIME:Parser 读取它; (示例 1)

From foo@gmail.com Sat Aug 23 19:22:27 2014 Received: from mail-yh0-f49.google.com (mail-yh0-f49.google.com [209.85.213.49]) by foo.testtesttest.com (Postfix) with ESMTPS id D83DC43C8 for <foo@testtesttest.com>; Sat, 23 Aug 2014 19:22:26 +0000 (UTC) Received: by mail-yh0-f49.google.com with SMTP id b6so9924529yha.36 for <foo@testtesttest.com>;

下面列出的示例邮件是我如何使用 MIME:Parser 正确阅读它的方式; (示例 2)

Delivered-To: foo@testtesttest.com
Received: by 10.140.108.135 with SMTP id j7csp222526qgf;
        Thu, 3 Jul 2014 06:26:51 -0700 (PDT)
X-Received: by 10.194.82.106 with SMTP id h10mr3033237wjy.115.1404394010626;
        Thu, 03 Jul 2014 06:26:50 -0700 (PDT)
Return-Path: <foo@gmail.com>
Received: from mail-we0-x22c.google.com (mail-we0-x22c.google.com [2a00:1450:400c:c03::22c])
        by mx.google.com with ESMTPS id e6si24028130wix.75.2014.07.03.06.26.50
        for <foo@testtesttest.com>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Thu, 03 Jul 2014 06:26:50 -0700 (PDT)
Received-SPF: pass (google.com: domain of foo@gmail.com designates 2a00:1450:400c:c03::22c as permitted sender) client-ip=2a00:1450:400c:c03::22c;

将第一个示例转换为第二个示例的最佳方法是什么?还是像第二个例子一样正确保存电子邮件?

【问题讨论】:

    标签: bash email postfix-mta


    【解决方案1】:

    你不是 quoting 正确的变量。

    echo "$mail"
    

    不过,明智的解决方案是根本不使用变量。

    ddate=$(date +%Y%m%d_%H%M%S)
    msg_file=${ddate}.msg
    path=/mle/spool/${code}
    cat> ${path}/${msg_file}
    

    如果在同一秒内有多条消息到达,这仍然​​会有问题。

    无论如何,我不明白您为什么不使用 Postfix 本身的内置交付机制。如果你想对传递有更多的控制,也许可以挂在 Procmail 中,它具有用于运行消息编号的内置传递模式。对于大多数实际场景来说,正确的 Maildir 仍然会更好,因为它更健壮。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-18
      • 1970-01-01
      • 2016-08-26
      • 2018-10-05
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      相关资源
      最近更新 更多