Change the message arg to a CamelMimeMessage instead of a CamelMedium.

* camel-transport.c (camel_transport_send_to): Change the message
	arg to a CamelMimeMessage instead of a CamelMedium. Even the NNTP
	provider returns CamelMimeMessages, and we're never going to
	support anything more exotic than that. Also do a few more
	g_return_if_fails here instead of in the providers.
	(camel_transport_can_send): No longer needed.
	(camel_transport_send): Remove this too. It wasn't being used any
	more, and it doesn't behave exactly the same in sendmail and smtp.

	* providers/smtp/camel-smtp-transport.c (smtp_send,
	smtp_can_send): Gone.
	(smtp_send_to): Update for arg change.
	(smtp_data): Make this take a CamelMimeMessage too.

	* providers/sendmail/camel-sendmail-transport.c (sendmail_send,
	sendmail_can_send): Gone.
	(sendmail_send_to): Update for arg change, and merge in the part
	that used to be shared with sendmail_send.

svn path=/trunk/; revision=16278
This commit is contained in:
Dan Winship
2002-03-28 23:20:09 +00:00
parent f272428252
commit 93c35349cf
5 changed files with 73 additions and 195 deletions

View File

@ -1,3 +1,24 @@
2002-03-28 Dan Winship <danw@ximian.com>
* camel-transport.c (camel_transport_send_to): Change the message
arg to a CamelMimeMessage instead of a CamelMedium. Even the NNTP
provider returns CamelMimeMessages, and we're never going to
support anything more exotic than that. Also do a few more
g_return_if_fails here instead of in the providers.
(camel_transport_can_send): No longer needed.
(camel_transport_send): Remove this too. It wasn't being used any
more, and it doesn't behave exactly the same in sendmail and smtp.
* providers/smtp/camel-smtp-transport.c (smtp_send,
smtp_can_send): Gone.
(smtp_send_to): Update for arg change.
(smtp_data): Make this take a CamelMimeMessage too.
* providers/sendmail/camel-sendmail-transport.c (sendmail_send,
sendmail_can_send): Gone.
(sendmail_send_to): Update for arg change, and merge in the part
that used to be shared with sendmail_send.
2002-03-27 Jeffrey Stedfast <fejj@ximian.com>
* camel-filter-driver.c (camel_filter_driver_filter_folder):

View File

