Sieve Kullanarak Sunucu Tarafı Posta Filtreleme

Sieve Kullanarak Sunucu Tarafı Posta Filtreleme

Sieve, postaları filtrelemek için tasarlanmış bir dildir ve sunucu tarafı filtreleme için kullanılır. Sunucudaki e-postaları filtrelemek, filtrelerinizi sunucuda bir kez ayarlayacağınız ve bunların aldığınız tüm postalara uygulanacağı anlamına gelir. Sunucu tarafı filtreniz her zaman posta istemcisinden bağımsız olarak kullanılacaktır. Böylece tüm istemcileriniz (farklı makinelerdeki farklı e-posta programları ve web postası), farklı yazılımlar arasında senkronizasyon sağlanması zor/imkansız olabilecek filtreleme kurallarından kurtulacaktır. Ayrıca sunucuda filtre uygulanırken posta klasörü dizinleri güncellenir; bu e-posta erişiminizi daha hızlı hale getirir.

Webmail'de Sieve Eklentisini Kullanmak

Posta filtreleme kuralları kurallarını eklemek/düzenlemek için Roundcube Webmail'deki eleme eklentisini kullanabilirsiniz. Eklentiye Roundcube'da Ayarlar → Filtreleme yoluyla erişebilirsiniz. Spam postalar için varsayılan bir kural bulacaksınız; spam posta kutusuna doğru spam filtrelemesi yapmak için lütfen bu kuralı yerinde bırakın. Spam kuralından sonra yeni kurallar ekleyebilirsiniz.

Sieve Dosyasını Manuel Olarak Düzenlemek

E-postalarınızı, posta sunucusuna ulaştığında farklı klasörlerde düzenlemek için elek dili kullanılabilir. Gelen kutunuzdan ayrı e-posta listeleri, dersle ilgili e-postalar olarak kullanabilirsiniz. Veya web sitelerine gönderilen e-postaları ayırt etmek için 'myuser+amazon@ceng.metu.edu.tr' gibi e-postalar verebilirsiniz. Ayrıca bunu tatil otomatik yanıtlayıcısı ve e-postayı reddetmek, atmak, iletmek için kullanabilirsiniz. Filtreleme dili, C benzeri sözdizimiyle tanıdık görünüyor.

Filtreleme komut dosyanızı ~/.dovecot.sieve dosyasına koyarak süzgeci kullanabilirsiniz. Dosyanın grup veya dünya tarafından okunabilir olması GEREKMEZ. Komut dosyasını değiştirdikten sonra kendinize bir test postası gönderin. Eğer elek scriptinizde bir hata varsa ana dizininizin altında “.dovecot.sieve.err” adında bir dosya oluşturulacak ve bu dosya hata mesajını içerecektir. Hata olması durumunda herhangi bir filtreleme yapılmayacak ve mailler gelen kutunuza teslim edilecektir. Eğer herhangi bir hata yoksa ana dizininizin altında “.dovecot.sievec” isminde derlenmiş bir elek dosyası görünecek ve filtreleriniz uygulanacaktır.

Bir eleme komut dosyasının nasıl çalıştığı aşağıda açıklanmıştır:

Bir komut dosyası 'require' direktifiyle başlayacaktır. Bu gerekli uzantıları etkinleştirecektir.

Daha sonra C benzeri sözdizimiyle filtreleme kuralları uygulanacaktır.

Filtre kuralları, postalardaki çeşitli özelliklerle eşleşebilir;

'Adres' eşleşmesi olan From/To adresleri, Konu başlıkları ve 'başlık' eşleşmesi olan özel başlıklar.

Maçın 'gövdesi' aşağıdaki gibi eylemleri içerecektir; dosyala, yönlendir, at, reddet… Eylemlerin ardından noktalı virgül gelir, bunu unutma. Not: Postayı bir posta kutusuna yerleştiren "dosyaya" eylemi için, dosyalama kuralında kullanılanla aynı adı taşıyan bir posta kutusu oluşturmanız gerekir. Aksi takdirde, eğer böyle bir posta kutusu mevcut değilse, postalar gelen kutunuza koyulacaktır.

Posta, dosya bitene kadar her kurala göre işlenmeye devam edecektir; bir postayla birçok bağımsız kural eşleşirse bu kuralların tümü posta üzerinde işlem gerçekleştirir. 'Durdur' eylemini kullanarak bir postanın işlenmesini sonlandırabilirsiniz.

