| 1 | submodule "/pliant/storage/database.pli" | |
| 2 | module "/pliant/fullpliant/this_computer.pli" | |
| 3 | ||
| 4 | public | |
| 5 | ||
| 6 | type MailBox | |
| 7 | field Str name | |
| 8 | field Str abstract | |
| 9 | field Str computer | |
| 10 | field Str auto_answer | |
| 11 | field Str path | |
| 12 | field Bool archive <- true | |
| 13 | field Str smtp_ip | |
| 14 | field Char pop3_level <- "0" # 0 no, 1 tigger, 2 read, 3 read and remove | |
| 15 | field Str pop3_ip | |
| 16 | field Str pop3_password_md5 | |
| 17 | field Str relay_computer | |
| 18 | field Bool relay_archive <- false | |
| 19 | field Bool list <- false | |
| 20 | field Set:Str subscriber | |
| 21 | field Bool check_ip <- true | |
| 22 | field Bool check_from <- true | |
| 23 | field Bool check_to <- true | |
| 24 | field Set:Void accept_from # receiving will be allowed, even with a missing 'to' if 'from' is one of these | |
| 25 | field Str options | |
| 26 | ||
| 27 | type MailRedirect | |
| 28 | field Str pop3_server | |
| 29 | field Str user | |
| 30 | field Str smtp_server | |
| 31 | field Str mailbox | |
| 32 | field Str error | |
| 33 | ||
| 34 | type MailDatabase | |
| 35 | field Set:MailBox box | |
| 36 | field Set:Void black_dns # black list domains | |
| 37 | field Set:Void black_ip # blacklisted SMTP servers IPs | |
| 38 | field Set:Void black_name # blacklisted SMTP servers names | |
| 39 | field Set:Void black_from # blacklisted boxes or domains | |
| 40 | field Set:Void magic_ip # always allowed SMTP servers IPs | |
| 41 | field Set:Void magic_name # always allowed SMTP servers names | |
| 42 | field Set:Void magic_from # allways allowed boxes or domains | |
| 43 | field Set:MailRedirect redirect | |
| 44 | ||
| 45 | type MailBoxSecret | |
| 46 | field Str pop3_password_md5 | |
| 47 | ||
| 48 | type MailSecretDatabase | |
| 49 | field Set:MailBoxSecret box | |
| 50 | ||
| 51 | (gvar Database:MailDatabase mail_database) load "security:/mail.pdb" log "security:/mail.log" mount "/pliant/mail" | |
| 52 | gvar (Data Set:MailBox) mailbox :> mail_database:data:box | |
| 53 | (gvar Database:MailSecretDatabase mail_secret_database) load "security:/mail_secret.pdb" | |
| 54 | ||
| 55 | function migrate | |
| 56 | each b mailbox | |
| 57 | if b:pop3_password_md5<>"" | |
| 58 | if not exists:(mail_secret_database:data:box keyof:b) | |
| 59 | mail_secret_database:data:box create keyof:b | |
| 60 | mail_secret_database:data:box:(keyof b) pop3_password_md5 := b pop3_password_md5 | |
| 61 | b pop3_password_md5 := "" | |
| 62 | migrate | |
| 63 | ||
| 64 | method mb smart_path area -> p | |
| 65 | arg Data:MailBox mb ; arg Str area ; arg Str p | |
| 66 | if mb:path<>"" | |
| 67 | p := mb:path+area+"/" | |
| 68 | else | |
| 69 | if not (keyof:mb parse any:(var Str id) "@" any:(var Str domain)) | |
| 70 | id := keyof mb ; domain := "unknown" | |
| 71 | p := this_computer:env:"pliant":"mail":"path" | |
| 72 | if p="" | |
| 73 | p := "data:/pliant/mail/" | |
| 74 | p += domain+"/"+id+"/"+(shunt area<>"" area+"/" "") | |
| 75 | ||
| 76 | method mb in_path -> p | |
| 77 | arg Data:MailBox mb ; arg Str p | |
| 78 | p := mb smart_path "in" | |
| 79 | ||
| 80 | method mb unknown_path -> p | |
| 81 | arg Data:MailBox mb ; arg Str p | |
| 82 | p := mb smart_path "unknown" | |
| 83 | ||
| 84 | method mb spam_path -> p | |
| 85 | arg Data:MailBox mb ; arg Str p | |
| 86 | p := mb smart_path "spam" | |
| 87 | ||
| 88 | method mb out_path -> p | |
| 89 | arg Data:MailBox mb ; arg Str p | |
| 90 | p := mb smart_path "out" | |
| 91 | ||
| 92 | method mb archive_path -> p | |
| 93 | arg Data:MailBox mb ; arg Str p | |
| 94 | p := mb smart_path "archive" | |
| 95 | ||
| 96 | method mb area_path -> p | |
| 97 | arg Data:MailBox mb ; arg Str p | |
| 98 | p := mb smart_path "area" | |
| 99 | ||
| 100 | method mb relay_path -> p | |
| 101 | arg Data:MailBox mb ; arg Str p | |
| 102 | p := mb smart_path "out" | |