The company used an online CRM system before and decided to disable it. Therefore, all previous customer emails must be exported from the CRM system. The problem is that the export mechanism is to use the mail client to receive the email again. This will change the receiving time of all emails to the receiving time, rather than the original receiving time of the email, this is not conducive to the user's search for historical emails (Foxmail only shows one time, cannot display the sending time, or you can also sort them by the sending time). At that time, I thought of a way, guide all emails. modify the receiving time of the EML file to the sending time, so that the mail client can be imported again in chronological order.
This time, shell commands such as sed in Linux are used. It takes a lot of time to debug the regular expression, but it is recorded as follows:
. Eml email format:
Return-path: <xioh@163.com>
Delivered-to: hog@trade.alisoft.com
Received: (Qmail 20460 invoked from network );
Written ed: from unknown (Helo alswm-rule3.hst.jyl.itbu.alidc.net) (172.26.9.127)
By 0 with SMTP; 23 Jul 2011 16:20:13-0000
Message-ID: <6935039.1311438013166.JavaMail.admin@alswm-rule3.hst.jyl.itbu.alidc.net>
Date: Wed, 20 Jul 2011 09:57:16 + 0800 (CST)
From: =? GBK? B? Urjz7q3lnwuuo =? = <Xionsh@163.com>
Reply-to: =? GBK? B? Export zh7q3lnwuuo =? = <Xiosh@163.com>
To: =? GBK? Q? Xuxiaoyan = 28 = D0 = EC = cf = Fe = d1 = d2 = a3 = A9? = <Xuxin@hoang.com>
Subject: =? GBK? B? 1/tfwcu5tcs/qsax0qrh8w =? =
Cc: =? GBK? B? Wu2zra =? = <Step@hog.com>,
=? GBK? B? 1 tzbwblfilrqycw =? = <Zhouliangcai@hog.com>
Mime-type: 1.0
Content-Type: multipart/mixed;
Boundary = "---- = _ part_1375787_30476309.1311438013163"
------ = _ Part_1375787_30476309.1311438013163
Content-Type: text/html; charset = GBK
Content-transfer-encoding: quoted-printable
<Div> </div>
<Div> = D0 = EC = D7 = DC3 = BA </div>
The shell script is as follows: Modify the Mail File Sending time to the receiving time, and rename the mail as the email before the Mail name.
#! /Bin/bash
Export ifs = $ '\ N'
Subdir = "modified"
Filelist = 'ls *. yml'
Mkdir $ subdir
For filename in $ filelist
Do
D = 'sed-n "1,15 S/^ \ (date :\)\(. * (CST) \ r \)/\ 2/P "$ filename '# obtain the mail sending time
E = 'sed-n "1, 15 S/^ \ (from :. * <\)\(. * \) \ (> \ r. * \)/\ 2/P "$ filename '# retrieve the sender of the email
Filename2 =$ {filename: 0 :( $ {# filename}-4 )}
Filename2 = "$ {filename2: 0: 64}. eml"
Filename2 = "$ subdir/from _ $ E, 'date-d" $ D "+ % Y-% m-% d _ % H: % M' _ $ filename2"
CP $ filename $ filename2 # copy a copy with the new file name
Sed-I "s/\ (received ed:. *; \) \ (. * \)/\ 1 $ D/g" $ filename2 # modify the mail receipt time
# Echo "CP" "$ FILENAME" $ filename2
Done
Refer:
Http://sed.sourceforge.net/sed1line_zh-CN.html