Commit 203c6eb3 203c6eb363274b8463ff114b3e382952a2cff8b7 by Alain Magloire

supporting CC BCC when mailing.

1 parent ad9f147e
......@@ -47,8 +47,7 @@ extern void mailer_destroy __P ((mailer_t *));
extern int mailer_open __P ((mailer_t, int flags));
extern int mailer_close __P ((mailer_t));
extern int mailer_send_message __P ((mailer_t, const char *from,
const char *rcpt, int dsn, message_t));
extern int mailer_send_message __P ((mailer_t, message_t));
/* stream settings */
extern int mailer_get_stream __P ((mailer_t, stream_t *));
extern int mailer_set_stream __P ((mailer_t, stream_t));
......
......@@ -50,6 +50,9 @@ extern int message_create __P ((message_t *, void *owner));
extern void message_destroy __P ((message_t *, void *owner));
extern void * message_get_owner __P ((message_t));
extern int message_ref __P ((message_t));
#define message_unref(msg) message_destroy (&msg)
extern int message_get_header __P ((message_t, header_t *));
extern int message_set_header __P ((message_t, header_t, void *owner));
......
......@@ -74,8 +74,7 @@ struct _mailer
void (*_destroy) __P ((mailer_t));
int (*_open) __P ((mailer_t, int flags));
int (*_close) __P ((mailer_t));
int (*_send_message) __P ((mailer_t, const char *from, const char *rcpt,
int dsn, message_t));
int (*_send_message) __P ((mailer_t, message_t));
};
/* Mail locks. */
......
......@@ -52,6 +52,9 @@ struct _message
mime_t mime;
observable_t observable;
/* Reference count. */
int ref;
/* Holder for message_write. */
char *hdr_buf;
size_t hdr_buflen;
......
......@@ -156,12 +156,11 @@ mailer_close (mailer_t mailer)
/* messages */
int
mailer_send_message (mailer_t mailer, const char *from, const char *rcpt,
int dsn, message_t msg)
mailer_send_message (mailer_t mailer, message_t msg)
{
if (mailer == NULL || mailer->_send_message == NULL)
return ENOSYS;
return mailer->_send_message (mailer, from, rcpt, dsn, msg);
return mailer->_send_message (mailer, msg);
}
int
......
......@@ -50,6 +50,7 @@ message_create (message_t *pmsg, void *owner)
if (msg == NULL)
return ENOMEM;
msg->owner = owner;
msg->ref = 1;
*pmsg = msg;
return 0;
}
......@@ -61,6 +62,7 @@ message_destroy (message_t *pmsg, void *owner)
{
message_t msg = *pmsg;
msg->ref--;
if (msg->owner == owner)
{
/* Notify the listeners. */
......@@ -91,6 +93,7 @@ message_destroy (message_t *pmsg, void *owner)
if (msg->mime)
mime_destroy (&(msg->mime));
if (msg->ref <= 0)
free (msg);
}
/* Loose the link */
......@@ -98,6 +101,14 @@ message_destroy (message_t *pmsg, void *owner)
}
}
int
message_ref (message_t msg)
{
if (msg)
msg->ref++;
return 0;
}
void *
message_get_owner (message_t msg)
{
......@@ -132,7 +143,7 @@ message_set_header (message_t msg, header_t hdr, void *owner)
return EACCES;
/* Make sure we destoy the old if it was own by the mesg */
/* FIXME: I do not know if somebody has already a ref on this ? */
/* header_destroy (&(msg->header), msg); */
header_destroy (&(msg->header), msg);
msg->header = hdr;
return 0;
}
......@@ -165,7 +176,7 @@ message_set_body (message_t msg, body_t body, void *owner)
return EACCES;
/* Make sure we destoy the old if it was own by the mesg. */
/* FIXME: I do not know if somebody has already a ref on this ? */
/* body_destroy (&(msg->body), msg); */
body_destroy (&(msg->body), msg);
msg->body = body;
return 0;
}
......@@ -177,6 +188,9 @@ message_set_stream (message_t msg, stream_t stream, void *owner)
return EINVAL;
if (msg->owner != owner)
return EACCES;
/* Make sure we destoy the old if it was own by the mesg. */
/* FIXME: I do not know if somebody has already a ref on this ? */
stream_destroy (&(msg->stream), msg);
msg->stream = stream;
return 0;
}
......
......@@ -72,8 +72,7 @@ typedef struct _sendmail * sendmail_t;
static void sendmail_destroy (mailer_t);
static int sendmail_open (mailer_t, int);
static int sendmail_close (mailer_t);
static int sendmail_send_message (mailer_t, const char *from, const char *rcpt,
int dsn, message_t);
static int sendmail_send_message (mailer_t, message_t);
int
sendmail_init (mailer_t mailer)
......@@ -148,8 +147,7 @@ sendmail_close (mailer_t mailer)
}
static int
sendmail_send_message (mailer_t mailer, const char *from, const char *rcpt,
int dsn, message_t msg)
sendmail_send_message (mailer_t mailer, message_t msg)
{
sendmail_t sendmail = mailer->data;
int status = 0;
......@@ -157,8 +155,6 @@ sendmail_send_message (mailer_t mailer, const char *from, const char *rcpt,
if (sendmail == NULL || msg == NULL)
return EINVAL;
sendmail->dsn = dsn;
switch (sendmail->state)
{
case SENDMAIL_NO_STATE:
......@@ -173,45 +169,6 @@ sendmail_send_message (mailer_t mailer, const char *from, const char *rcpt,
argvec[1] = strdup ("-oi");
argvec[2] = strdup ("-t");
if (from)
{
size_t len = strlen (from) + 1;
char *addr = calloc (len, sizeof (char));
if (parseaddr (from, addr, len) == 0)
{
argc++;
argvec = realloc (argvec, argc * (sizeof (*argvec)));
argvec[argc - 1] = strdup ("-f");
argc++;
argvec = realloc (argvec, argc * (sizeof (*argvec)));
argvec[argc - 1] = addr;
}
else
free (addr);
}
if (rcpt)
{
const char *p = rcpt;
do
{
size_t len = strlen (p) + 1;
char *addr = calloc (len, sizeof (char));
if (parseaddr (rcpt, addr, len) == 0)
{
argc++;
argvec = realloc (argvec, argc * (sizeof (*argvec)));
argvec[argc - 1] = addr;
}
else
free (addr);
p = strchr (p, ',');
if (p != NULL)
p++;
}
while (p != NULL && *p != '\0');
}
argc++;
argvec = realloc (argvec, argc * (sizeof (*argvec)));
argvec[argc - 1] = NULL;
......