EmailDiscussions.com

EmailDiscussions.com (http://www.emaildiscussions.com/index.php)
-   FastMail Forum (http://www.emaildiscussions.com/forumdisplay.php?f=27)
-   -   Quick and Dirty Sieve Script to add Missing "Subject" Header (http://www.emaildiscussions.com/showthread.php?t=78824)

Jacinto 23 Sep 2021 04:43 AM

Quick and Dirty Sieve Script to add Missing "Subject" Header
 
Hello!

I subscribe to a fax service that sends an E-Mail notification of incoming faxes. As luck would have it, notification messages do not have a "Subject" header.

Not having composed Sieve scripts for a while, I've gotten rusty and would appreciate anyone who's willing to share her or his knowledge for a Sieve script to add the missing header.

Cannot use the sender's E-Mail address because I also receive sent fax confirmations that do contain a Subject header.

The sender's name without the E-Mail address could be use because the name is different for sent fax confirmations.

Thank you.

--
Jacinto

xyzzy 23 Sep 2021 05:57 PM

Quote:

Originally Posted by Jacinto (Post 622534)
Cannot use the sender's E-Mail address because I also receive sent fax confirmations that do contain a Subject header.

The sender's name without the E-Mail address could be use because the name is different for sent fax confirmations.

Here, I guess, is a 1st approximation (tested with Sieve Tester):

Code:

if not exists "Subject" {
  if header :regex "From" "[[:space:]]*\"?(.*?)\"?[[:space:]]*<" {
    set "name" "${1}";
  } else {
    set "name" "what do you want to do if there is no name?";
  }

  addheader "Subject" "${name}";
}

This uses the sender's name extracted from the "From" header if it's there. Not sure what you want to use if there is no name.

Note, the extraction of the name from the From header is more-or-less paraphrasing what FM generates for the UI "From name" (no preview) condition. It allows any number of leading spaces, names enclosed in quotes, and any number of spaces before the '<' preceding the email address. This match will fail if there is no name so I added a placeholder to handle that case but I don't know what you want to do for that case.

Jacinto 23 Sep 2021 07:53 PM

Good morning and thank you, xyzzy!

Looks good.

I'll play with it over the weekend and report how I made out.

Thank you, again.

--
Jacinto

xyzzy 24 Sep 2021 11:27 AM

Quote:

Originally Posted by Jacinto (Post 622547)
I'll play with it over the weekend and report how I made out.

Ok, good luck. If you decide to play around with this in Sieve Tester (that's what I do with these kind of things) then for the sake of completeness the minimum require line for this test can be the following:

Code:

require ["fileinto", "regex", "variables", "editheader"];
or just use the full require line from the full FM Sieve script (that's easier then spending the effort stripping it down).

The test cases I used were,

Code:

From: name  <>
and
Code:

From: "a name" <>


All times are GMT +9. The time now is 01:51 PM.


Copyright EmailDiscussions.com 1998-2022. All Rights Reserved. Privacy Policy