1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /* camel-groupwise-transport.c : class for an groupwise transport */
5 * Authors: Sivaiah Nallagatla <snallagatla@novell.com>
6 * Parthasarathi Susarla <sparthasarathi@novell.com>
8 * Copyright (C) 2004 Novell, Inc.
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU Lesser General Public
12 * License as published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
32 #include <glib/gi18n-lib.h>
34 #include <libsoup/soup-misc.h>
36 #include "camel-data-wrapper.h"
37 #include "camel-medium.h"
38 #include "camel-mime-message.h"
39 #include "camel-mime-utils.h"
40 #include "camel-multipart.h"
41 #include "camel-session.h"
42 #include "camel-stream-mem.h"
43 #include "camel-stream.h"
45 #include "camel-groupwise-store.h"
46 #include "camel-groupwise-transport.h"
47 #include "camel-groupwise-utils.h"
49 static gboolean groupwise_send_to (CamelTransport *transport,
50 CamelMimeMessage *message,
52 CamelAddress *recipients,
55 static gboolean groupwise_transport_connect (CamelService *service, CamelException *ex);
56 static char *groupwise_transport_get_name (CamelService *service, gboolean brief);
57 static void groupwise_transport_construct (CamelService *service, CamelSession *session,
58 CamelProvider *provider, CamelURL *url, CamelException *ex);
61 static CamelTransportClass *parent_class = NULL;
66 camel_groupwise_transport_class_init (CamelGroupwiseTransportClass *camel_groupwise_transport_class)
68 CamelTransportClass *camel_transport_class =
69 CAMEL_TRANSPORT_CLASS (camel_groupwise_transport_class);
71 CamelServiceClass *camel_service_class =
72 CAMEL_SERVICE_CLASS (camel_groupwise_transport_class);
74 parent_class = CAMEL_TRANSPORT_CLASS (camel_type_get_global_classfuncs (camel_transport_get_type ()));
76 camel_service_class->connect = groupwise_transport_connect;
77 camel_service_class->get_name = groupwise_transport_get_name;
78 camel_service_class->construct = groupwise_transport_construct;
80 /* virtual method overload */
81 camel_transport_class->send_to = groupwise_send_to;
85 camel_groupwise_transport_init (CamelTransport *transport)
91 groupwise_transport_construct (CamelService *service, CamelSession *session,
92 CamelProvider *provider, CamelURL *url,
95 CAMEL_SERVICE_CLASS (parent_class)->construct (service, session, provider, url, ex);
96 if (camel_exception_is_set (ex))
101 camel_groupwise_transport_get_type (void)
103 static CamelType camel_groupwise_transport_type = CAMEL_INVALID_TYPE;
105 if (camel_groupwise_transport_type == CAMEL_INVALID_TYPE) {
106 camel_groupwise_transport_type =
107 camel_type_register (CAMEL_TRANSPORT_TYPE,
108 "CamelGroupwiseTransport",
109 sizeof (CamelGroupwiseTransport),
110 sizeof (CamelGroupwiseTransportClass),
111 (CamelObjectClassInitFunc) camel_groupwise_transport_class_init,
113 (CamelObjectInitFunc) camel_groupwise_transport_init,
117 return camel_groupwise_transport_type;
120 static char *groupwise_transport_get_name (CamelService *service, gboolean brief)
123 return g_strdup_printf (_("GroupWise server %s"), service->url->host);
125 return g_strdup_printf (_("GroupWise mail delivery via %s"),
132 groupwise_transport_connect (CamelService *service, CamelException *ex)
140 groupwise_send_to (CamelTransport *transport,
141 CamelMimeMessage *message,
143 CamelAddress *recipients,
146 CamelService *service;
147 CamelStore *store = NULL;
148 CamelGroupwiseStore *groupwise_store = NULL;
149 CamelGroupwiseStorePrivate *priv = NULL;
150 EGwItem *item ,*temp_item=NULL;
151 EGwConnection *cnc = NULL;
152 EGwConnectionStatus status = 0;
153 GSList *sent_item_list = NULL;
155 const char *reply_request = NULL;
156 EGwItemLinkInfo *info = NULL;
159 camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE, _("Authentication failed"));
163 service = CAMEL_SERVICE(transport);
164 url = camel_url_to_string (service->url,
165 (CAMEL_URL_HIDE_PASSWORD |
166 CAMEL_URL_HIDE_PARAMS |
167 CAMEL_URL_HIDE_AUTH) );
169 camel_operation_start (NULL, _("Sending Message") );
171 /*camel groupwise store and cnc*/
172 store = camel_session_get_store (service->session, url, ex );
175 g_warning ("ERROR: Could not get a pointer to the store");
176 camel_exception_set (ex, CAMEL_EXCEPTION_STORE_INVALID, _("Cannot get folder: Invalid operation on this store"));
179 groupwise_store = CAMEL_GROUPWISE_STORE (store);
180 priv = groupwise_store->priv;
182 cnc = cnc_lookup (priv);
184 g_warning ("||| Eh!!! Failure |||\n");
185 camel_operation_end (NULL);
186 camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE, _("Authentication failed"));
190 item = camel_groupwise_util_item_from_message (cnc, message, from);
192 reply_request = (char *)camel_medium_get_header (CAMEL_MEDIUM (message), "In-Reply-To");
195 int len = strlen (reply_request);
197 id = (char *)g_malloc0 (len-1);
198 id = memcpy(id, reply_request+2, len-3);
199 status = e_gw_connection_reply_item (cnc, id, NULL, &temp_item);
200 if (status != E_GW_CONNECTION_STATUS_OK)
201 g_warning ("Could not send a replyRequest...continuing without!!\n");
203 info = e_gw_item_get_link_info (temp_item);
204 e_gw_item_set_link_info (item, info);
212 status = e_gw_connection_send_item (cnc, item, &sent_item_list);
213 if (status != E_GW_CONNECTION_STATUS_OK) {
214 g_warning (" Error Sending mail");
215 camel_operation_end (NULL);
216 e_gw_item_set_link_info (item, NULL);
217 g_object_unref (item);
219 g_object_unref (temp_item);
221 /* FIXME: 58652 should be changed with an enum.*/
223 camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, _("You have exceeded this account's storage limit. Your messages are queued in your Outbox. Resend by pressing Send/Receive after deleting/archiving some of your mail.\n"));
225 camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,_("Could not send message: %s"),_("Unknown error"));
229 e_gw_item_set_link_info (item, NULL);
231 e_gw_item_set_recipient_list (item, NULL);
234 g_object_unref (temp_item);
235 g_object_unref (item);
237 camel_operation_end (NULL);