@ -28,7 +28,8 @@
#endif
#include "camel-transport.h"
#include "camel-exception.h"
#include "camel-address.h"
#include "camel-mime-message.h"
#include "camel-private.h"
/* Returns the class for a CamelTransport */
@ -77,68 +78,30 @@ camel_transport_get_type (void)
/**
* camel_transport_can_send: Determine if a message is send-able on a transport
* @transport: the transport
* @message: the message
*
* Determines if a CamelMedium is of an appropriate subclass to send
* via the given @transport. (Mail transports are not able to send
* netnews articles, and vice versa.)
*
* Return value: TRUE or FALSE
**/
gboolean
camel_transport_can_send (CamelTransport *transport, CamelMedium *message)
{
return CT_CLASS (transport)->can_send (transport, message);
}
/**
* camel_transport_send: Send a message via a transport
* @transport: the transport
* @message: the message
* @ex: a CamelException
*
* Sends the message to the recipients indicated in the message.
*
* Return value: success or failure.
**/
gboolean
camel_transport_send (CamelTransport *transport, CamelMedium *message,
CamelException *ex)
{
gboolean sent;
g_return_val_if_fail (CAMEL_IS_TRANSPORT (transport), FALSE);
CAMEL_TRANSPORT_LOCK (transport, send_lock);
sent = CT_CLASS (transport)->send (transport, message, ex);
CAMEL_TRANSPORT_UNLOCK (transport, send_lock);
return sent;
}
/**
* camel_transport_send_to: Send a message non-standard recipients
* camel_transport_send_to:
* @transport: the transport
* @message: the message
* @from: from address
* @recipients: the recipients
* @ex: a CamelException
*
* Sends the message to the given recipients, rather than to the
* recipients indicated in the message.
* Sends the message to the given recipients, regardless of the contents
* of @message. If the message contains a "Bcc" header, the transport
* is responsible for stripping it.
*
* Return value: success or failure.
**/
gboolean
camel_transport_send_to (CamelTransport *transport, CamelMedium *message,
camel_transport_send_to (CamelTransport *transport, CamelMimeMessage *message,
CamelAddress *from, CamelAddress *recipients,
CamelException *ex)
{
gboolean sent;
g_return_val_if_fail (CAMEL_IS_TRANSPORT (transport), FALSE);
g_return_val_if_fail (CAMEL_IS_MIME_MESSAGE (message), FALSE);
g_return_val_if_fail (CAMEL_IS_ADDRESS (from), FALSE);
g_return_val_if_fail (CAMEL_IS_ADDRESS (recipients), FALSE);
CAMEL_TRANSPORT_LOCK (transport, send_lock);
sent = CT_CLASS (transport)->send_to (transport, message,

View File

@ -54,25 +54,16 @@ struct _CamelTransport
typedef struct {
CamelServiceClass parent_class;
gboolean (*can_send) (CamelTransport *transport, CamelMedium *message);
gboolean (*send) (CamelTransport *transport, CamelMedium *message,
CamelException *ex);
gboolean (*send_to) (CamelTransport *transport, CamelMedium *message,
gboolean (*send_to) (CamelTransport *transport,
CamelMimeMessage *message,
CamelAddress *from, CamelAddress *recipients,
CamelException *ex);
} CamelTransportClass;
/* public methods */
gboolean camel_transport_can_send (CamelTransport *transport,
CamelMedium *message);
gboolean camel_transport_send (CamelTransport *transport,
CamelMedium *message,
CamelException *ex);
gboolean camel_transport_send_to (CamelTransport *transport,
CamelMedium *message,
CamelMimeMessage *message,
CamelAddress *from,
CamelAddress *recipients,
CamelException *ex);

View File

@ -41,10 +41,8 @@
static char *get_name (CamelService *service, gboolean brief);
static gboolean sendmail_can_send (CamelTransport *transport, CamelMedium *message);
static gboolean sendmail_send (CamelTransport *transport, CamelMedium *message,
CamelException *ex);
static gboolean sendmail_send_to (CamelTransport *transport, CamelMedium *message,
static gboolean sendmail_send_to (CamelTransport *transport,
CamelMimeMessage *message,
CamelAddress *from, CamelAddress *recipients,
CamelException *ex);
@ -59,9 +57,6 @@ camel_sendmail_transport_class_init (CamelSendmailTransportClass *camel_sendmail
/* virtual method overload */
camel_service_class->get_name = get_name;
camel_transport_class->can_send = sendmail_can_send;
camel_transport_class->send = sendmail_send;
camel_transport_class->send_to = sendmail_send_to;
}
@ -86,22 +81,40 @@ camel_sendmail_transport_get_type (void)
static gboolean
sendmail_can_send (CamelTransport *transport, CamelMedium *message)
sendmail_send_to (CamelTransport *transport, CamelMimeMessage *message,
CamelAddress *from, CamelAddress *recipients,
CamelException *ex)
{
return CAMEL_IS_MIME_MESSAGE (message);
}
static gboolean
sendmail_send_internal (CamelMedium *message, const char **argv, CamelException *ex)
{
int fd[2], nullfd, wstat;
const char *from_addr, *addr, **argv;
int i, len, fd[2], nullfd, wstat;
sigset_t mask, omask;
CamelStream *out;
pid_t pid;
g_assert (CAMEL_IS_MIME_MESSAGE (message));
if (!camel_internet_address_get (CAMEL_INTERNET_ADDRESS (from), 0, NULL, &from_addr))
return FALSE;
len = camel_address_length (recipients);
argv = g_malloc ((len + 6) * sizeof (char *));
argv[0] = "sendmail";
argv[1] = "-i";
argv[2] = "-f";
argv[3] = from_addr;
argv[4] = "--";
for (i = 0; i < len; i++) {
if (!camel_internet_address_get (CAMEL_INTERNET_ADDRESS (recipients), i, NULL, &addr)) {
camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
_("Could not parse recipient list"));
g_free (argv);
return FALSE;
}
argv[i + 5] = addr;
}
argv[i + 5] = NULL;
if (pipe (fd) == -1) {
camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
_("Could not create pipe to sendmail: "
@ -125,6 +138,7 @@ sendmail_send_internal (CamelMedium *message, const char **argv, CamelException
"%s: mail not sent"),
g_strerror (errno));
sigprocmask (SIG_SETMASK, &omask, NULL);
g_free (argv);
return FALSE;
case 0:
@ -139,6 +153,7 @@ sendmail_send_internal (CamelMedium *message, const char **argv, CamelException
execv (SENDMAIL_PATH, (char **)argv);
_exit (255);
}
g_free (argv);
/* Parent process. Write the message out. */
close (fd[0]);
@ -182,76 +197,6 @@ sendmail_send_internal (CamelMedium *message, const char **argv, CamelException
return TRUE;
}
static const char *
get_from (CamelMedium *message, CamelException *ex)
{
const CamelInternetAddress *from;
const char *name, *address;
from = camel_mime_message_get_from (CAMEL_MIME_MESSAGE (message));
if (!from || !camel_internet_address_get (from, 0, &name, &address)) {
camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
_("Could not find 'From' address in message"));
return NULL;
}
return address;
}
static gboolean
sendmail_send_to (CamelTransport *transport, CamelMedium *message,
CamelAddress *from, CamelAddress *recipients,
CamelException *ex)
{
const char *from_addr, *addr, **argv;
gboolean status;
int i, len;
if (!from)
return FALSE;
if (!camel_internet_address_get (CAMEL_INTERNET_ADDRESS (from), 0, NULL, &from_addr))
return FALSE;
len = camel_address_length (recipients);
argv = g_malloc ((len + 6) * sizeof (char *));
argv[0] = "sendmail";
argv[1] = "-i";
argv[2] = "-f";
argv[3] = from_addr;
argv[4] = "--";
for (i = 0; i < len; i++) {
if (!camel_internet_address_get (CAMEL_INTERNET_ADDRESS (recipients), i, NULL, &addr)) {
camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
_("Could not parse recipient list"));
g_free (argv);
return FALSE;
}
argv[i + 5] = addr;
}
argv[i + 5] = NULL;
status = sendmail_send_internal (message, argv, ex);
g_free (argv);
return status;
}
static gboolean
sendmail_send (CamelTransport *transport, CamelMedium *message,
CamelException *ex)
{
const char *argv[6] = { "sendmail", "-t", "-i", "-f", NULL, NULL };
argv[4] = get_from (message, ex);
if (!argv[4])
return FALSE;
return sendmail_send_internal (message, argv, ex);
}
static char *
get_name (CamelService *service, gboolean brief)
{

View File

@ -63,9 +63,7 @@
#define SMTP_PORT 25
/* camel smtp transport class prototypes */
static gboolean smtp_can_send (CamelTransport *transport, CamelMedium *message);
static gboolean smtp_send (CamelTransport *transport, CamelMedium *message, CamelException *ex);
static gboolean smtp_send_to (CamelTransport *transport, CamelMedium *message,
static gboolean smtp_send_to (CamelTransport *transport, CamelMimeMessage *message,
CamelAddress *from, CamelAddress *recipients, CamelException *ex);
/* support prototypes */
@ -83,7 +81,7 @@ static gboolean smtp_auth (CamelSmtpTransport *transport, const char *mech, Came
static gboolean smtp_mail (CamelSmtpTransport *transport, const char *sender,
gboolean has_8bit_parts, CamelException *ex);
static gboolean smtp_rcpt (CamelSmtpTransport *transport, const char *recipient, CamelException *ex);
static gboolean smtp_data (CamelSmtpTransport *transport, CamelMedium *message,
static gboolean smtp_data (CamelSmtpTransport *transport, CamelMimeMessage *message,
gboolean has_8bit_parts, CamelException *ex);
static gboolean smtp_rset (CamelSmtpTransport *transport, CamelException *ex);
static gboolean smtp_quit (CamelSmtpTransport *transport, CamelException *ex);
@ -111,8 +109,6 @@ camel_smtp_transport_class_init (CamelSmtpTransportClass *camel_smtp_transport_c
camel_service_class->query_auth_types = query_auth_types;
camel_service_class->get_name = get_name;
camel_transport_class->can_send = smtp_can_send;
camel_transport_class->send = smtp_send;
camel_transport_class->send_to = smtp_send_to;
}
@ -651,13 +647,7 @@ get_name (CamelService *service, gboolean brief)
}
static gboolean
smtp_can_send (CamelTransport *transport, CamelMedium *message)
{
return CAMEL_IS_MIME_MESSAGE (message);
}
static gboolean
smtp_send_to (CamelTransport *transport, CamelMedium *message,
smtp_send_to (CamelTransport *transport, CamelMimeMessage *message,
CamelAddress *from, CamelAddress *recipients,
CamelException *ex)
{
@ -667,13 +657,6 @@ smtp_send_to (CamelTransport *transport, CamelMedium *message,
const char *addr;
int i, len;
if (!from) {
camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
_("Cannot send message: "
"sender address not defined."));
return FALSE;
}
if (!camel_internet_address_get (CAMEL_INTERNET_ADDRESS (from), 0, NULL, &addr)) {
camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
_("Cannot send message: "
@ -684,7 +667,7 @@ smtp_send_to (CamelTransport *transport, CamelMedium *message,
camel_operation_start (NULL, _("Sending message"));
/* find out if the message has 8bit mime parts */
has_8bit_parts = camel_mime_message_has_8bit_parts (CAMEL_MIME_MESSAGE (message));
has_8bit_parts = camel_mime_message_has_8bit_parts (message);
/* rfc1652 (8BITMIME) requires that you notify the ESMTP daemon that
you'll be sending an 8bit mime message at "MAIL FROM:" time. */
@ -729,31 +712,6 @@ smtp_send_to (CamelTransport *transport, CamelMedium *message,
return TRUE;
}
static gboolean
smtp_send (CamelTransport *transport, CamelMedium *message, CamelException *ex)
{
const CamelInternetAddress *from, *to, *cc, *bcc;
CamelInternetAddress *recipients = NULL;
gboolean status;
from = camel_mime_message_get_from (CAMEL_MIME_MESSAGE (message));
to = camel_mime_message_get_recipients (CAMEL_MIME_MESSAGE (message), CAMEL_RECIPIENT_TYPE_TO);
cc = camel_mime_message_get_recipients (CAMEL_MIME_MESSAGE (message), CAMEL_RECIPIENT_TYPE_CC);
bcc = camel_mime_message_get_recipients (CAMEL_MIME_MESSAGE (message), CAMEL_RECIPIENT_TYPE_BCC);
recipients = camel_internet_address_new ();
camel_address_cat (CAMEL_ADDRESS (recipients), CAMEL_ADDRESS (to));
camel_address_cat (CAMEL_ADDRESS (recipients), CAMEL_ADDRESS (cc));
camel_address_cat (CAMEL_ADDRESS (recipients), CAMEL_ADDRESS (bcc));
status = smtp_send_to (transport, message, CAMEL_ADDRESS (from), CAMEL_ADDRESS (recipients), ex);
camel_object_unref (CAMEL_OBJECT (recipients));
return status;
}
static const char *
smtp_next_token (const char *buf)
{
@ -1169,7 +1127,7 @@ smtp_rcpt (CamelSmtpTransport *transport, const char *recipient, CamelException
}
static gboolean
smtp_data (CamelSmtpTransport *transport, CamelMedium *message, gboolean has_8bit_parts, CamelException *ex)
smtp_data (CamelSmtpTransport *transport, CamelMimeMessage *message, gboolean has_8bit_parts, CamelException *ex)
{
/* now we can actually send what's important :p */
char *cmdbuf, *respbuf = NULL;
@ -1183,7 +1141,7 @@ smtp_data (CamelSmtpTransport *transport, CamelMedium *message, gboolean has_8bi
doesn't support it, encode 8bit parts to the best
encoding. This will also enforce an encoding to keep the lines in limit */
if (has_8bit_parts && !(transport->flags & CAMEL_SMTP_TRANSPORT_8BITMIME))
camel_mime_message_encode_8bit_parts (CAMEL_MIME_MESSAGE (message));
camel_mime_message_encode_8bit_parts (message);
cmdbuf = g_strdup ("DATA\r\n");