2014-08-27 59 views
0

我想将我的传入电子邮件存储为* .msg文件,并使用以下外部传送方法尝试此操作;这是行之有效的,但我收到邮件作为一个大的纯文本字符串。无法正确地存储Postfix输出邮件格式

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 [email protected] 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 <[email protected]>; Sat, 23 Aug 2014 19:22:26 +0000 (UTC) Received: by mail-yh0-f49.google.com with SMTP id b6so9924529yha.36 for <[email protected]>; 

下面列出的实例是邮件如何我可以与MIME正确读取的方式:解析器; (例如2)

Delivered-To: [email protected] 
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: <[email protected]> 
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 <[email protected]> 
     (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 [email protected] designates 2a00:1450:400c:c03::22c as permitted sender) client-ip=2a00:1450:400c:c03::22c; 

什么是第一例转换为第二个例子的最佳方式?或者像第二个例子一样保存电子邮件?

回答

0

你不是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对于大多数现实世界的情况仍然会更好,因为它更强大。