View Single Post
Old 30 Mar 2020, 08:49 AM   #9
n5bb
Intergalactic Postmaster
 
Join Date: May 2004
Location: Irving, Texas
Posts: 8,929
Arrow Simple label mode sieve code

I have been using the new rules system, which still allows custom sieve code to be inserted at one of three locations:
  1. At the very top of the sieve code.
  2. After the blocked senders and spam filters have executed, but before the normal user configured rules.
  3. At the very end of the sieve code.
When using the new rules and label modes, the automatically created sieve code looks quite different to allow the new features to work. The good news is that in most cases you should be able to add old-style custom sieve before or after the automatically created code.

Below is an example where I have only created the following two user interface rules. I also inserted custom sieve comments (USER CODE A/B/C) at the three locations shown above. Other settings are defaulted.
  • File #1: If subject:file, then Pin, Add label "Test", Skip inbox, and Continue to apply other rules.
  • File #2: If subject:file, then Notify me, Add label "Test", Skip inbox, and Continue to apply other rules.
Code:
require ["fileinto", "reject", "vacation", "notify", "envelope", "body", "relational", "regex", "subaddress", 
  "copy", "mailbox", "mboxmetadata", "servermetadata", "date", "index", "comparator-i;ascii-numeric",
  "variables", "imap4flags", "editheader", "duplicate", "vacation-seconds", "fcc", "x-cyrus-jmapquery"];
# USER CODE A *************************************************************
### 1. Sieve generated for save-on-SMTP identities
# You do not have any identities with special filing.

### 2. Sieve generated for blocked senders
# You have no blocked senders.

### 3. Sieve generated for spam protection
if not header :matches "X-Spam-Known-Sender" "yes*" {
  if 
    allof(
    header :contains "X-Backscatter" "yes",
    not header :matches "X-LinkName" "*"
    )
  {
    fileinto "\\Junk";
    stop;
  }
  if header :value "ge" :comparator "i;ascii-numeric" "X-Spam-score" "5" {
    fileinto "\\Junk";
    stop;
  }
}

# USER CODE B *************************************************************
### 4. User configured rules

### 4a. Calculate rule actions

# Rule File #1
# Search: "subject:file"
if 
  allof( not string :is "${stop}" "Y",
    jmapquery text:
  {
     "subject" : "file"
  }
.
  )
{
  addflag "\\Flagged";
  
  set "L0_Test" "Y";
  
  set "skipinbox" "Y";
  
}

# Rule File #2
# Search: "subject:file"
if 
  allof( not string :is "${stop}" "Y",
    jmapquery text:
  {
     "subject" : "file"
  }
.
  )
{
  addflag "$notify";
  
  set "L1_Testing" "Y";
  
  set "skipinbox" "Y";
  
}

### 4b. Rule sent message to trash
if string :is "${deletetotrash}" "Y" {
  fileinto "\\Trash";
}

### 4c. Rule says message is spam
elsif string :is "${spam}" "Y" {
  fileinto "\\Junk";
}

### 4d. Do rule actions
else {
  if string :is "${L0_Test}" "Y" {
    set "hasmailbox" "Y";
    fileinto :copy "INBOX.Test";
  }
  if string :is "${L1_Testing}" "Y" {
    set "hasmailbox" "Y";
    fileinto :copy "INBOX.Testing";
  }
  if string :is "${skipinbox}" "Y" {
    if string :is "${hasmailbox}" "Y" {
      discard;
    }
    else {
      fileinto "\\Archive";
    }
  }
  else {
    ### 4e. Sieve generated for fetch mail filing
    # You have no pop-links filing into special folders.
  }
  
  ### 5. Sieve generated for vacation responses
  # You do not have vacation responses enabled.
  
  ### 6. Sieve generated for calendar preferences
  if 
    allof(
    header :is "X-ME-Cal-Method" "request",
    not exists "X-ME-Cal-Exists",
    header :contains "X-Spam-Known-Sender" "in-addressbook"
    )
  {
    notify :method "addcal";
  }
  elsif exists "X-ME-Cal-Exists" {
    notify :method "updatecal";
  }
}

if string :is "${stop}" "Y" {
#   For backwards compatibility
}

# USER CODE C *************************************************************
n5bb is offline   Reply With Quote