Skip to content

Commit 3e521cb

Browse files
committed
fwd-only flag
1 parent 6e75b6e commit 3e521cb

File tree

11 files changed

+202
-6
lines changed

11 files changed

+202
-6
lines changed

bin/v-add-mail-account

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ echo $str >> $HOMEDIR/$user/conf/mail/$domain/passwd
6363
#----------------------------------------------------------#
6464

6565
str="ACCOUNT='$account' ALIAS='' QUOTA='$quota' AUTOREPLY='no' FWD=''"
66-
str="$str MD5='$md5' U_DISK='0' SUSPENDED='no' TIME='$TIME' DATE='$DATE'"
66+
str="$str FWD_ONLY='' MD5='$md5' U_DISK='0' SUSPENDED='no' TIME='$TIME'"
67+
str="$str DATE='$DATE'"
6768
echo "$str" >> $USER_DATA/mail/$domain.conf
6869
chmod 660 $USER_DATA/mail/$domain.conf
6970

bin/v-add-mail-account-fwd-only

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/bin/bash
2+
# info: add mail account forward-only flag
3+
# options: USER DOMAIN ACCOUNT
4+
#
5+
# The function adds fwd-only flag
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
user=$1
14+
domain=$(idn -t --quiet -u "$2" )
15+
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
16+
domain_idn=$(idn -t --quiet -a "$domain")
17+
account=$3
18+
19+
# Includes
20+
source $VESTA/func/main.sh
21+
source $VESTA/func/domain.sh
22+
source $VESTA/conf/vesta.conf
23+
24+
25+
#----------------------------------------------------------#
26+
# Verifications #
27+
#----------------------------------------------------------#
28+
29+
check_args '3' "$#" 'USER DOMAIN ACCOUNT'
30+
validate_format 'user' 'domain' 'account'
31+
is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
32+
is_object_valid 'user' 'USER' "$user"
33+
is_object_unsuspended 'user' 'USER' "$user"
34+
is_object_valid 'mail' 'DOMAIN' "$domain"
35+
is_object_unsuspended 'mail' 'DOMAIN' "$domain"
36+
is_object_valid "mail/$domain" 'ACCOUNT' "$account"
37+
is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account"
38+
fwd=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$FWD')
39+
if [ -z "$fwd" ]; then
40+
echo "Error: forward doesn't exist"
41+
log_event "$E_NOTEXIST $EVENT"
42+
exit $E_NOTEXIST
43+
fi
44+
45+
46+
#----------------------------------------------------------#
47+
# Action #
48+
#----------------------------------------------------------#
49+
50+
# Adding account to fwd_only
51+
touch $HOMEDIR/$user/conf/mail/$domain/fwd_only
52+
check_fwd=$(grep "^$account$" $HOMEDIR/$user/conf/mail/$domain/fwd_only)
53+
if [ -z "$check_fwd" ]; then
54+
echo "$account" > $HOMEDIR/$user/conf/mail/$domain/fwd_only
55+
fi
56+
57+
# Set ownership
58+
if [ "$MAIL_SYSTEM" = 'exim' ]; then
59+
mail_user=exim
60+
fi
61+
if [ "$MAIL_SYSTEM" = 'exim4' ]; then
62+
mail_user=Debian-exim
63+
fi
64+
chown -R $mail_user:mail $HOMEDIR/$user/conf/mail/$domain/fwd_only
65+
66+
67+
#----------------------------------------------------------#
68+
# Vesta #
69+
#----------------------------------------------------------#
70+
71+
# Updating config
72+
add_object_key "mail/$domain" 'ACCOUNT' "$account" 'FWD_ONLY' 'MD5'
73+
update_object_value "mail/$domain" 'ACCOUNT' "$account" '$FWD_ONLY' "yes"
74+
75+
# Logging
76+
log_history "added fwd_only flag for $account@$domain"
77+
log_event "$OK" "$EVENT"
78+
79+
exit

