37 lines
865 B
JavaScript
37 lines
865 B
JavaScript
|
|
/**
|
||
|
|
* 메일 크기 계산 유틸리티
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 메일 크기 계산 (bytes)
|
||
|
|
* subject + text + html + 첨부파일 크기 합산
|
||
|
|
* @param {object} emailData - 메일 데이터
|
||
|
|
* @returns {number} 크기 (bytes)
|
||
|
|
*/
|
||
|
|
const calculateEmailSize = (emailData) => {
|
||
|
|
let size = 0;
|
||
|
|
if (emailData.subject) size += Buffer.byteLength(emailData.subject, "utf8");
|
||
|
|
if (emailData.text) size += Buffer.byteLength(emailData.text, "utf8");
|
||
|
|
if (emailData.html) size += Buffer.byteLength(emailData.html, "utf8");
|
||
|
|
|
||
|
|
let atts = emailData.attachments || [];
|
||
|
|
|
||
|
|
// JSON 문자열인 경우 파싱
|
||
|
|
if (typeof atts === "string") {
|
||
|
|
try {
|
||
|
|
atts = JSON.parse(atts);
|
||
|
|
} catch {
|
||
|
|
atts = [];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if (Array.isArray(atts)) {
|
||
|
|
atts.forEach((att) => {
|
||
|
|
size += att.size || 0;
|
||
|
|
});
|
||
|
|
}
|
||
|
|
return size;
|
||
|
|
};
|
||
|
|
|
||
|
|
module.exports = { calculateEmailSize };
|