Süzme kurallarının nasıl oluşturulacağını öğrenmek için lütfen aşağıdaki örnek komut dosyasına bakın. Ayrıca posta sunucusu hakkında genel bilgi ve diğer örnek eleme komut dosyalarına bağlantılar için posta hizmetleri sayfasına bakın. IMAP bayraklarını ayarlama, normal ifadelere göre filtreleme vb. gibi bazı gelişmiş şeyleri eleme ile kullanabilirsiniz.

Örnek Sieve Scripti

İşte kendi komut dosyanızı oluşturmak için kullanabileceğiniz örnek komut dosyası. Lütfen Sieve'in çalışmasını açıklayan yorumları da okuyunuz.

/*
   ============= Example sieve script ============
*/
##### We will 'require' necessary modules first.
# Comments can be C-style or bash/perl/python style
require [ "fileinto", "subaddress", "vacation" ];
##### Filter the spam into your spam folder. This is done 
# on the global sieve script by default IF you don't have 
# a .dovecot.sieve file.  When you create your sieve script,
# the global one will be disabled so you have to filter 
# the spam in your own script.
if header :is "X-Spam-Flag" "YES" {
    fileinto "spam";
    stop; #---- this stops further processing; 
    #prevents sending replies and/or redirecting(forwarding)
}
##### If you have forwarded your other e-mail accounts to
# department e-mail, you can filter them into their own folders.
# Note that arrays can be used with square brackets.
if address :is [ "to", "cc", "bcc" ] "myself@cmail.com" { 
    fileinto "forwarded-cmail"; 
    stop;
}
##### Logical operators equivalents;
#     OR:  anyof 
#     AND: allof
#     NOT: not
if anyof ( address :is "from" 
			  [ "gueststudent1@example.com", 
			    "gueststudent2@example.com" ] ,
           header :contains "subject" "CENG777" ) 
{
    fileinto "courses";
    stop;
}
##### Rule for 'plus addressing/address extension' like gmail filters.
# If you give "myaddr+shopping@ceng.metu.edu.tr" as e-mail to 
# shopping sites, the following will put all mail sent to that address
# into 'shoppingMania' mailbox. Remeber to create the mailbox itself before
# using this rule
if address :detail "to" "shopping" { fileinto "shoppingMania"; stop; }
##### Send some of my mail to my brother.
# ':matches' is used for wildcard matches;
#     *: zero or more characters
#     ?: a single character
# This example matches 'Summer vacation photos' ,
# and also 'Istanbul vacation photo'

if header :matches "subject" "* vacation photo?" {  
    redirect "mybrother@hisuniversity.edu.tr";
    stop;
}

# ALSO you can use 'redirect' action as an 'advanced .forward file'
# If you redirect to your other addresses after the spam filter, 
# and outside an 'if' block the spams will not be redirected 
# and will be delivered to your department spambox. All other
# mail will be forwarded to your other address. 
# This usage is recommended over .forward files

# redirect "myotheraddress@example.com";



##### My friend forwards some annoying things, discard those 'Fwd' things 
# but not her other messages, hence allof(logical AND) is used

if allof (address :contains "from" "nova777@cmail.com",
            header :contains "subject" "Fwd") {
    discard;
    stop;
}

##### A complex rule for matching various development lists.
# You can use two arrays in a rule, like the 'header' rule in the first line.
# 'exists' checks for existance of mail headers inserted by some web services.
# The array syntax means AND in 'exists' match, so check them seperately.
# The ':is' can be omitted if you want, as can be seen in 'address' match

if anyof (header :contains [ "List-Id" , "X-Trac-Project" ]
                [ "RoundCube" ,
                    "screen-users.gnu.org",
                    "pdf-devel.gnu.org",
                    "gentoo-dev.gentoo.org",
                    "prayer-announce.lists.cam.ac.uk"
               ] ,
          address "From" "bugzilla-daemon@gentoo.org" ,
          exists "X-Savane-Server",  
          exists "X-Launchpad-Bug", 
          exists "X-Debian-PR-Message" 
  ) 
{
    fileinto "developersTimesThree";
    stop;
}


##### Vacation autoresponder.
# If you are away for vacation, set something like this.
# Do not overuse this feature as it tends to get annoying, 
# and generates unnecessary mail trafic on many servers.

vacation
# Reply at most once a week to a same sender
  :days 7
  :subject "Gone fishing"
# List of recipient addresses which are included in the auto replying.
# If a mail's recipient is not on this list, no vacation reply is sent for it.
# this feature is used to prevent replies to mailing lists.
 :addresses ["name.surname@ceng.metu.edu.tr", "e1234567@ceng.metu.edu.tr"]
"Having a lovely fishing trip, You can reach me from my cell phone 
if the issue is urgent ( 0 5xx 123 45 67 )

Best regards

- Ali Veli";