Fix FSF address (Tobias Mueller, #470445)
[platform/upstream/evolution-data-server.git] / camel / camel-transport.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /* camel-transport.c : Abstract class for an email transport */
3
4 /* 
5  *
6  * Author : 
7  *  Dan Winship <danw@ximian.com>
8  *
9  * Copyright 2000 Ximian, Inc. (www.ximian.com)
10  *
11  * This program is free software; you can redistribute it and/or 
12  * modify it under the terms of version 2 of the GNU Lesser General Public 
13  * License as published by the Free Software Foundation.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
23  * USA
24  */
25
26 #ifdef HAVE_CONFIG_H
27 #include <config.h>
28 #endif
29
30 #include "camel-address.h"
31 #include "camel-mime-message.h"
32 #include "camel-private.h"
33 #include "camel-transport.h"
34
35 static CamelServiceClass *parent_class = NULL;
36
37 /* Returns the class for a CamelTransport */
38 #define CT_CLASS(so) CAMEL_TRANSPORT_CLASS (CAMEL_OBJECT_GET_CLASS(so))
39
40 static int transport_setv (CamelObject *object, CamelException *ex, CamelArgV *args);
41 static int transport_getv (CamelObject *object, CamelException *ex, CamelArgGetV *args);
42
43
44 static void
45 camel_transport_class_init (CamelTransportClass *camel_transport_class)
46 {
47         CamelObjectClass *camel_object_class = CAMEL_OBJECT_CLASS (camel_transport_class);
48         
49         parent_class = CAMEL_SERVICE_CLASS (camel_type_get_global_classfuncs (camel_service_get_type ()));
50         
51         /* virtual method overload */
52         camel_object_class->setv = transport_setv;
53         camel_object_class->getv = transport_getv;
54 }
55
56 static void
57 camel_transport_init (gpointer object, gpointer klass)
58 {
59         CamelTransport *xport = object;
60         
61         xport->priv = g_malloc0 (sizeof (struct _CamelTransportPrivate));
62         xport->priv->send_lock = g_mutex_new ();
63 }
64
65 static void
66 camel_transport_finalize (CamelObject *object)
67 {
68         CamelTransport *xport = CAMEL_TRANSPORT (object);
69         
70         g_mutex_free (xport->priv->send_lock);
71         g_free (xport->priv);
72 }
73
74 CamelType
75 camel_transport_get_type (void)
76 {
77         static CamelType type = CAMEL_INVALID_TYPE;
78         
79         if (type == CAMEL_INVALID_TYPE) {
80                 type = camel_type_register (CAMEL_SERVICE_TYPE,
81                                             "CamelTransport",
82                                             sizeof (CamelTransport),
83                                             sizeof (CamelTransportClass),
84                                             (CamelObjectClassInitFunc) camel_transport_class_init,
85                                             NULL,
86                                             (CamelObjectInitFunc) camel_transport_init,
87                                             (CamelObjectFinalizeFunc) camel_transport_finalize);
88         }
89         
90         return type;
91 }
92
93
94 static int
95 transport_setv (CamelObject *object, CamelException *ex, CamelArgV *args)
96 {
97         /* CamelTransport doesn't currently have anything to set */
98         return CAMEL_OBJECT_CLASS (parent_class)->setv (object, ex, args);
99 }
100
101 static int
102 transport_getv (CamelObject *object, CamelException *ex, CamelArgGetV *args)
103 {
104         /* CamelTransport doesn't currently have anything to get */
105         return CAMEL_OBJECT_CLASS (parent_class)->getv (object, ex, args);
106 }
107
108
109 /**
110  * camel_transport_send_to:
111  * @transport: a #CamelTransport object
112  * @message: a #CamelMimeMessage to send
113  * @from: a #CamelAddress to send from
114  * @recipients: a #CamelAddress containing all recipients
115  * @ex: a #CamelException
116  *
117  * Sends the message to the given recipients, regardless of the contents
118  * of @message. If the message contains a "Bcc" header, the transport
119  * is responsible for stripping it.
120  *
121  * Return %TRUE on success or %FALSE on fail
122  **/
123 gboolean
124 camel_transport_send_to (CamelTransport *transport, CamelMimeMessage *message,
125                          CamelAddress *from, CamelAddress *recipients,
126                          CamelException *ex)
127 {
128         gboolean sent;
129         
130         g_return_val_if_fail (CAMEL_IS_TRANSPORT (transport), FALSE);
131         g_return_val_if_fail (CAMEL_IS_MIME_MESSAGE (message), FALSE);
132         g_return_val_if_fail (CAMEL_IS_ADDRESS (from), FALSE);
133         g_return_val_if_fail (CAMEL_IS_ADDRESS (recipients), FALSE);
134         
135         CAMEL_TRANSPORT_LOCK (transport, send_lock);
136         sent = CT_CLASS (transport)->send_to (transport, message,
137                                               from, recipients, ex);
138         CAMEL_TRANSPORT_UNLOCK (transport, send_lock);
139         
140         return sent;
141 }