maildir标题问题

发布于 2024-07-13 08:46:10 字数 2240 浏览 12 评论 0原文

我有以下 bash 脚本来更新 maildir 文件的 mtimes:

#!/bin/bash

for i in /test/emailfile

do
    date=$(sed -n '/Received: from/ { :a; n; /;/ {s/.*; //p;q}; b a }' "$i")
    newdate=$(date -d "$date" +'%Y%m%d%H%M.%S')
    touch -t "$newdate" "$i"
done

该脚本始终工作正常,具有如下标准标头:

Delivery-date: Sun, 22 Apr 2007 00:15:13 -0600
Received: from an-out-0708.google.com ([209.85.132.243])
    by x.xxxx.com with esmtp (Exim 4.63)
    (envelope-from <[email protected]>)
    id 1HfVLs-0002Io-RQ
    for [email protected]; Sun, 22 Apr 2007 00:15:13 -0600

其中有 2007 年的交付日期。 如果我触摸该文件,使文件日期从今天开始,然后运行我的脚本,文件日期将恢复为收到的日期。

但是,当尝试在具有以下标题的电子邮件上运行我的脚本时:

Delivery-date: Mon, 15 Dec 2008 17:26:37 -0800
Received: from xxxxxx ([130.194.13.165])
    by xxxxxxx with esmtp (Exim 4.69)
    (envelope-from <[email protected]>)
    id 1LCOhp-0006fm-2g
    for [email protected]; Mon, 15 Dec 2008 17:26:37 -0800

日期显然未恢复。 我看不出标题有任何明显的不同。 我需要重置 mtime,因为许多邮件客户端使用文件时间来显示接收时间。 我的脚本已处理超过 3000 封电子邮件,确保所有客户端在移动服务器和具有相同日期的所有文件后以正确的顺序显示电子邮件,但由于某种原因,它不适用于特定电子邮件。 我是否在剧本中遗漏了一些明显的内容?

编辑:日期显然是从脚本中恢复的,但是无论脚本将日期设置为什么,依赖 mtimes 的客户端都不会显示此消息。 权限相同,布局和文件名格式也相同。 下面是来自 ls -la 的帖子

-rw-rw----   1 username username    11769 Dec 14 21:25 1229318728.H329820P11297.xxxxx.serverxxxxx.com:2,S
-rw-rw----   1 username username     3366 Dec 15 17:26 1229390797.H476913P25671.xxxxx.serverxxxxx.com:2,S
-rw-rw----   1 username username     1149 Dec 22 05:39 1229953142.H901034P11016.xxxxx.serverxxxxx.com:2,S
-rw-rw----   1 username username     7557 Dec 23 15:43 1230075791.H700954P8392.xxxxx.serverxxxxx.com:2,S

无法正确显示的文件是从顶部开始的第二个文件。 有什么方法可以调试为什么会发生这种情况吗?

I have the followign bash script to update mtimes for maildir files:

#!/bin/bash

for i in /test/emailfile

do
    date=$(sed -n '/Received: from/ { :a; n; /;/ {s/.*; //p;q}; b a }' "$i")
    newdate=$(date -d "$date" +'%Y%m%d%H%M.%S')
    touch -t "$newdate" "$i"
done

This script has always worked fine, with standard headers like these:

Delivery-date: Sun, 22 Apr 2007 00:15:13 -0600
Received: from an-out-0708.google.com ([209.85.132.243])
    by x.xxxx.com with esmtp (Exim 4.63)
    (envelope-from <[email protected]>)
    id 1HfVLs-0002Io-RQ
    for [email protected]; Sun, 22 Apr 2007 00:15:13 -0600

Which has a 2007 delivery date. If I touch that file so the file date is from today, and then run my script, the file date is restored to the received from date.

However, when attempting to run my script on an email with the following headers:

Delivery-date: Mon, 15 Dec 2008 17:26:37 -0800
Received: from xxxxxx ([130.194.13.165])
    by xxxxxxx with esmtp (Exim 4.69)
    (envelope-from <[email protected]>)
    id 1LCOhp-0006fm-2g
    for [email protected]; Mon, 15 Dec 2008 17:26:37 -0800

The date is apparantly not restored. I can not see that the headers are obviously different in any way. I need to reset the mtimes, because many mail clients use the filetime to display as the received from time. My script has worked on over 3000 emails, ensuring all clients displays the emails in the right order aftr moving servers and all files having the same date, but for some reason it will not work on a particular email. Have I left something obvious out of the script?

edit: the date is apparently restored from the script, however clients that rely on mtimes will not display this message regardless of what the script sets the date to. The permissions are the same, as is the layout and filename format. Below is a posting from ls -la

