Improve msgconvert error handling and security

- Remove unnecessary stdout logging to reduce output clutter
- Sanitize stderr logging to protect sensitive path information
- Return targetPath instead of generic 'Done' message for better caller context
- Use proper Error objects instead of string rejections
- Address Sourcery AI feedback from PR #370
This commit is contained in:
radhakrishnan 2025-07-24 21:13:20 +05:30 committed by Emrik Östling
parent 5ffb7f4a01
commit 8f93ac29dd

View file

@ -26,22 +26,20 @@ export function convert(
execFile("msgconvert", args, (error, stdout, stderr) => { execFile("msgconvert", args, (error, stdout, stderr) => {
if (error) { if (error) {
reject(`error: ${error}`); reject(new Error(`msgconvert failed: ${error.message}`));
return; return;
} }
if (stdout) {
console.log(`stdout: ${stdout}`);
}
if (stderr) { if (stderr) {
console.error(`stderr: ${stderr}`); // Log sanitized stderr to avoid exposing sensitive paths
const sanitizedStderr = stderr.replace(/(\/[^\s]+)/g, "[REDACTED_PATH]");
console.warn(`msgconvert stderr: ${sanitizedStderr.length > 200 ? sanitizedStderr.slice(0, 200) + '...' : sanitizedStderr}`);
} }
resolve("Done"); resolve(targetPath);
}); });
} else { } else {
reject(`Unsupported conversion from ${fileType} to ${convertTo}. Only MSG to EML conversion is currently supported.`); reject(new Error(`Unsupported conversion from ${fileType} to ${convertTo}. Only MSG to EML conversion is currently supported.`));
} }
}); });
} }