require [ "envelope", "fileinto", "mailbox", "subaddress", "variables" ];

#if currentdate :matches "year"  "*" { set "year"  "${1}"; }
#if currentdate :matches "month" "*" { set "month" "${1}"; }

if exists "X-MC-User" {
  if header :matches "From" "*<*@*.asso.fr>*" {
    fileinto :create "Listes+${3}";
    stop;
  }
  elsif header :matches "From" "*<*@*.*>*" {
    fileinto :create "Listes+${3}+${2}";
    stop;
  }
}
elsif exists "List-Id" {
  if allof (header :matches "List-Id" "*<*/*.*.lists.sr.ht>*", not string :is "${2}" "", not string :is "${3}" "", not string :is "${4}" "")  {
    fileinto :create "Listes+sr-ht+${2}+${3}+${4}";
    stop;
  }
  elsif allof (header :matches "List-Id" "*<*/*.lists.sr.ht>*", not string :is "${2}" "", not string :is "${3}" "")  {
    fileinto :create "Listes+sr-ht+${2}+${3}";
    stop;
  }
  elsif allof (header :matches "List-Id" "*<*.*.*.*>*", not string :is "${2}" "", not string :is "${3}" "", not string :is "${4}" "")  {
    fileinto :create "Listes+${4}+${3}+${2}";
    stop;
  }
  elsif allof (header :matches "List-Id" "*<*.*.*>*", not string :is "${2}" "", not string :is "${3}" "")  {
    fileinto :create "Listes+${3}+${2}";
    stop;
  }
}