New applet: sendmail
Denys Vlasenko
vda.linux at googlemail.com
Wed Jan 9 21:59:54 UTC 2008
On Tuesday 08 January 2008 12:49, Vladimir Dronnikov wrote:
> Hi, Denis!
>
> I personally have always been missing mail client applet in BB.
> Attached is a draft attempt to fix this.
Cool.
> Please, take a look
/*
These should imho be moved to bb library
*/
enum {
SRC_BUF_SIZE = 45, /* This *MUST* be a multiple of 3 */
DST_BUF_SIZE = 4 * ((SRC_BUF_SIZE + 2) / 3),
};
static void uuencode(char *fname, int src_fd)
I guess you looked at reusing existing uuen/decode,
but there are problems in doing that. What are they?
/*
<<<< 220 local <1199329409.14351 at local> [XMail 1.24 ESMTP Server] service ready; Thu, 3 Jan 2008 03:03:29 -0000
>>>> HELO ahost
<<<< 250 local
>>>> MAIL FROM:<root at ahost>
<<<< 250 OK
>>>> RCPT TO:<admin at local>
<<<< 250 OK
>>>> DATA
<<<< 354 Start mail input; end with <CRLF>.<CRLF>
<<<< 250 OK <S3>
>>>> QUIT
<<<< 221 [XMail 1.24 ESMTP Server] service closing transmission channel
*/
A few of above lines have DOS line ending (extra Ctrl-M).
static const char *STDERRS[] = {
"220 ", "250 ", "354 ", "221 ", NULL
};
You need const char *const STDERRS[], or even better,
const char STDERRS[] = "220 \0" "250 \0"... ;
- it is *the* most compact string table representation.
You can scan such string table using index_in_strings()
(see examples in code).
static int chat(char *cmd, const char *answers[])
{
int n;
char *answer = NULL;
// send command
if (cmd && *cmd) {
printf(cmd);
}
// shall we wait for an answer?
if (!answers) return 0; // ... no! just return ok
Never happens (you always pass non-NULL answers).
char *boundary = xasprintf("%d-%d-%d", rand(), rand(), rand());
Does it give different result? manpage says you need to use srand()
to seed the generator...
/* XMAIL should dump output as follows...
FILE=`date +%s`-$RANDOM.$$.`hostname`
mail "$@" | sed 's/$/^M/' >/var/MailRoot/spool/temp/$FILE
mv -f /var/MailRoot/spool/temp/$FILE /var/MailRoot/spool/local
*/
That ^M above is a literal Ctrl-M - !?
--
vda
More information about the busybox
mailing list