bin/v-delete-mail-account-fwd-only

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
# info: delete mail account forward-only flag
3+
# options: USER DOMAIN ACCOUNT
4+
#
5+
# The function deletes fwd-only flag
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
user=$1
14+
domain=$(idn -t --quiet -u "$2" )
15+
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
16+
domain_idn=$(idn -t --quiet -a "$domain")
17+
account=$3
18+
19+
# Includes
20+
source $VESTA/func/main.sh
21+
source $VESTA/func/domain.sh
22+
source $VESTA/conf/vesta.conf
23+
24+
25+
#----------------------------------------------------------#
26+
# Verifications #
27+
#----------------------------------------------------------#
28+
29+
check_args '3' "$#" 'USER DOMAIN ACCOUNT'
30+
validate_format 'user' 'domain' 'account'
31+
is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM'
32+
is_object_valid 'user' 'USER' "$user"
33+
is_object_unsuspended 'user' 'USER' "$user"
34+
is_object_valid 'mail' 'DOMAIN' "$domain"
35+
is_object_unsuspended 'mail' 'DOMAIN' "$domain"
36+
is_object_valid "mail/$domain" 'ACCOUNT' "$account"
37+
is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account"
38+
39+
40+
#----------------------------------------------------------#
41+
# Action #
42+
#----------------------------------------------------------#
43+
44+
# Deleting account from fwd_only
45+
sed -i "/^$account$/d" $HOMEDIR/$user/conf/mail/$domain/fwd_only
46+
47+
48+
#----------------------------------------------------------#
49+
# Vesta #
50+
#----------------------------------------------------------#
51+
52+
# Updating config
53+
update_object_value "mail/$domain" 'ACCOUNT' "$account" '$FWD_ONLY' ''
54+
55+
# Logging
56+
log_history "deleted fwd_only flag for $account@$domain"
57+
log_event "$OK" "$EVENT"
58+
59+
exit

bin/v-list-mail-account

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ is_object_valid "mail/$domain" 'ACCOUNT' "$account"
7575

7676
# Defining config and fields to select
7777
conf=$USER_DATA/mail/$domain.conf
78-
fields="\$ACCOUNT \$ALIAS \$FWD \$QUOTA \$AUTOREPLY \$U_DISK \$SUSPENDED"
79-
fields="$fields \$TIME \$DATE"
78+
fields="\$ACCOUNT \$ALIAS \$FWD \$FWD_ONLY \$QUOTA \$AUTOREPLY \$U_DISK"
79+
fields="$fields \$SUSPENDED \$TIME \$DATE"
8080

8181
# Listing domains
8282
case $format in

bin/v-list-mail-accounts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ is_object_valid 'mail' 'DOMAIN' "$domain"
3434

3535
# Defining fileds to select
3636
conf=$USER_DATA/mail/$domain.conf
37-
fields="\$ACCOUNT \$ALIAS \$FWD \$AUTOREPLY \$QUOTA \$U_DISK \$SUSPENDED"
38-
fields="$fields \$TIME \$DATE"
37+
fields="\$ACCOUNT \$ALIAS \$FWD \$FWD_ONLY \$QUOTA \$AUTOREPLY \$U_DISK"
38+
fields="$fields \$SUSPENDED \$TIME \$DATE"
3939

4040
# Listing domain accounts
4141
case $format in

func/main.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,17 @@ update_object_value() {
287287
$USER_DATA/$1.conf
288288
}
289289

