EmailDiscussions.com  

Go Back   EmailDiscussions.com > Email Service Provider-specific Forums > FastMail Forum
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
Stay in touch wirelessly

FastMail Forum All posts relating to FastMail.FM should go here: suggestions, comments, requests for help, complaints, technical issues etc.

Reply
 
Thread Tools
Old 23 Sep 2021, 04:43 AM   #1
Jacinto
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
Jacinto is offline   Reply With Quote

Old 23 Sep 2021, 05:57 PM   #2
xyzzy
Essential Contributor
 
Join Date: May 2018
Posts: 383
Quote:
Originally Posted by Jacinto View Post
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.
xyzzy is offline   Reply With Quote
Old 23 Sep 2021, 07:53 PM   #3
Jacinto
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
Jacinto is offline   Reply With Quote
Old 24 Sep 2021, 11:27 AM   #4
xyzzy
Essential Contributor
 
Join Date: May 2018
Posts: 383
Quote:
Originally Posted by Jacinto View Post
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" <>
xyzzy is offline   Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +9. The time now is 06:57 AM.

 

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