summaryrefslogtreecommitdiff
path: root/fml/lib/FML/MTA/Control/Qmail.pm
blob: 05368170c1e9fe97305ecbcfcf47f11c1be73490 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#-*- perl -*-
#
#  Copyright (C) 2002,2003,2004,2005,2006 Ken'ichi Fukamachi
#   All rights reserved. This program is free software; you can
#   redistribute it and/or modify it under the same terms as Perl itself.
#
# $FML: Qmail.pm,v 1.8 2006/02/04 08:10:08 fukachan Exp $
#

package FML::MTA::Control::Qmail;
use strict;
use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD);
use Carp;

my $debug = 0;


=head1 NAME

FML::MTA::Control::Qmail - handle qmail specific configurations.

=head1 SYNOPSIS

set up aliases and virtual maps for qmail.

=head1 DESCRIPTION

=head1 METHODS

=cut


# Descriptions: udummy. qmail not needs installation of alias files.
#    Arguments: OBJ($self) OBJ($curproc) HASH_REF($params) HASH_REF($optargs)
# Side Effects: update aliases
# Return Value: none
sub qmail_install_alias
{
    my ($self, $curproc, $params, $optargs) = @_;
    my $config       = $curproc->config();
    my $template_dir = $curproc->newml_command_template_files_dir();
    my $ml_home_dir  = $params->{ ml_home_dir };

    use File::Spec;

    my $qmail_template_files =
	$config->get_as_array_ref('newml_command_qmail_template_files');
    my $fml_owner_home_dir = $config->{ fml_owner_home_dir };
    my $ml_name   = $config->{ ml_name };
    my $ml_domain = $config->{ ml_domain }; $ml_domain =~ s/\./:/g;
    for my $file (@$qmail_template_files) {
	# XXX-TODO: we should define dot-qmail file name generator as method.
	my $xfile = $file;
	$xfile =~ s/dot-/\./;
	$xfile =~ s/dot-/\./;
	$xfile =~ s/qmail/qmail-$ml_domain-$ml_name/;

	my $src   = File::Spec->catfile($template_dir, $file);
	my $dst   = File::Spec->catfile($fml_owner_home_dir, $xfile);

	$curproc->ui_message("creating $dst");
	$self->_install($src, $dst, $params);
    }

    my $virtual_domain_conf = $config->{ qmail_virtualdomains_file };
    unless (-f $virtual_domain_conf) {
	if (0) {
	    $curproc->ui_message("  XXX We assume $ml_domain:fml-$ml_domain");
	    $curproc->ui_message("  XXX in $virtual_domain_conf");
	}
    }
}


# Descriptions: remove .qmail-$ml* files (remove aliases).
#    Arguments: OBJ($self) OBJ($curproc) HASH_REF($params) HASH_REF($optargs)
# Side Effects: update aliases
# Return Value: none
sub qmail_delete_alias
{
    my ($self, $curproc, $params, $optargs) = @_;
    my $config       = $curproc->config();
    my $template_dir = $curproc->newml_command_template_files_dir();
    my $ml_home_dir  = $params->{ ml_home_dir };

    use File::Spec;

    my $qmail_template_files =
	$config->get_as_array_ref('newml_command_qmail_template_files');
    my $fml_owner_home_dir = $config->{ fml_owner_home_dir };
    my $ml_name   = $config->{ ml_name };
    my $ml_domain = $config->{ ml_domain }; $ml_domain =~ s/\./:/g;
    for my $file (@$qmail_template_files) {
	my $xfile = $file;
	$xfile =~ s/dot-/\./;
	$xfile =~ s/dot-/\./;
	$xfile =~ s/qmail/qmail-$ml_domain-$ml_name/;

	my $src   = File::Spec->catfile($template_dir, $file);
	my $dst   = File::Spec->catfile($fml_owner_home_dir, $xfile);

	if (-f $dst) {
	    $curproc->ui_message("removing $dst");
	    unlink $dst || do {
		my $s = "failed to remove $dst";
		$curproc->ui_message("error: $s");
		$curproc->logerror($s);
	    };
	}
    }
}


