|
FastMail Forum All posts relating to FastMail.FM should go here: suggestions, comments, requests for help, complaints, technical issues etc. |
|
Thread Tools |
23 Sep 2021, 04:43 AM | #1 |
Essential Contributor
Join Date: Jun 2009
Posts: 395
|
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 |
23 Sep 2021, 05:57 PM | #2 | |
Essential Contributor
Join Date: May 2018
Posts: 474
|
Quote:
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}"; } 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. |
|
23 Sep 2021, 07:53 PM | #3 |
Essential Contributor
Join Date: Jun 2009
Posts: 395
|
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 |
24 Sep 2021, 11:27 AM | #4 |
Essential Contributor
Join Date: May 2018
Posts: 474
|
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"]; The test cases I used were, Code:
From: name <> Code:
From: "a name" <> |