Skip to content

Commit 8f93ac2

Browse files
gingeekrishnaC4illin
authored andcommitted
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
1 parent 5ffb7f4 commit 8f93ac2

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/converters/msgconvert.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,20 @@ export function convert(
2626

2727
execFile("msgconvert", args, (error, stdout, stderr) => {
2828
if (error) {
29-
reject(`error: ${error}`);
29+
reject(new Error(`msgconvert failed: ${error.message}`));
3030
return;
3131
}
3232

33-
if (stdout) {
34-
console.log(`stdout: ${stdout}`);
35-
}
36-
3733
if (stderr) {
38-
console.error(`stderr: ${stderr}`);
34+
// Log sanitized stderr to avoid exposing sensitive paths
35+
const sanitizedStderr = stderr.replace(/(\/[^\s]+)/g, "[REDACTED_PATH]");
36+
console.warn(`msgconvert stderr: ${sanitizedStderr.length > 200 ? sanitizedStderr.slice(0, 200) + '...' : sanitizedStderr}`);
3937
}
4038

41-
resolve("Done");
39+
resolve(targetPath);
4240
});
4341
} else {
44-
reject(`Unsupported conversion from ${fileType} to ${convertTo}. Only MSG to EML conversion is currently supported.`);
42+
reject(new Error(`Unsupported conversion from ${fileType} to ${convertTo}. Only MSG to EML conversion is currently supported.`));
4543
}
4644
});
4745
}

0 commit comments

Comments
 (0)