-rw-rw----   1 username username    11769 Dec 14 21:25 1229318728.H329820P11297.xxxxx.serverxxxxx.com:2,S
-rw-rw----   1 username username     3366 Dec 15 17:26 1229390797.H476913P25671.xxxxx.serverxxxxx.com:2,S
-rw-rw----   1 username username     1149 Dec 22 05:39 1229953142.H901034P11016.xxxxx.serverxxxxx.com:2,S
-rw-rw----   1 username username     7557 Dec 23 15:43 1230075791.H700954P8392.xxxxx.serverxxxxx.com:2,S

The file that will not display correctly is the second from the top. Is there any way to debug why this is happening at all?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

默嘫て 2024-07-20 08:46:10

它似乎对我来说效果很好,尝试一下这首小曲,看看你会得到什么。

#!/bin/bash
echo 'Delivery-date: Sun, 22 Apr 2007 00:15:13 -0600
Received: from an-out-0708.google.com ([209.85.132.243])
    by x.xxxx.com with esmtp (Exim 4.63)
    (envelope-from <[email protected]>)
    id 1HfVLs-0002Io-RQ
    for [email protected]; Sun, 22 Apr 2007 00:15:13 -0600' | sed -n '/Received: from/ { :a; n; /;/ {s/.*; //p;q}; b a }'
date -d "Sun, 22 Apr 2007 00:15:13 -0600" +'%Y%m%d%H%M.%S'
echo 'Delivery-date: Mon, 15 Dec 2008 17:26:37 -0800
Received: from xxxxxx ([130.194.13.165])
    by xxxxxxx with esmtp (Exim 4.69)
    (envelope-from <[email protected]>)
    id 1LCOhp-0006fm-2g
    for [email protected]; Mon, 15 Dec 2008 17:26:37 -0800' | sed -n '/Received: from/ { :a; n; /;/ {s/.*; //p;q}; b a }'
date -d "Mon, 15 Dec 2008 17:26:37 -0800" +'%Y%m%d%H%M.%S'

我得到(如预期):

Sun, 22 Apr 2007 00:15:13 -0600
200704221415.13
Mon, 15 Dec 2008 17:26:37 -0800
200812161026.37

所以我不确定为什么你的不起作用,尽管该脚本的输出应该是一个很好的起点。

您可以做的另一件事是暂时修改您的脚本,如下所示:

: : : : :
echo touch -t "$newdate" "$i"
touch -t "$newdate" "$i"
: : : : :

这将输出您正在尝试的实际命令。

还要检查目录和单个文件的文件权限。

“ls -l”(mtime)和“ls -lc”(ctime)在实际的可疑邮件文件中给出了什么? 您的脚本可能工作正常,但用户电子邮件客户端未使用 mtime/ctime。

编辑后:

引用“但是,无论脚本将日期设置为什么,依赖 mtimes 的客户端都不会显示此消息”,我的回答是客户端依赖 mtimes。

套用夏洛克自己的话说,一旦你排除了所有其他的可能性,剩下的无论多么不可能,都一定是这种情况。 我注意到一件事:您是否刚刚声明该消息根本没有显示(或者正如我认为我们正在讨论的那样,它的日期错误)?

如果是后者,您需要查看邮件客户端以了解它实际上从哪里获取日期。 只是出于兴趣,客户认为它是哪个日期(它与标头中的任何日期匹配吗?

如果是前者,那是我们可以讨论的不同问题。

我认为这就是(客户)您需要从这里开始的地方而且,由于我的专业知识更多的是脚本而不是电子邮件客户端,所以我可能无法提供进一步的帮助,但我很想知道结果如何,所以我会喜欢这个问题。

It appears to work fine for me, try this little ditty and see what you get.

#!/bin/bash
echo 'Delivery-date: Sun, 22 Apr 2007 00:15:13 -0600
Received: from an-out-0708.google.com ([209.85.132.243])
    by x.xxxx.com with esmtp (Exim 4.63)
    (envelope-from <[email protected]>)
    id 1HfVLs-0002Io-RQ
    for [email protected]; Sun, 22 Apr 2007 00:15:13 -0600' | sed -n '/Received: from/ { :a; n; /;/ {s/.*; //p;q}; b a }'
date -d "Sun, 22 Apr 2007 00:15:13 -0600" +'%Y%m%d%H%M.%S'
echo 'Delivery-date: Mon, 15 Dec 2008 17:26:37 -0800
Received: from xxxxxx ([130.194.13.165])
    by xxxxxxx with esmtp (Exim 4.69)
    (envelope-from <[email protected]>)
    id 1LCOhp-0006fm-2g
    for [email protected]; Mon, 15 Dec 2008 17:26:37 -0800' | sed -n '/Received: from/ { :a; n; /;/ {s/.*; //p;q}; b a }'
date -d "Mon, 15 Dec 2008 17:26:37 -0800" +'%Y%m%d%H%M.%S'

I get (as expected):

Sun, 22 Apr 2007 00:15:13 -0600
200704221415.13
Mon, 15 Dec 2008 17:26:37 -0800
200812161026.37

So I'm not sure why yours isn't working, although the output of that script should be a good starting point.

The other thing you can do is temporarily modify your script as follows:

: : : : :
echo touch -t "$newdate" "$i"
touch -t "$newdate" "$i"
: : : : :

This will output the actual command you're trying.

Also check file permissions on the directory and individual files.

What does "ls -l" (mtime) and "ls -lc" (ctime) give you on the actual suspect mail file? It may be that your script is working fine vut the users email client is not using the mtime/ctime.

After edit:

Quoting "however clients that rely on mtimes will not display this message regardless of what the script sets the date to", my response is that the client is not relying on mtimes.

Paraphrasing Sherlock himself, once you have eliminated all the other possibilities, whatever's left, however unlikely, must be the case. And one thing I noticed: did you just state that the message isn't being displayed at all (or that it's got the wrong date as I've thought we were talking about)?

If the latter, you need to look into the mail client to see where it's actually getting its date from. Just out of interest, what date does the client think it is (and does it match any date within the header?

If the former, that's a different problem we can discuss.

I think that's (the client) where you need to go from here and, since my expertise is more in scripting than email clients, I may not be able to help further. Still, I'm interested to see how it turns out, so I'll favorite this question.

浮光之海 2024-07-20 08:46:10

以下脚本使用邮件消息的“日期”而不是“接收日期”属性。 这会将日期设置为与某些邮件应用程序使用的日期相匹配,并简化 sed 语句。 它还包括改进的错误处理,当遇到不正确/无效的日期时。

#!/bin/bash
echo "Process folder : $@"
for i in $( ls -1 $@ )
do
#    date=$(sed -n '/Received: from/ { :a; n; /;/ {s/.*; //p;q}; b a }' "$i") 
#    date=$(sed -n -f ~/scripts/fix.sed "$i")
    date=$(sed  -n '/^Date: / {s/^Date: //p;q}' "$i")
    newdate=$(date -d "$date" +'%Y%m%d%H%M.%S')
    returnCode=$?
    if [ "$returnCode" != "0" ]
    then
      echo "Date Return Code : $returnCode"
      echo "Message file : $i received at : $date"
    fi
touch -c -t "$newdate" "$i"
done

The following scripts used the Date rather then the Received Date attribute of the mail message. This sets the date to match the date used by some mail applications and simplifies the sed statement as well. It also includes improved error handling when an incorrect / invalid date is encountered.

#!/bin/bash
echo "Process folder : $@"
for i in $( ls -1 $@ )
do
#    date=$(sed -n '/Received: from/ { :a; n; /;/ {s/.*; //p;q}; b a }' "$i") 
#    date=$(sed -n -f ~/scripts/fix.sed "$i")
    date=$(sed  -n '/^Date: / {s/^Date: //p;q}' "$i")
    newdate=$(date -d "$date" +'%Y%m%d%H%M.%S')
    returnCode=$?
    if [ "$returnCode" != "0" ]
    then
      echo "Date Return Code : $returnCode"
      echo "Message file : $i received at : $date"
    fi
touch -c -t "$newdate" "$i"
done
无悔心 2024-07-20 08:46:10

你确定吗 - 这对我有用。

我所做的唯一更改是:

#!/bin/bash

for i in "$@"

do
    date=$(sed -n '/Received: from/ { :a; n; /;/ {s/.*; //p;q}; b a }' "$i")
    newdate=$(date -d "$date" +'%Y%m%d%H%M.%S')
    touch -c -t "$newdate" "$i"
done

touch -c,这样文件就不会通过 touch 创建。

for i in "$@" 以便它在命令行参数而不是固定文件上运行。

$ touch data2 ; ls -l data2
-rw-r--r-- 1 leeder leeder 250 2009-01-22 11:43 data2
$ bash test.sh data data2 ; ls -l data2
-rw-r--r-- 1 leeder leeder 250 2008-12-16 01:26 data2

Are you sure - it works for me.

The only changes I made were:

#!/bin/bash

for i in "$@"

do
    date=$(sed -n '/Received: from/ { :a; n; /;/ {s/.*; //p;q}; b a }' "$i")
    newdate=$(date -d "$date" +'%Y%m%d%H%M.%S')
    touch -c -t "$newdate" "$i"
done

touch -c so that files don't get created by touch.

for i in "$@" so that it runs on the command line arguments rather than a fixed file.

$ touch data2 ; ls -l data2
-rw-r--r-- 1 leeder leeder 250 2009-01-22 11:43 data2
$ bash test.sh data data2 ; ls -l data2
-rw-r--r-- 1 leeder leeder 250 2008-12-16 01:26 data2
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文