File: send-mail

package info (click to toggle)
coldsync 3.0%2Bpre3-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,188 kB
  • ctags: 2,033
  • sloc: ansic: 20,386; perl: 2,302; cpp: 1,640; yacc: 1,102; lex: 802; makefile: 533; sh: 177
file content (175 lines) | stat: -rwxr-xr-x 4,334 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/perl
#
# ColdSync Mail conduit
#
# $Id: send-mail,v 1.9 2001/11/13 13:51:00 arensb Exp $
#
use strict;
use Palm::Mail;
use ColdSync;
use Text::Wrap;

# Default values for headers
%HEADERS = (
	# XXX - This ought to be determined at configure-time
	"Sendmail"	=> "/usr/sbin/sendmail",
	"My-Address"	=> (getpwuid($>))[0],
	"Wrap"		=> 74,
	"Outbox-name"	=> "Outbox",	# Name of category for outgoing mail

	"Paragraph"	=> "",		# Paragraph indent
	"Line-Indent"	=> "",		# Line indentation
);

my $VERSION = (qw( $Revision: 1.9 $ ))[1];	# Conduit version

# print_header
# Print a valid mail header. Headers with empty values are ignored.
# Newlines are replaced with newline-whitespace, per RFC822.
sub print_header
{
	my $header_name = shift;
	my $header_content = shift;

	if (!defined($header_content) || ($header_content eq ""))
	{
		# Empty header
		return;
	}

	$header_content =~ s/\n(?!\s)/\n\t/mg;
	print SENDMAIL "$header_name: $header_content\n";
}

StartConduit("dump");

$Text::Wrap::columns = $HEADERS{Wrap};
my $record;
foreach $record (@{$PDB->{records}})
{
	# Skip everything except the Outbox folder
	next unless $PDB->{appinfo}{categories}[$record->{category}]{name}
		eq $HEADERS{"Outbox-name"};

	my $whoami = $HEADERS{"My-Address"};
	my @sm_args;		# Sendmail command-line arguments

	@sm_args = ("-t", "-i");	# -t: get addressee from the
					# body of the message
					# -i: ignore lines consisting of
					# a single dot.
	if ($record->{confirm_delivery})
	{
		push @sm_args, "-N", "success,failure";
	}

	open SENDMAIL, "| $HEADERS{Sendmail} @sm_args" or
		die "502 Can't run $HEADERS{Sendmail}: $!\n";
	select SENDMAIL;

	# Print header fields so that they conform to RFC822 (a continuation
	# line must start with a whitespace or tab character).
	&print_header("From", $whoami);
	&print_header("To", $record->{"to"});
	&print_header("Cc", $record->{"cc"});
	&print_header("Bcc", $record->{bcc});
	&print_header("Reply-To", $record->{reply_to})
	&print_header("X-Sent-To", $record->{send_to});
	&print_header("X-Mailer",
	    "$HEADERS{Daemon} $HEADERS{Version}/send-mail conduit $VERSION");
	&print_header("Subject", $record->{subject});

	my $body = $record->{body};

	$body .= "\n" if $body !~ /\n$/m;	# Make sure message ends in \n

	# Wrap the text if requested
	$body = wrap($HEADERS{"Paragraph"}, $HEADERS{"Line-Indent"},
			$record->{body})
		if $HEADERS{Wrap} > 0;

	print "\n", $body;

	select STDOUT;
	close SENDMAIL;

	$PDB->delete_Record($record, 1);
}

$PDB->Write($HEADERS{OutputDB} || $HEADERS{InputDB});

EndConduit;

__END__

=head1 NAME

send-mail - ColdSync conduit to send Palm mail

=head1 SYNOPSIS

    conduit dump {
        type: mail/DATA;
        path: "<...>/send-mail";
      arguments:
        Sendmail:	/path/to/sendmail;
        My-Address:	user@my.dom.ain;
        Outbox-name:	Outbox;
    }

=head1 DESCRIPTION

The C<send-mail> conduit reads the Palm Mail database, finds the
outgoing messages, and passes them on to C<sendmail> for further
processing.

Once each message has been successfully passed along to C<sendmail>,
it is deleted.

=head1 OPTIONS

=over 4

=item C<Sendmail>

Specifies the path to the C<sendmail> executable. The default is
F</usr/sbin/sendmail>.

=item C<My-Address>

Specifies the return address to put on outgoing messages. If omitted,
defaults to your username (or, more precisely, the username of the
first user with your uid).

=item C<Wrap>

Specifies the column at which to wrap long lines. Defaults to 74. A
value of 0 specifies that text should not be wrapped.

=item C<Outbox-name>

Specifies the category where outgoing messages are stored.
If omitted, the default F<Outbox> is used. For German use F<Ausgang>.

=head1 BUGS

Messages that were successfully sent are not immediately deleted on
the Palm, but remain until the next sync. This is a limitation of
ColdSync's conduit model.

The ``Confirm Read'' flag, as well as the various conduit-related
options on the Palm, are ignored.

The ``Signature'' option on the Palm is ignored; this will most likely
not be fixed. Nor is there an option to include a F<.signature> file
on the desktop machine; this will most likely be fixed.

=head1 AUTHOR

Andrew Arensburger E<lt>arensb@ooblick.comE<gt>

=head1 SEE ALSO

coldsync(8)

F<ColdSync Conduits>, in the ColdSync documentation.