(bodyText = '', headers = {})
| 259 | } |
| 260 | |
| 261 | function decodeMimeBody(bodyText = '', headers = {}) { |
| 262 | const contentType = String(headers['content-type'] || ''); |
| 263 | const transferEncoding = String(headers['content-transfer-encoding'] || '').trim().toLowerCase(); |
| 264 | const charset = getCharsetFromContentType(contentType); |
| 265 | let decoded = String(bodyText || ''); |
| 266 | |
| 267 | if (transferEncoding === 'base64') { |
| 268 | decoded = decodeBytesToString(base64ToBytes(decoded), charset); |
| 269 | } else if (transferEncoding === 'quoted-printable') { |
| 270 | decoded = decodeBytesToString(quotedPrintableToBytes(decoded), charset); |
| 271 | } |
| 272 | |
| 273 | if (/text\/html/i.test(contentType)) { |
| 274 | return stripHtmlTags(decoded); |
| 275 | } |
| 276 | return decoded.replace(/\s+/g, ' ').trim(); |
| 277 | } |
| 278 | |
| 279 | function extractTextFromMime(rawMessage = '', depth = 0) { |
| 280 | const { headerText, bodyText } = splitRawMessage(rawMessage); |
no test coverage detected