0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

GASでGmailの本文から不要な空行を削除する

Posted at

GASでメールを転送する時に不要な空行を削除したい場合など。

返信部分の空行は引用表示なので「>」が入力されています。
なので空判定と併せて引用符も判定しましょう。

無題.png

// 連続する空行を削除
function func(mailBody){
  var result = [];
  var strList = mailBody.split(/\r\n|\n/g);
  var prevRow = 'dummy';
  strList.forEach(function(currentRow) {
    var currentRow = currentRow.trim();
    if ((prevRow && prevRow != '>') || (currentRow && currentRow != '>')) {
      result.push(currentRow);
    }
    prevRow = currentRow;
  });
  return result.join("\n");
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?