# J. Thomsen 2002-04-11 Postfix utility # /usr/local/bin/virtual.awk # # Used by Postfix for delivering mail to a GNU-pop3d virtual domain # mailbox. # # Postfix will use this utility for delivering a message to the local # mailbox rewriting the Delivered-To header line to the original recipient # address. # # 2002-04-11 Fix 'From ' lines in msg body and add empty line to msgs to ensure # the separation of messages # # LOCAL@DOMAIN, LOCAL = USER+EXTENSION # BEGIN { DT = 0; LIN = 0; PF = ""; fil = "Mail/mailbox"; R = ENVIRON["EXTENSION"]; sub("--", "@", R); # user--virtual.domain -> user@virtual.domain if (R == "") DT = 1; # something wrong, don't modify else { split(R, a1, "@"); usr = a1[1]; n = split(a1[2], a2, "."); if (n > 2) { dom = a2[n-1] "." a2[n]; } else dom = a1[2]; fil = "/var/spool/virtual/" tolower(dom) "/" tolower(usr) } } { if (DT == 0) { # Delivered-To not found yet if (index(toupper($1), "DELIVERED-TO") != 0) { # Delivered-To:domain_com+userid--domain.com DT = 1; print $1": "R >>fil; # print modified Delivered-To:userid@domain.com next; } } } /^From .*$/ {if (LIN > 0) {PF = ">" }} # Escape "From " lines in body {print PF $0 >>fil; PF = ""; LIN = LIN + 1} # Print all other lines END { print "" >>fil; }