require [ "regex", "variables", "fileinto", "envelope", "mailbox",
  "imap4flags", "include" ];

if address :is "from" "noreply+chat@canonical.com" {
  fileinto :create "mattermost";
  stop;
}

if address :is "from" "noreply+discourse@canonical.com" {
  fileinto :create "discourse";
  stop;
}

if address :is :domain "from" ["discourse.ubuntu.com", "forum.snapcraft.io"] {
  fileinto :create "discourse";
  stop;
}

if address :is "from" "jira@warthogs.atlassian.net" {
  fileinto :create "jira";
  stop;
}

if address :is :domain "from" "rt.canonical.com" {
  fileinto :create "rt";
  stop;
}

if address :matches :domain "from" ["launchpad.net", "*.launchpad.net"] {
  fileinto :create "launchpad";
  stop;
}

if address :is "from" "gitlab@salsa.debian.org" {
  fileinto :create "salsa";
  stop;
}

if address :is "from" "bugzilla-daemon@mozilla.org" {
  fileinto :create "bugzilla";
  stop;
}

if address :is "to" "ftp-release-notifications@gnome.org" {
  fileinto :create "gnome-releases";
  stop;
}

if address :is "from" "notifications@github.com" {
  keep;
  stop;
}

if allof (header :regex "list-id" "<([a-z_0-9-]+)[.@]",
  not address :regex :localpart "from" "^(no)?reply")
{
  set :lower "listname" "${1}";
  fileinto :create "l.${listname}";
  stop;
}