Fix FSF address (Tobias Mueller, #470445)
[platform/upstream/evolution-data-server.git] / servers / groupwise / e-gw-container.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /* 
3  * Authors : 
4  *  JP Rosevear <jpr@ximian.com>
5  *  Rodrigo Moya <rodrigo@ximian.com>
6  *
7  * Copyright 2003, Novell, Inc.
8  *
9  * This program is free software; you can redistribute it and/or 
10  * modify it under the terms of version 2 of the GNU Lesser General Public 
11  * License as published by the Free Software Foundation.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
21  * USA
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27 #include <string.h>
28 #include "e-gw-container.h"
29 #include "e-gw-message.h"
30
31 struct _EGwContainerPrivate {
32         char *name;
33         char *id;
34         char *parent;
35         guint32 unread ;
36         guint32 total ;
37         int sequence;
38         char *owner;    
39         GList *user_list;       
40         char *modified;
41         EGwContainerType type ;
42         gboolean is_root ;
43         gboolean is_writable;
44         gboolean is_frequent_contacts; /*indicates  whether this folder is frequent contacts or not */
45         gboolean is_shared_by_me;   
46         gboolean is_shared_to_me;
47
48 };
49
50 static GObjectClass *parent_class = NULL;
51
52 static void e_gw_container_set_sequence (EGwContainer *container, int sequence);
53 static void e_gw_container_set_modified (EGwContainer *container, const char *modified);
54 static void e_gw_container_set_owner(EGwContainer *container, const char *owner);
55 static void e_gw_container_set_is_shared_by_me (EGwContainer *container, gboolean is_shared_by_me);
56 static void e_gw_container_set_is_shared_to_me (EGwContainer *container, gboolean is_shared_to_me);
57
58 static void
59 free_node(EShUsers *user)
60 {
61         if(user){
62                 g_free(user->email);
63                 user->email = NULL;
64         }
65         g_free (user);
66         return ;
67 }
68
69 static void
70 e_gw_container_dispose (GObject *object)
71 {
72         EGwContainer *container = (EGwContainer *) object;
73
74         g_return_if_fail (E_IS_GW_CONTAINER (container));
75
76         if (parent_class->dispose)
77                 (* parent_class->dispose) (object);
78 }
79
80 static void
81 e_gw_container_finalize (GObject *object)
82 {
83         EGwContainer *container = (EGwContainer *) object;
84         EGwContainerPrivate *priv;
85
86         g_return_if_fail (E_IS_GW_CONTAINER (container));
87
88         priv = container->priv;
89         if (priv) {
90                 if (priv->name) {
91                         g_free (priv->name);
92                         priv->name = NULL;
93                 }
94
95                 if (priv->id) {
96                         g_free (priv->id);
97                         priv->id = NULL;
98                 }
99
100                 if (priv->parent) {
101                         g_free (priv->parent);
102                         priv->parent = NULL;
103                 }
104
105                 if (priv->owner) {
106                         g_free (priv->owner);
107                         priv->owner = NULL;
108                 }
109
110                 if (priv->modified) {
111                         g_free (priv->modified);
112                         priv->modified = NULL;
113                 }
114
115                 if(priv->user_list) {
116                         g_list_foreach (priv->user_list,(GFunc) free_node, NULL);
117                         g_list_free (priv->user_list);
118                         priv->user_list = NULL;
119                 }
120
121                 g_free (priv);
122                 container->priv = NULL;
123         }
124
125         if (parent_class->finalize)
126                 (* parent_class->finalize) (object);
127 }
128
129 static void
130 e_gw_container_class_init (EGwContainerClass *klass)
131 {
132         GObjectClass *object_class = G_OBJECT_CLASS (klass);
133
134         parent_class = g_type_class_peek_parent (klass);
135
136         object_class->dispose = e_gw_container_dispose;
137         object_class->finalize = e_gw_container_finalize;
138 }
139
140 static void
141 e_gw_container_init (EGwContainer *container, EGwContainerClass *klass)
142 {
143         EGwContainerPrivate *priv;
144
145         /* allocate internal structure */
146         priv = g_new0 (EGwContainerPrivate, 1);
147         priv->is_writable = TRUE;
148         priv->is_frequent_contacts = FALSE;
149         container->priv = priv;
150 }
151
152 GType
153 e_gw_container_get_type (void)
154 {
155         static GType type = 0;
156
157         if (!type) {
158                 static GTypeInfo info = {
159                         sizeof (EGwContainerClass),
160                         (GBaseInitFunc) NULL,
161                         (GBaseFinalizeFunc) NULL,
162                         (GClassInitFunc) e_gw_container_class_init,
163                         NULL, NULL,
164                         sizeof (EGwContainer),
165                         0,
166                         (GInstanceInitFunc) e_gw_container_init
167                 };
168                 type = g_type_register_static (G_TYPE_OBJECT, "EGwContainer", &info, 0);
169         }
170
171         return type;
172 }
173
174 EGwContainer *
175 e_gw_container_new_from_soap_parameter (SoupSoapParameter *param)
176 {
177         EGwContainer *container;
178
179         g_return_val_if_fail (param != NULL, NULL);
180
181         container = g_object_new (E_TYPE_GW_CONTAINER, NULL);
182         if (!e_gw_container_set_from_soap_parameter (container, param)) {
183                 g_object_unref (container);
184                 return NULL;
185         }
186
187         return container;
188 }
189
190 gboolean
191 e_gw_container_set_from_soap_parameter (EGwContainer *container, SoupSoapParameter *param)
192 {
193         char *value;
194         int int_value;
195         int rights = 0;
196         gboolean byme = FALSE;
197         gboolean tome = FALSE;
198         SoupSoapParameter *subparam;
199         SoupSoapParameter *entry_subparam;
200         SoupSoapParameter *email_rt_subparam;
201         SoupSoapParameter *rights_subparam;
202
203         g_return_val_if_fail (E_IS_GW_CONTAINER (container), FALSE);
204         g_return_val_if_fail (param != NULL, FALSE);
205
206         /* retrieve the name */
207         subparam = soup_soap_parameter_get_first_child_by_name (param, "name");
208         if (!subparam) {
209                 g_warning (G_STRLOC ": found container with no name");
210                 return FALSE;
211         }
212
213         value = soup_soap_parameter_get_string_value (subparam);
214         e_gw_container_set_name (container, (const char *) value);
215         g_free (value);
216
217         /* retrieve the ID */
218         subparam = soup_soap_parameter_get_first_child_by_name (param, "id");
219         if (!subparam) {
220                 g_warning (G_STRLOC ": found container with no ID");
221                 return FALSE;
222         }
223
224         value = soup_soap_parameter_get_string_value (subparam);
225         e_gw_container_set_id (container, (const char *) value);
226         g_free (value);
227
228         /* retrieve the parent container id */
229         subparam = soup_soap_parameter_get_first_child_by_name (param, "parent");
230         if (!subparam) {
231                 e_gw_container_set_parent_id (container, "");
232                 container->priv->is_root = TRUE ;
233         } else {
234
235                 value = soup_soap_parameter_get_string_value (subparam);
236                 e_gw_container_set_parent_id (container, (const char *) value);
237                 g_free (value) ;
238         }
239
240         /*retrieve the folder type*/
241         subparam = soup_soap_parameter_get_first_child_by_name (param, "folderType") ;
242         if (!subparam) 
243                 container->priv->type = E_GW_CONTAINER_TYPE_FOLDER ;
244         else {
245                 value = soup_soap_parameter_get_string_value (subparam);
246                 if (!strcmp (value, "Root")) 
247                         container->priv->type = E_GW_CONTAINER_TYPE_ROOT ;
248                 else if (!strcmp (value, "Mailbox")) 
249                         container->priv->type = E_GW_CONTAINER_TYPE_INBOX ;
250                 else if (!strcmp (value, "SentItems")) 
251                         container->priv->type = E_GW_CONTAINER_TYPE_SENT;
252                 else if (!strcmp (value, "Calendar")) 
253                         container->priv->type = E_GW_CONTAINER_TYPE_CALENDAR ;
254                 else if (!strcmp (value, "Contacts")) 
255                         container->priv->type = E_GW_CONTAINER_TYPE_CONTACTS ;
256                 else if (!strcmp (value, "Draft")) 
257                         container->priv->type = E_GW_CONTAINER_TYPE_DRAFT ;
258                 else if (!strcmp (value, "Trash")) 
259                         container->priv->type = E_GW_CONTAINER_TYPE_TRASH ;
260                 else if (!strcmp (value, "JunkMail")) 
261                         container->priv->type = E_GW_CONTAINER_TYPE_JUNK;
262                 g_free (value) ;
263         }
264
265         /* retrive the unread and total count */
266         subparam = soup_soap_parameter_get_first_child_by_name (param, "hasUnread") ;
267         if (!subparam) {
268                 container->priv->unread = 0 ;
269         } else {
270                 subparam = soup_soap_parameter_get_first_child_by_name (param, "unreadCount") ;
271                 if (subparam) {
272                         value = soup_soap_parameter_get_string_value (subparam) ;
273                         if (value)
274                                 container->priv->unread = atoi(value) ;
275                         else
276                                 container->priv->unread = 0 ; /*XXX:should it be 0?*/
277
278                         g_free (value) ;
279                 }
280         }
281
282         subparam = soup_soap_parameter_get_first_child_by_name (param, "count") ;
283         if (subparam) {
284                 value = soup_soap_parameter_get_string_value (subparam) ;
285                 if (value)
286                         container->priv->total = atoi(value) ;
287                 g_free (value) ;
288         }
289         /* Is shared by me*/
290         subparam = soup_soap_parameter_get_first_child_by_name (param, "isSharedByMe");
291         if (!subparam) {
292                 e_gw_container_set_is_shared_by_me(container, FALSE);
293
294         } else {
295                 value = soup_soap_parameter_get_string_value (subparam);
296                 if (value) {
297                         e_gw_container_set_is_shared_by_me (container, TRUE);
298                         byme = TRUE;
299                 } else {
300                         e_gw_container_set_is_shared_by_me (container, FALSE);
301                         byme = FALSE;
302                 }
303
304                 g_free (value);
305         }
306         /* is shared to me*/
307         subparam = soup_soap_parameter_get_first_child_by_name (param, "isSharedToMe");
308         
309         if (!subparam) {
310                 e_gw_container_set_is_shared_to_me (container, FALSE);
311
312         } else {
313                 value = soup_soap_parameter_get_string_value (subparam);
314                 if (value) {
315                         e_gw_container_set_is_shared_to_me (container, TRUE);
316                         tome = TRUE;
317                 } else { 
318                         e_gw_container_set_is_shared_to_me (container, FALSE);
319                         tome = FALSE;
320                 }
321                 
322                 g_free (value);
323         }
324         /*Retrieve email add of the sharing person*/
325         if (tome || byme) {
326                 subparam = soup_soap_parameter_get_first_child_by_name (param, "acl");
327                 if (!subparam)
328                         g_warning (G_STRLOC ": No ACL");
329
330                 else {
331                         for (entry_subparam = soup_soap_parameter_get_first_child_by_name (subparam, "entry");
332                                         entry_subparam != NULL;
333                                         entry_subparam = soup_soap_parameter_get_next_child_by_name (entry_subparam, "entry")) {
334
335                                 EShUsers *user = g_new0(EShUsers , 1);
336                                 email_rt_subparam = soup_soap_parameter_get_first_child_by_name (entry_subparam, "email");
337
338                                 if (!email_rt_subparam) {
339                                         g_warning (G_STRLOC ":Email Tag Not Available");
340                                 } else {
341                                         value = soup_soap_parameter_get_string_value (email_rt_subparam);
342                                         if (value) {
343                                                 user->email = value;
344                                         }       
345                                         /* Retrieve Rights*/
346                                         email_rt_subparam = soup_soap_parameter_get_first_child_by_name (entry_subparam, "rights");
347
348                                         if (!email_rt_subparam)
349                                                 g_warning (G_STRLOC ": User without any Rights");
350                                         else {
351                                                 rights = 0;
352                                                 rights_subparam = soup_soap_parameter_get_first_child_by_name (email_rt_subparam, "add");       
353                                                 if (rights_subparam)    
354                                                         rights = rights | 0x1;
355
356                                                 rights_subparam = soup_soap_parameter_get_first_child_by_name (email_rt_subparam, "edit");      
357                                                 if (rights_subparam) 
358                                                         rights = rights | 0x2;
359
360                                                 rights_subparam = soup_soap_parameter_get_first_child_by_name (email_rt_subparam, "delete");    
361                                                 if (rights_subparam)    
362                                                         rights = rights | 0x4;
363
364                                                 user->rights = rights;
365                                         }
366
367                                         container->priv->user_list = g_list_append (container->priv->user_list, user);
368
369                                 } 
370
371                         }
372
373                 }
374
375                 /*Retrieve owner*/
376                 subparam = soup_soap_parameter_get_first_child_by_name (param, "owner");
377                 if (subparam) {
378                         value = soup_soap_parameter_get_string_value (subparam);
379                         e_gw_container_set_owner (container, value);
380                         g_free (value);
381                 }
382         }       
383
384                 /* shared folder*/
385                 /*Retrieve When Modified last*/
386                 subparam = soup_soap_parameter_get_first_child_by_name (param, "modified");
387
388                 if (subparam) {
389                         value = soup_soap_parameter_get_string_value (subparam);
390                         e_gw_container_set_modified (container, (const char *) value);
391                         g_free (value);
392                 }
393
394                 /*retrieve sequence*/
395                 subparam = soup_soap_parameter_get_first_child_by_name (param, "sequence");
396
397                 if (subparam) { 
398                         int_value = soup_soap_parameter_get_int_value (subparam);
399                         e_gw_container_set_sequence (container, int_value);             
400                 }
401
402                 return TRUE;
403 }
404
405 void 
406 e_gw_container_get_user_list (EGwContainer *container, GList **user_list)
407 {
408         g_return_if_fail (E_GW_CONTAINER (container));
409         
410         *user_list = container->priv->user_list;
411
412 }
413
414 int
415 e_gw_container_get_sequence (EGwContainer *container)
416 {
417         g_return_val_if_fail (E_IS_GW_CONTAINER (container), 0);
418         
419         return (int)container->priv->sequence;
420 }
421
422 static  void 
423 e_gw_container_set_sequence (EGwContainer *container, int sequence)
424 {
425         g_return_if_fail (E_IS_GW_CONTAINER (container));
426         container->priv->sequence = sequence;
427 }
428
429 const char *
430 e_gw_container_get_modified (EGwContainer *container)
431 {
432         g_return_val_if_fail (E_IS_GW_CONTAINER (container), NULL);
433
434         return (const char *) container->priv->modified;
435 }
436
437 static void
438 e_gw_container_set_modified (EGwContainer *container, const char *modified)
439 {
440         EGwContainerPrivate *priv;
441
442         g_return_if_fail (E_IS_GW_CONTAINER (container));
443         g_return_if_fail (modified != NULL);
444
445         priv = container->priv;
446
447         if (priv->modified)
448                 g_free (priv->modified);
449         priv->modified = g_strdup (modified);
450 }
451
452 static void 
453 e_gw_container_set_owner(EGwContainer *container, const char *owner)
454 {
455         EGwContainerPrivate *priv;
456         
457         g_return_if_fail (E_IS_GW_CONTAINER(container));
458         g_return_if_fail (owner!=NULL);
459         
460         priv = container->priv;
461         if (priv->owner)
462                 g_free (container->priv->owner);
463         container->priv->owner = g_strdup (owner);
464 }
465
466 const char *
467 e_gw_container_get_owner (EGwContainer *container)
468 {
469         g_return_val_if_fail (E_GW_CONTAINER (container), NULL);
470         
471         return (const char *) container->priv->owner;
472 }
473
474 int
475 e_gw_container_get_rights (EGwContainer *container, gchar *email)
476 {
477         GList *user_list = NULL;
478         GList *node = NULL;
479         EShUsers *user = NULL;
480
481         g_return_val_if_fail (E_IS_GW_CONTAINER (container), 0);
482
483         user_list = container->priv->user_list;
484         
485         for (node = user_list; node != NULL; node = node->next) {
486                 user = node->data;
487                 if( !strcmp (user->email, email))
488                         return user->rights;
489         }
490
491         return 0;
492 }
493
494 gboolean
495 e_gw_container_get_is_shared_by_me (EGwContainer *container)
496 {
497         g_return_val_if_fail (E_IS_GW_CONTAINER (container), FALSE);
498         
499         return (gboolean) container->priv->is_shared_by_me;
500 }
501
502 static void
503 e_gw_container_set_is_shared_by_me (EGwContainer *container, gboolean is_shared_by_me)
504 {
505         g_return_if_fail (E_IS_GW_CONTAINER (container));
506         
507         container->priv->is_shared_by_me = is_shared_by_me;
508 }
509
510 gboolean
511 e_gw_container_get_is_shared_to_me (EGwContainer *container)
512 {
513         g_return_val_if_fail (E_IS_GW_CONTAINER (container), FALSE);
514         
515         return (gboolean) container->priv->is_shared_to_me;
516 }
517
518 static void
519 e_gw_container_set_is_shared_to_me (EGwContainer *container, gboolean is_shared_to_me)
520 {
521         g_return_if_fail (E_IS_GW_CONTAINER (container));
522         
523         container->priv->is_shared_to_me = is_shared_to_me;
524 }
525
526 const char *
527 e_gw_container_get_name (EGwContainer *container)
528 {
529         g_return_val_if_fail (E_IS_GW_CONTAINER (container), NULL);
530
531         return (const char *) container->priv->name;
532 }
533
534 void
535 e_gw_container_set_name (EGwContainer *container, const char *new_name)
536 {
537         EGwContainerPrivate *priv;
538
539         g_return_if_fail (E_IS_GW_CONTAINER (container));
540         g_return_if_fail (new_name != NULL);
541
542         priv = container->priv;
543
544         if (priv->name)
545                 g_free (priv->name);
546         priv->name = g_strdup (new_name);
547 }
548
549 const char *
550 e_gw_container_get_id (EGwContainer *container)
551 {
552         g_return_val_if_fail (E_IS_GW_CONTAINER (container), NULL);
553
554         return (const char *) container->priv->id;
555 }
556
557 void
558 e_gw_container_set_id (EGwContainer *container, const char *new_id)
559 {
560         EGwContainerPrivate *priv;
561
562         g_return_if_fail (E_IS_GW_CONTAINER (container));
563         g_return_if_fail (new_id != NULL);
564
565         priv = container->priv;
566
567         if (priv->id)
568                 g_free (priv->id);
569         priv->id = g_strdup (new_id);
570 }
571
572 const char *
573 e_gw_container_get_parent_id (EGwContainer *container) 
574 {
575         g_return_val_if_fail (E_IS_GW_CONTAINER (container), NULL);
576
577         return (const char *) container->priv->parent;
578 }
579
580 void
581 e_gw_container_set_parent_id (EGwContainer *container, const char *parent_id)
582 {
583         EGwContainerPrivate *priv ;
584         
585         g_return_if_fail (E_IS_GW_CONTAINER (container));
586         g_return_if_fail (parent_id != NULL);
587
588         priv = container->priv ;
589
590         if (priv->parent)
591                 g_free (priv->parent) ;
592
593         priv->parent = g_strdup (parent_id) ;
594 }
595
596 guint32
597 e_gw_container_get_total_count (EGwContainer *container)
598 {
599         g_return_val_if_fail (E_IS_GW_CONTAINER (container), -1) ;
600
601         return container->priv->total ;
602 }
603                 
604 guint32
605 e_gw_container_get_unread_count (EGwContainer *container)
606 {
607         g_return_val_if_fail (E_IS_GW_CONTAINER (container), -1) ;
608
609         return container->priv->unread ;
610
611 }
612
613
614 gboolean 
615 e_gw_container_get_is_writable (EGwContainer *container)
616 {
617         g_return_val_if_fail (E_IS_GW_CONTAINER (container), FALSE);
618         
619         return container->priv->is_writable;
620
621 }
622
623 void 
624 e_gw_container_set_is_writable (EGwContainer *container, gboolean is_writable)
625 {
626         g_return_if_fail (E_IS_GW_CONTAINER (container));
627         
628         container->priv->is_writable = is_writable;
629 }
630
631 gboolean 
632 e_gw_container_get_is_frequent_contacts (EGwContainer *container)
633 {
634         g_return_val_if_fail (E_IS_GW_CONTAINER (container), FALSE);
635                                                                                                                              
636         return container->priv->is_frequent_contacts;
637
638 }
639
640 void
641 e_gw_container_set_is_frequent_contacts (EGwContainer *container, gboolean is_frequent_contacts)
642 {
643         g_return_if_fail (E_IS_GW_CONTAINER (container));
644                                                                                                                              
645         container->priv->is_frequent_contacts = is_frequent_contacts;
646 }
647
648 gboolean
649 e_gw_container_is_root (EGwContainer *container)
650 {
651         g_return_val_if_fail (E_IS_GW_CONTAINER (container), FALSE) ;
652         
653         return container->priv->is_root ;
654 }
655
656 EGwContainerType
657 e_gw_container_get_container_type (EGwContainer *container)
658 {
659         g_return_val_if_fail (E_IS_GW_CONTAINER (container), FALSE) ;
660         return container->priv->type ;
661 }
662
663 /* flag specifies whether we are adding to acl or deleting one or more entries*/
664 /* flag = 1 :delete entry
665  * flag = 2 :update entry
666  * flag = 0 :add to acl
667  */
668 void    
669 e_gw_container_form_message (SoupSoapMessage *msg, gchar *id, GList *new_list, const char *sub, const char *mesg, int flag)
670 {
671         gboolean add, edit, del;
672         gchar *email = NULL;
673         GList *node = NULL;
674         EShUsers *user = NULL;
675
676         e_gw_message_write_string_parameter (msg, "id", NULL, id);
677         soup_soap_message_start_element (msg, "notification", NULL, NULL);
678         e_gw_message_write_string_parameter (msg, "subject", NULL, sub);
679         e_gw_message_write_string_parameter (msg, "message", NULL, mesg);
680         soup_soap_message_end_element (msg);
681         soup_soap_message_start_element (msg, "updates", NULL, NULL);
682
683         if (flag == 0) {        
684                 soup_soap_message_start_element (msg, "add", NULL, NULL);
685                 soup_soap_message_start_element (msg, "acl", NULL, NULL);
686
687                 for (node = new_list; node != NULL; node = node->next) {
688                         user = node->data;
689                         add=edit=del=FALSE;
690                         soup_soap_message_start_element (msg, "entry", NULL, NULL);
691                         e_gw_message_write_string_parameter (msg, "displayName", NULL,"");
692                         email = g_strdup (user->email); 
693                         if (user->rights & 0x1)
694                                 add = TRUE;
695                         if (user->rights & 0x2)
696                                 edit = TRUE;
697                         if (user->rights & 0x4)
698                                 del = TRUE;
699
700                         e_gw_message_write_string_parameter (msg, "email", NULL, email);
701                         soup_soap_message_start_element (msg, "rights", NULL, NULL);
702                         e_gw_message_write_int_parameter (msg, "read", NULL, 1);
703                         e_gw_message_write_int_parameter (msg, "add", NULL, add);
704                         e_gw_message_write_int_parameter (msg, "edit", NULL, edit);
705                         e_gw_message_write_int_parameter (msg, "delete", NULL, del);
706
707                         soup_soap_message_end_element (msg);
708                         soup_soap_message_end_element (msg);
709                 } 
710
711                 soup_soap_message_end_element (msg);
712                 soup_soap_message_end_element (msg);
713
714         } else  if (flag == 1) {
715                 soup_soap_message_start_element (msg, "delete", NULL, NULL);
716                 soup_soap_message_start_element (msg, "acl", NULL, NULL);
717
718                 for (node = new_list; node != NULL; node = node->next) {
719                         user = node->data;
720                         add = edit = del = FALSE;
721                         soup_soap_message_start_element (msg, "entry", NULL, NULL);
722                         e_gw_message_write_string_parameter (msg, "displayName", NULL, "name");
723                         email = g_strdup (user->email); 
724
725                         if(user->rights & 0x1)
726                                 add = TRUE;
727                         if(user->rights & 0x2)
728                                 edit = TRUE;
729                         if(user->rights & 0x4)
730                                 del = TRUE;
731
732                         e_gw_message_write_string_parameter (msg, "email", NULL, email);
733                         soup_soap_message_start_element(msg, "rights", NULL, NULL);
734                         e_gw_message_write_int_parameter (msg, "read", NULL, 1);
735                         e_gw_message_write_int_parameter (msg, "add", NULL, add);
736                         e_gw_message_write_int_parameter (msg, "edit", NULL, edit);
737                         e_gw_message_write_int_parameter (msg, "delete", NULL, del);
738
739                         soup_soap_message_end_element (msg);
740                         soup_soap_message_end_element (msg);
741
742                 }
743                 soup_soap_message_end_element (msg);
744                 soup_soap_message_end_element (msg);
745
746         } else if (flag == 2) { 
747                 soup_soap_message_start_element (msg, "update", NULL, NULL);
748                 soup_soap_message_start_element (msg, "acl", NULL, NULL);
749
750                 for (node = new_list; node != NULL; node = node->next) {
751                         user = node->data;
752                         add = edit = del = FALSE;
753                         soup_soap_message_start_element (msg, "entry", NULL, NULL);
754                         e_gw_message_write_string_parameter (msg, "displayName",NULL,"");
755                         email = g_strdup (user->email); 
756                         if (user->rights & 0x1)
757                                 add = TRUE;
758                         if (user->rights & 0x2)
759                                 edit = TRUE;
760                         if (user->rights & 0x4)
761                                 del =TRUE;
762
763                         e_gw_message_write_string_parameter (msg, "email", NULL, email);
764                         soup_soap_message_start_element (msg, "rights", NULL, NULL);
765                         e_gw_message_write_int_parameter (msg, "read", NULL, 1);
766                         e_gw_message_write_int_parameter (msg, "add", NULL, add);
767                         e_gw_message_write_int_parameter (msg, "edit", NULL, edit);
768                         e_gw_message_write_int_parameter (msg, "delete", NULL, del);
769
770                         soup_soap_message_end_element (msg);
771                         soup_soap_message_end_element (msg);
772                 }
773
774                 soup_soap_message_end_element (msg);
775                 soup_soap_message_end_element (msg);
776
777         }
778
779         soup_soap_message_end_element (msg);    
780 }