arithmetric / aws-lambda-ses-forwarder

Serverless email forwarding using AWS Lambda and SES
MIT License
1.7k stars 450 forks source link

Feature Request - always include Reply-to in log #135

Open dubrowin opened 2 years ago

dubrowin commented 2 years ago

I found myself troubleshooting a potential problem and couldn't find logs of the email that I was looking for. After dumping the S3 bucket contents, I was able to find what I was looking for. Only then did I find the difference between when a reply-to is listed in the log or not. And then I found it in the code. I would love an option (or default) to always include the reply-to or source address so that I can search through the logs for it, should I need it.

I've been looking at the code and think it would need to be an else to the primary if here:

  // Add "Reply-To:" with the "From" address if it doesn't already exists
  if (!/^Reply-To: /mi.test(header)) {
    match = header.match(/^From: (.*(?:\r?\n\s+.*)*\r?\n)/m);
    var from = match && match[1] ? match[1] : '';
    if (from) {
      header = header + 'Reply-To: ' + from;
      data.log({level: "info", message: "Added Reply-To address of: " + from});
    } else {
      data.log({level: "info", message: "Reply-To address not added because " +
       "From address was not properly extracted."});
    }
  }

to be something like (I am not a node programmer, which is why this is an issue and not a pull request):

  // Add "Reply-To:" with the "From" address if it doesn't already exists
  if (!/^Reply-To: /mi.test(header)) {
    match = header.match(/^From: (.*(?:\r?\n\s+.*)*\r?\n)/m);
    var from = match && match[1] ? match[1] : '';
    if (from) {
      header = header + 'Reply-To: ' + from;
      data.log({level: "info", message: "Added Reply-To address of: " + from});
    } else {
      data.log({level: "info", message: "Reply-To address not added because " +
       "From address was not properly extracted."});
    } else {
   reply = header.match(/^Reply-To: (.*(?:\r?\n\s+.*)*\r?\n)/m);
   data.log({level: "info", message: "Reply-To existed: + reply});
  }