[英]Google Script: get content of an email answer without the original email
我在處理作為對自己發送的電子郵件的答復的電子郵件時遇到了麻煩。 確實,當我使用“ getPlainBody”方法獲取電子郵件的內容時,我總是會得到一個包含我想要的消息和原始消息的文本。 此外,我猜格式取決於其他人的電子郵件客戶端。
一些例子來說明這一點:
Hello,
This is my answer to your email.
Best regards
On Wed, Jul 12, 2017 at 10:02 AM, Bastien <bastien@example.org> wrote:
> Hi,
>
> This is the original email I sent you.
> Bastien
或這個:
Hello,
This is my answer to your email.
Best regards
From: bastien@example.org [mailto:bastien@example.org]
Sent: Wednesday, July 12, 2017 6:49 PM
To: someone <someone@example.com>
Subject: this is the original subject
Hi,
This is the original email I sent you.
Bastien
我只想檢索這部分:
Hello,
This is my answer to your email.
Best regards
我也有許多不同語言的電子郵件,因此將原始消息和答案分開的信息可以用任何一種語言編寫,因此以編程方式對任何一種語言進行檢測都有些復雜。
我確信Gmail知道該怎么做,因為在Gmail界面中,它僅顯示我想要的電子郵件部分,並自動隱藏我的第一封電子郵件。 我只是不知道是否有一種使用Google Script提取消息的方法。
巴斯蒂安
我沒有一個不優雅,但相當穩定的方式獲得身體和服用的Gmail的優勢化解知道的情況下,即尋找標記<div class="gmail_quote">
這是[...]
通過GMail的表現。
在那些情況下, [...]
是不是這種情況 (例如由Microsoft郵件發送的郵件)的第一<div>
有時勝任。 您將看到針對自此代碼的第一個實現(大約一年前)以來看到的錯誤而進行的另外兩次嘗試。 在我的情況下, 發件人領域非常小,因此這種俗氣的解決方案效果很好。 祝好運。
mRtaU = mails[j].getBody();
mRta = mRtaU;
mRta = mRta.substring(0,mRta.toLowerCase().indexOf('<div class="gmail_quote">'));
if( mRta == '' ){
mRta = mRtaU;
if( mRta.slice( 0, 5 ) == '<div>' ){ //case Microsoft try I...
mRta = mRta.substring(0,mRta.toLowerCase().indexOf('</div>'));
}else{
if( mRta.slice( 0, 2 ) == '<p' ){ //case Microsoft try II...
mRta = mRta.substring(0, mRta.toLowerCase().indexOf('</p>'));
}else{
mRta = mRta.substring(0,mRta.indexOf('\n')); //last try, a crlf could split the answer from original (yeap, no crlf in html but...)
}
}
}
mRta = mRta.split('<br>').join('\n').replace(/<\/?[^>]+(>|$)/g, "");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.