私は電子メール関連のPoCでPythonを使用しています。システムはメールトレイルを含むメールを受信します。個々のメールをメールトレイルから分離して処理したかったのです。問題は、私はそれを行うための正しいコードやライブラリを取得していないです。誰でも助けてください。Pythonを使用してメールをメールトレイルから分離する
SUBJECT: RE: CALL ID # 98670786 CALL ID # 98983051 DATE SENT: 23-JANUARY-2017 TIME SENT: 17:56:09 PM SENDER ID: [email protected] MESSAGE TEXT: DEAR SIR,
Please check and let me know
REGARDS
XXXXXXX
00000015
FROM: company;[email protected]
SENT:MON, 23 JAN 2017 16:04:26 +0530
TO: [email protected]
SUBJECT: RE: RE: CALL ID # 98670786 CALL ID # 98983051
DEAR MR. XXXXX,
>
>WE REFER TO YOUR EMAIL DATED 20/01/2017 FOR THE company.
>
>WE HEREBY INFORM YOU THAT WE HAVE CHECKED WITH OUR TOUCH POINT AND THEY HAVE CONFIRMED THAT THE Things HAS BEEN delivered TO YOU AND WE WOULD KINDLY REQUEST YOU TO CHECK YOUR at your end FOR BETTER ASSISTANCE.
>
>
>
>YOURS SINCERELY,
>
>sender,
>Company
>----------------------------------------------------------
>Disclaimers:
>adsadsadsadadasdada
>daadsadadsadsadsa.
>REGISTERED ADDRESS:-sadsadsadsadsadsadsadasdsadsadsadsa
>---------------ORIGINAL MESSAGE------------------
>SUBJECT: CALL ID # 98418758 CALL ID # 98510240 CALL ID # 98670786 DATE SENT: 20-JANUARY-2017 TIME SENT: 11:06:38 AM SENDER ID: [email protected] MESSAGE TEXT: DEAR SIR,
>
>BY WHEN WILL THIS things WILL BE delivered TO Me.
>
>REGARDS
>
>XXXXXXX
>
>00000015
>
>FROM: "company"[email protected]
>SENT:FRI, 20 JAN 2017 10:44:16 +0530
>TO: [email protected]
>SUBJECT: RE: RE: CALL ID # 98510240 CALL ID # 98670786
>DEAR MR. XXXXX, WE APPRECIATE YOUR TIME AND PATIENCE AND APOLOGIZE FOR THE LATE RESPONSE.
>>
>>WE REFER TO YOUR EMAIL DATED 11/01/2017N FOR company NUMBER 00000015. WITH REGARDS TO YOUR CONCERN WE HEREBY INFORM YOU THAT TILL DATE YOUR things is pending with us.
>>TRUST THIS CLARIFIES YOUR CONCERN. YOURS SINCERELY,
>>
>>Sender.
>>company
>>----------------------------------------------------------
>>CALL CENTER TIMINGS: 10.00 A.M. TO 7.00 P.M MONDAY TO SATURDAY (EXCEPT NATIONAL HOLIDAYS)
の下に上記のメールが
1以下のような四つの部分に分割されなければならないよう システム)
SUBJECT: RE: CALL ID # 98670786 CALL ID # 98983051 DATE SENT: 23-JANUARY-2017 TIME SENT: 17:56:09 PM SENDER ID: [email protected] MESSAGE TEXT: DEAR SIR,
Please check and let me know
REGARDS
XXXXXXX
00000015
2)
FROM: company;[email protected]
SENT:MON, 23 JAN 2017 16:04:26 +0530
TO: [email protected]
SUBJECT: RE: RE: CALL ID # 98670786 CALL ID # 98983051
DEAR MR. XXXXX,
>
>WE REFER TO YOUR EMAIL DATED 20/01/2017 FOR THE company.
>
>WE HEREBY INFORM YOU THAT WE HAVE CHECKED WITH OUR TOUCH POINT AND THEY HAVE CONFIRMED THAT THE Things HAS BEEN delivered TO YOU AND WE WOULD KINDLY REQUEST YOU TO CHECK YOUR at your end FOR BETTER ASSISTANCE.
>
>
>
>YOURS SINCERELY,
>
>sender,
>Company
>----------------------------------------------------------
>Disclaimers
>adsadsadsadadasdada
>daadsadadsadsadsa.
>REGISTERED ADDRESS:-sadsadsadsadsadsadsadasdsadsadsadsa
3)
メールを取得します>---------------ORIGINAL MESSAGE------------------
>SUBJECT: CALL ID # 98418758 CALL ID # 98510240 CALL ID # 98670786 DATE SENT: 20-JANUARY-2017 TIME SENT: 11:06:38 AM SENDER ID: [email protected] MESSAGE TEXT: DEAR SIR,
>
>BY WHEN WILL THIS things WILL BE delivered TO Me.
>
>REGARDS
>
>XXXXXXX
>
>00000015
>
4)
>FROM: "company"[email protected]
>SENT:FRI, 20 JAN 2017 10:44:16 +0530
>TO: [email protected]
>SUBJECT: RE: RE: CALL ID # 98510240 CALL ID # 98670786
>DEAR MR. XXXXX, WE APPRECIATE YOUR TIME AND PATIENCE AND APOLOGIZE FOR THE LATE RESPONSE.
>>
>>WE REFER TO YOUR EMAIL DATED 11/01/2017N FOR company NUMBER 00000015. WITH REGARDS TO YOUR CONCERN WE HEREBY INFORM YOU THAT TILL DATE YOUR things is pending with us.
>>TRUST THIS CLARIFIES YOUR CONCERN. YOURS SINCERELY,
>>
>>Sender.
>>company
>>----------------------------------------------------------
>>CALL CENTER TIMINGS: 10.00 A.M. TO 7.00 P.M MONDAY TO SATURDAY (EXCEPT NATIONAL HOLIDAYS)
------順列をたくさんした後----- 編集、私は、コードを次のようになってきました。
startMsgPatter=
re.compile((\W*ORIGINAL\s*MESSAGE|\W*FROM\s*:|\W*ON.*WROTE\s*:)")
def sperateEmails(callDesc):
itr = startMsgPatter.finditer(callDesc)
blockStart = 0
emails = []
while True:
m = next(itr,None)
if not m:
break
blockEnd = m.start()
if blockStart >= blockEnd:
continue
emailPart = callDesc[blockStart:blockEnd]
emails.append(emailPart)
blockStart = blockEnd
emails.append(callDesc[blockStart:len(callDesc)])
return emails
私は動作していますが、メールの開始と終了を示すパターンを見つけて更新する必要があります。私のように、このメールトレイルは特定のパターンに従うべきです。誰もこのパターンの大部分を考慮してコードを書いていますか?それを共有してください。
例を挙げていただけますか? – BoilingFire