290+
# Add object key
291+
add_object_key() {
292+
row=$(grep -n "$2='$3'" $USER_DATA/$1.conf)
293+
lnr=$(echo $row | cut -f 1 -d ':')
294+
object=$(echo $row | sed "s/^$lnr://")
295+
if [ -z "$(echo $object |grep $4=)" ]; then
296+
eval old="$4"
297+
sed -i "$lnr s/$5='/$4='' $5='/" $USER_DATA/$1.conf
298+
fi
299+
}
300+
290301
# Search objects
291302
search_objects() {
292303
OLD_IFS="$IFS"

func/rebuild.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,10 @@ rebuild_mail_domain_conf() {
435435
rm -f $HOMEDIR/$user/conf/mail/$domain/antivirus
436436
rm -f $HOMEDIR/$user/conf/mail/$domain/protection
437437
rm -f $HOMEDIR/$user/conf/mail/$domain/passwd
438+
rm -f $HOMEDIR/$user/conf/mail/$domain/fwd_only
438439
touch $HOMEDIR/$user/conf/mail/$domain/aliases
439440
touch $HOMEDIR/$user/conf/mail/$domain/passwd
441+
touch $HOMEDIR/$user/conf/mail/$domain/fwd_only
440442

441443
# Adding antispam protection
442444
if [ "$ANTISPAM" = 'yes' ]; then
@@ -519,6 +521,9 @@ rebuild_mail_domain_conf() {
519521
if [ ! -z "$FWD" ]; then
520522
echo "$account@$domain:$FWD" >> $dom_aliases
521523
fi
524+
if [ "$FWD_ONLY" = 'yes' ]; then
525+
echo "$account" >> $HOMEDIR/$user/conf/mail/$domain/fwd_only
526+
fi
522527
done
523528

524529
# Set permissions

web/add/mail/index.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,13 @@
130130
}
131131
unset($output);
132132
}
133+
// Add fwd_only flag
134+
if ((!empty($_POST['v_fwd_only'])) && (empty($_SESSION['error_msg']))) {
135+
exec (VESTA_CMD."v-add-mail-account-fwd-only ".$user." ".$v_domain." ".$v_account, $output, $return_var);
136+
check_return_code($return_var,$output);
137+
unset($output);
138+
}
133139
}
134-
unset($output);
135140

136141
if (empty($_SESSION['error_msg'])) {
137142
list($http_host, $port) = explode(':', $_SERVER["HTTP_HOST"].":");

web/edit/mail/index.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
$valiases = explode(",", $data[$v_account]['ALIAS']);
141141
$v_fwd = str_replace(',', "\n", $data[$v_account]['FWD']);
142142
$vfwd = explode(",", $data[$v_account]['FWD']);
143+
$v_fwd_only = $data[$v_account]['FWD_ONLY'];
143144
$v_quota = $data[$v_account]['QUOTA'];
144145
$v_autoreply = $data[$v_account]['AUTOREPLY'];
145146
if ( $v_autoreply == 'yes' ) {
@@ -234,6 +235,20 @@
234235
}
235236
}
236237

238+
// FWD_ONLY flag
239+
if (($v_fwd_only == 'yes') && (empty($_POST['v_fwd_only'])) && (empty($_SESSION['error_msg']))) {
240+
exec (VESTA_CMD."v-delete-mail-account-fwd-only ".$v_username." ".$v_domain." ".$v_account, $output, $return_var);
241+
check_return_code($return_var,$output);
242+
unset($output);
243+
$v_fwd_only = '';
244+
}
245+
if (($v_fwd_only != 'yes') && (!empty($_POST['v_fwd_only'])) && (empty($_SESSION['error_msg']))) {
246+
exec (VESTA_CMD."v-add-mail-account-fwd-only ".$v_username." ".$v_domain." ".$v_account, $output, $return_var);
247+
check_return_code($return_var,$output);
248+
unset($output);
249+
$v_fwd_only = 'yes';
250+
}
251+
237252
// Autoreply
238253
if (($v_autoreply == 'yes') && (empty($_POST['v_autoreply'])) && (empty($_SESSION['error_msg']))) {
239254
exec (VESTA_CMD."v-delete-mail-account-autoreply ".$v_username." ".$v_domain." ".$v_account, $output, $return_var);

web/templates/admin/add_mail_acc.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,17 @@
127127
<textarea size="20" class="vst-textinput" name="v_fwd"><?php if (!empty($v_fwd)) echo $v_fwd; ?></textarea>
128128
</td>
129129
</tr>
130+
<tr>
131+
<td class="vst-text" style="padding: 10 0 0 2px;">
132+
<?php print __("Don't store forwarded mail");?>
133+
</td>
134+
</tr>
135+
<tr>
136+
<td>
137+
<input type="checkbox" size="20" class="vst-checkbox" name="v_fwd_only" <?php if ($v_fwd_only == 'yes') echo "checked=yes" ?>>
138+
</td>
139+
</tr>
140+
130141
</table>
131142
</td>
132143
</tr>

0 commit comments

Comments
 (0)