# Descriptions: dummy (update alias).
#    Arguments: OBJ($self) OBJ($curproc) HASH_REF($params) HASH_REF($optargs)
# Side Effects: update aliases
# Return Value: none
sub qmail_update_alias
{
    my ($self, $curproc, $params, $optargs) = @_;

    0;
}


# Descriptions: dummy (find key in aliases).
#    Arguments: OBJ($self) OBJ($curproc) HASH_REF($params) HASH_REF($optargs)
# Side Effects: none
# Return Value: NUM(1 or 0)
sub qmail_find_key_in_alias_maps
{
    my ($self, $curproc, $params, $optargs) = @_;

    # XXX-TODO: implement this!
    0;
}


# Descriptions: get { key => value } in aliases.
#    Arguments: OBJ($self) OBJ($curproc) HASH_REF($params) HASH_REF($optargs)
# Side Effects: none
# Return Value: HASH_REF
sub qmail_get_aliases_as_hash_ref
{
    my ($self, $curproc, $params, $optargs) = @_;

    # XXX-TODO: implement this!
    0;
}


# Descriptions: return alias_maps as ARRAY_REF.
#    Arguments: OBJ($self) OBJ($curproc) HASH_REF($params) HASH_REF($optargs)
# Side Effects: none
# Return Value: ARRAY_REF
sub qmail_alias_maps
{
    my ($self, $curproc, $params, $optargs) = @_;

    # XXX-TODO: implement this!
    0;
}


# Descriptions: create ~/.qmail-* files.
#    Arguments: OBJ($self) OBJ($curproc) HASH_REF($params) HASH_REF($optargs)
# Side Effects: creates ~/.qmail-XXX
# Return Value: none
sub qmail_setup
{
    my ($self, $curproc, $params, $optargs) = @_;

    0;
}


# Descriptions: prepare a template for qmail/control/virtualdomains
#               for example: rule of a virtual domain for "nuinui.net"
#                            nuinui.net:fml-.nuinui.net
#    Arguments: OBJ($self) OBJ($curproc) HASH_REF($params)
#         bugs: we cannot update /var/qmail/control/virtualdomains
#               since it needs root priviledge.
#               So, we can only update our templates for qmail.
# Side Effects: update template not /var/qmail/control/virtualdomains
# Return Value: none
sub qmail_install_virtual_map
{
    my ($self, $curproc, $params) = @_;
    my $fmlowner  = $curproc->fml_owner();
    my $config    = $curproc->config();
    my $ml_domain = $config->{ ml_domain };
    my $virtual   = $config->{ qmail_virtual_map_file };

    # 1. check the current template file firstly
    my $found = 0;
    my $fh    = new FileHandle $virtual;
    if (defined $fh) {
	my $buf;

      LINE:
	while ($buf = <$fh>) {
	    $found = 1 if $buf =~ /^$ml_domain:/i;
	    last LINE  if $found;
	}
	$fh->close();
    }

    # 2. if not found
    unless ($found) {
	$curproc->ui_message("updating $virtual");

	my $fh = new FileHandle ">> $virtual";
	if (defined $fh) {
	    print $fh "$ml_domain:$fmlowner-$ml_domain\n";
	    $fh->close();
	}
    }
    else {
	$curproc->ui_message("skip updating $virtual");
    }
}


# Descriptions: dummy.
#    Arguments: OBJ($self) HASH_REF($args)
# Side Effects: none
# Return Value: none
sub qmail_delete_virtual_map
{
    0;
}


# Descriptions: dummy.
#    Arguments: OBJ($self) HASH_REF($args)
# Side Effects: none
# Return Value: none
sub qmail_update_virtual_map
{
    0;
}


=head1 CODING STYLE

See C<http://www.fml.org/software/FNF/> on fml coding style guide.

=head1 AUTHOR

Ken'ichi Fukamachi

=head1 COPYRIGHT

Copyright (C) 2002,2003,2004,2005,2006 Ken'ichi Fukamachi

All rights reserved. This program is free software; you can
redistribute it and/or modify it under the same terms as Perl itself.

=head1 HISTORY

FML::MTA::Control first appeared in fml8 mailing list driver package.
See C<http://www.fml.org/> for more details.

=cut


1;