talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit 8924abc0db7198ac115bce618bdd565e46dfcf7d
parent 28b2c38a9b25f611f844202ba785fa4c9588768e
Author: Oliver Lowe <o@olowe.co>
Date:   Sun,  3 Aug 2025 19:49:23 +1000

Drop LDAP, JPilot address book support

Me no clever for LDAP
Palm pilot devices not manufactured for many years now.

Diffstat:
Mconfigure.ac | 142+------------------------------------------------------------------------------
Msrc/Makefile.am | 40+++-------------------------------------
Msrc/adbookbase.h | 4+---
Msrc/addrdefs.h | 3+--
Msrc/addrduplicates.c | 18++----------------
Msrc/addressadd.c | 47+++++++++++++++--------------------------------
Msrc/addressbook.c | 661+++++++++++--------------------------------------------------------------------
Msrc/addressitem.h | 5+----
Msrc/addrindex.c | 862++-----------------------------------------------------------------------------
Msrc/addrindex.h | 16+++++-----------
Msrc/addrmerge.c | 15++-------------
Msrc/addrquery.h | 3+--
Dsrc/browseldap.c | 444-------------------------------------------------------------------------------
Dsrc/browseldap.h | 35-----------------------------------
Msrc/compose.c | 814++++++++++++++++++++++++++++++++++++++-----------------------------------------
Msrc/compose.h | 28+++++++++++-----------------
Msrc/crash.c | 68+++++++++++++++++++++++++++++++-------------------------------------
Msrc/editaddress.c | 73++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/editaddress_other_attributes_ldap.c | 450-------------------------------------------------------------------------------
Msrc/editaddress_other_attributes_ldap.h | 36+-----------------------------------
Dsrc/editjpilot.c | 414-------------------------------------------------------------------------------
Dsrc/editjpilot.h | 33---------------------------------
Dsrc/editldap.c | 1093-------------------------------------------------------------------------------
Dsrc/editldap.h | 29-----------------------------
Dsrc/editldap_basedn.c | 370-------------------------------------------------------------------------------
Dsrc/editldap_basedn.h | 30------------------------------
Msrc/etpan/etpan-errors.h | 3+--
Dsrc/expldifdlg.c | 780-------------------------------------------------------------------------------
Dsrc/expldifdlg.h | 35-----------------------------------
Dsrc/exportldif.c | 705-------------------------------------------------------------------------------
Dsrc/exportldif.h | 78------------------------------------------------------------------------------
Msrc/gtk/about.c | 54+++++++++++++++++-------------------------------------
Dsrc/importldif.c | 1041-------------------------------------------------------------------------------
Dsrc/importldif.h | 34----------------------------------
Dsrc/jpilot.c | 1668-------------------------------------------------------------------------------
Dsrc/jpilot.h | 107-------------------------------------------------------------------------------
Dsrc/ldapctrl.c | 794-------------------------------------------------------------------------------
Dsrc/ldapctrl.h | 118-------------------------------------------------------------------------------
Dsrc/ldaplocate.c | 152-------------------------------------------------------------------------------
Dsrc/ldaplocate.h | 44--------------------------------------------
Dsrc/ldapquery.c | 1380-------------------------------------------------------------------------------
Dsrc/ldapquery.h | 102-------------------------------------------------------------------------------
Dsrc/ldapserver.c | 924-------------------------------------------------------------------------------
Dsrc/ldapserver.h | 115-------------------------------------------------------------------------------
Dsrc/ldapupdate.c | 1441-------------------------------------------------------------------------------
Dsrc/ldapupdate.h | 39---------------------------------------
Dsrc/ldaputil.c | 350-------------------------------------------------------------------------------
Dsrc/ldaputil.h | 59-----------------------------------------------------------
Dsrc/ldif.c | 1002-------------------------------------------------------------------------------
Dsrc/ldif.h | 125-------------------------------------------------------------------------------
Msrc/main.c | 138++++++++++++++++++++++++++++++++++++-------------------------------------------
Dsrc/pixmaps/jpilot.xpm | 181-------------------------------------------------------------------------------
Dsrc/pixmaps/ldap.xpm | 82-------------------------------------------------------------------------------
Msrc/prefs_toolbar.c | 2--
Msrc/stock_pixmap.c | 4----
Msrc/stock_pixmap.h | 14++++++--------
56 files changed, 692 insertions(+), 16612 deletions(-)

diff --git a/configure.ac b/configure.ac @@ -292,10 +292,6 @@ AC_ARG_ENABLE(dbus, [ --disable-dbus Do not build DBUS support], [enable_dbus=$enableval], [enable_dbus=yes]) -AC_ARG_ENABLE(ldap, - [ --disable-ldap Do not build LDAP support], - [enable_ldap=$enableval], [enable_ldap=yes]) - AC_ARG_ENABLE(jpilot, [ --disable-jpilot Do not build JPilot support], [enable_jpilot=$enableval], [enable_jpilot=yes]) @@ -328,10 +324,6 @@ AC_ARG_ENABLE(more-addressbook-debug, [ --enable-more-addressbook-debug Build with additional addressbook debug calls], [enable_more_addressbook_debug=$enableval], [enable_more_addressbook_debug=no]) -AC_ARG_ENABLE(more-ldap-debug, - [ --enable-more-ldap-debug Build with additional LDAP debug calls], - [enable_more_ldap_debug=$enableval], [enable_more_ldap_debug=no]) - AC_ARG_ENABLE(more-archive-debug, [ --enable-more-archive-debug Build with additional debug calls in archive plugin], [enable_more_archive_debug=$enableval], [enable_more_archive_debug=no]) @@ -609,13 +601,6 @@ dnl enchant is used for spell checking AC_MSG_CHECKING([whether to use enchant]) AC_MSG_RESULT($enable_enchant) if test $enable_enchant = yes; then - PKG_CHECK_MODULES(ENCHANT, enchant >= 1.4.0, - [ - AC_DEFINE(USE_ENCHANT, 1, enchant) - echo "Building with enchant" - enable_enchant=yes - ], - [ PKG_CHECK_MODULES(ENCHANT, enchant-2 >= 2.0.0, [ AC_DEFINE(USE_ENCHANT, 1, enchant-2) @@ -626,7 +611,6 @@ if test $enable_enchant = yes; then echo "Building without enchant-notification" enable_enchant=no ]) - ]) AC_SUBST(ENCHANT_CFLAGS) AC_SUBST(ENCHANT_LIBS) fi @@ -789,117 +773,6 @@ else fi dnl ####################################################################### -dnl # Check for old address book support -dnl ####################################################################### -if test x"$enable_alternate_addressbook" = xno; then - dnl for LDAP support in addressbook - dnl no check for libraries; dynamically loaded - AC_MSG_CHECKING([whether to use LDAP]) - if test x"$enable_ldap" = xno; then - AC_MSG_RESULT(no) - elif test x"$enable_ldap" = xyes -a x"$enable_pthread" = xno; then - AC_MSG_RESULT(no - LDAP support needs pthread support) - - enable_ldap=no - elif test x"$platform_win32" = xyes; then - AC_MSG_RESULT(yes) - AC_DEFINE(USE_LDAP, 1, Define if you want LDAP support in addressbook.) - LDAP_LIBS="-lwldap32" - AC_SUBST(LDAP_LIBS) - else - AC_MSG_RESULT(yes) - - dnl check for available libraries, and pull them in - AC_CHECK_LIB(resolv, res_query, LDAP_LIBS="$LDAP_LIBS -lresolv") - AC_CHECK_LIB(socket, bind, LDAP_LIBS="$LDAP_LIBS -lsocket") - AC_CHECK_LIB(nsl, gethostbyaddr, LDAP_LIBS="$LDAP_LIBS -lnsl") - AC_CHECK_LIB(lber, ber_get_tag, LDAP_LIBS="$LDAP_LIBS -llber",, - $LDAP_LIBS) - - AC_CHECK_HEADERS(ldap.h lber.h, - [ enable_ldap=yes ], - [ enable_ldap=no ]) - - if test "$enable_ldap" = yes; then - AC_CHECK_LIB(ldap, ldap_open, - [ enable_ldap=yes ], - [ enable_ldap=no ], - $LDAP_LIBS) - - AC_CHECK_LIB(ldap, ldap_start_tls_s, - [ ac_cv_have_tls=yes ], - [ ac_cv_have_tls=no ]) - - fi - - AC_MSG_CHECKING([whether ldap library is available]) - AC_MSG_RESULT($enable_ldap) - - AC_MSG_CHECKING([whether TLS library is available]) - AC_MSG_RESULT($ac_cv_have_tls) - - if test "$enable_ldap" = yes; then - AC_DEFINE(USE_LDAP, 1, Define if you want LDAP support in addressbook.) - LDAP_LIBS="$LDAP_LIBS -lldap" - AC_SUBST(LDAP_LIBS) - if test "$ac_cv_have_tls" = yes; then - AC_DEFINE(USE_LDAP_TLS, 1, Define if you want LDAP TLS support in addressbook.) - fi - dnl As of OpenLDAP API version 3000 a number of functions has - dnl been deprecated. As Claws-mail compiles and runs on many - dnl platforms and many versions of OpenLDAP we need to be able - dnl to switch between the old and new API because new API has - dnl added new functions replacing old ones and at the same time - dnl old functions has been changed. - dnl If cross-compiling defaults to enable deprecated features - dnl for maximum portability - AC_MSG_CHECKING([The API version of OpenLDAP]) - AC_RUN_IFELSE( - [AC_LANG_PROGRAM( - [#include <ldap.h>], - [if (LDAP_API_VERSION >= 3000) - return 1 - ])], - [AC_MSG_RESULT([version < 3000]) - AC_DEFINE(OPEN_LDAP_API_AT_LEAST_3000, 0, Define if OpenLDAP API is at least version 3000.)], - [AC_MSG_RESULT([version >= 3000]) - AC_DEFINE(OPEN_LDAP_API_AT_LEAST_3000, 1, Define if OpenLDAP API is at least version 3000.)], - [AC_MSG_RESULT([Enabling deprecated features in OpenLDAP]) - AC_DEFINE(OPEN_LDAP_API_AT_LEAST_3000, 0, Define if OpenLDAP API is at least version 3000.) - AC_DEFINE(LDAP_DEPRECATED, 1, Define to activate deprecated features in OpenLDAP)] - ) - fi - fi - - dnl for JPilot support in addressbook - dnl no check for libraries; these are dynamically loaded - AC_MSG_CHECKING([whether to use JPilot]) - if test "$enable_jpilot" = yes; then - AC_MSG_RESULT(yes) - AC_CHECK_HEADERS(pi-args.h pi-appinfo.h pi-address.h pi-version.h, - [ AC_DEFINE(USE_JPILOT, 1, Define if you want JPilot support in addressbook.) ], - [ enable_jpilot=no ]) - if test "$enable_jpilot" = no; then - AC_CHECK_HEADERS(libpisock/pi-args.h libpisock/pi-appinfo.h libpisock/pi-address.h libpisock/pi-version.h, - [ enable_jpilot=yes - AC_DEFINE(USE_JPILOT, 1, Define if you want JPilot support in addressbook.) ]) - fi - - AC_CHECK_LIB(pisock, unpack_Address, [JPILOT_LIBS="-lpisock"], [JPILOT_LIBS="" enable_jpilot="no"]) - if test x"$enable_jpilot" = xyes; then - AC_DEFINE(USE_JPILOT, 1, Define if you want JPilot support in addressbook.) - else - AC_MSG_NOTICE([JPilot support not available]) - fi - AC_SUBST(JPILOT_LIBS) - else - AC_MSG_RESULT(no) - fi -fi - -AM_CONDITIONAL(BUILD_ALTADDRBOOK, test x"$enable_alternate_addressbook" = x"yes") - -dnl ####################################################################### dnl # Check for NetworkManager support dnl ####################################################################### if test x"$enable_dbus" = xyes; then @@ -1046,15 +919,6 @@ else AC_MSG_RESULT(no) fi -AC_MSG_CHECKING([whether to build LDAP with more debug calls]) -if test x$enable_more_ldap_debug = xyes; then - more_debug_output_modules="$more_debug_output_modules LDAP" - AC_MSG_RESULT(yes) - AC_DEFINE(DEBUG_LDAP, 1, [Define if you want additional LDAP debug calls]) -else - AC_MSG_RESULT(no) -fi - AC_MSG_CHECKING([whether to build archive plugin with more debug calls]) if test x$enable_more_archive_debug = xyes; then more_debug_output_modules="$more_debug_output_modules ArchivePlugin" @@ -1356,7 +1220,7 @@ if test x"$HAVE_PERL" = xyes; then fi if test x"$HAVE_PERL" = xyes; then - AC_CHECK_LIB(perl,perl_alloc,[AC_DEFINE(HAVE_LIBPERL, 1, Check for libperl.)], + AC_CHECK_LIB(perl,perl_alloc,[AC_DEFINE(HAVE_LIBPERL, 1, Check for libperl.)], [ HAVE_LIBPERL=no ]) fi @@ -2242,10 +2106,6 @@ echo "$PACKAGE $VERSION" echo "" if test x"$enable_alternate_addressbook" = xyes; then echo "Using Address Book : Alternate experimental interface" -else - echo "Using Address Book : Original stable interface" - echo "JPilot : $enable_jpilot" - echo "LDAP : $enable_ldap" fi echo "gnuTLS : $enable_gnutls" echo "OAuth2 : $enable_oauth2" diff --git a/src/Makefile.am b/src/Makefile.am @@ -8,7 +8,7 @@ etpan_dir = etpan etpan_library = etpan/libclawsetpan.la else etpan_dir = -etpan_library = +etpan_library = endif SUBDIRS = common gtk $(etpan_dir) . plugins @@ -44,30 +44,15 @@ orig_abook_source = \ addrselect.c \ addrduplicates.c \ addrmerge.c \ - browseldap.c \ editaddress.c \ editaddress_other_attributes_ldap.c \ editbook.c \ editgroup.c \ - editjpilot.c \ - editldap_basedn.c \ - editldap.c \ editvcard.c \ exphtmldlg.c \ - expldifdlg.c \ exporthtml.c \ - exportldif.c \ - importldif.c \ importmutt.c \ importpine.c \ - jpilot.c \ - ldapctrl.c \ - ldaplocate.c \ - ldapquery.c \ - ldapserver.c \ - ldapupdate.c \ - ldaputil.c \ - ldif.c \ mutt.c \ pine.c \ vcard.c @@ -93,31 +78,16 @@ abook_headers = \ addrselect.h \ addrduplicates.h \ addrmerge.h \ - browseldap.h \ editaddress.h \ editaddress_other_attributes_ldap.h \ editbook.h \ editgroup.h \ - editjpilot.h \ - editldap_basedn.h \ - editldap.h \ editvcard.h \ exphtmldlg.h \ - expldifdlg.h \ exporthtml.h \ - exportldif.h \ file_checker.h \ - importldif.h \ importmutt.h \ importpine.h \ - jpilot.h \ - ldapctrl.h \ - ldaplocate.h \ - ldapquery.h \ - ldapserver.h \ - ldapupdate.h \ - ldaputil.h \ - ldif.h \ mutt.h \ pine.h \ vcard.h @@ -446,11 +416,9 @@ EXTRA_DIST = \ pixmaps/inbox_close_mark.xpm \ pixmaps/interface.xpm \ pixmaps/insert_file.xpm \ - pixmaps/jpilot.xpm \ pixmaps/key.xpm \ pixmaps/key_gpg_signed.xpm \ pixmaps/last_arrow.xpm \ - pixmaps/ldap.xpm \ pixmaps/left_arrow.xpm \ pixmaps/linewrap.xpm \ pixmaps/linewrapcurrent.xpm \ @@ -594,11 +562,9 @@ claws_mail_LDADD = \ $(ENCHANT_LIBS) \ $(INTLLIBS) \ $(GTK_LIBS) \ - $(LDAP_LIBS) \ $(GNUTLS_LIBS) \ $(NETTLE_LIBS) \ $(COMPFACE_LIBS) \ - $(JPILOT_LIBS) \ $(PTHREAD_LIBS) \ $(SM_LIBS) \ $(LIBICONV) \ @@ -642,7 +608,7 @@ quote_fmt_lex.$(OBJEXT) : AM_CFLAGS += -Wno-unused-function AM_YFLAGS = -d if CYGWIN -claws-mail$(EXEEXT): $(claws_mail_OBJECTS) $(claws_mail_DEPENDENCIES) +claws-mail$(EXEEXT): $(claws_mail_OBJECTS) $(claws_mail_DEPENDENCIES) @rm -f claws-mail$(EXEEXT) @rm -f claws-mail.def claws-mail.base claws-mail.exp libclaws-mail.a .libs/libclaws-mail.a $(LINK) -shared $(claws_mailLDFLAGS) -Wl,--out-implib=libclaws-mail.a -Wl,--export-all-symbols,--exclude-symbols,main $(claws_mail_OBJECTS) -Wl,--no-whole-archive $(claws_mail_LDADD) $(LIBS) @@ -653,7 +619,7 @@ claws-mail$(EXEEXT): $(claws_mail_OBJECTS) $(claws_mail_DEPENDENCIES) $(LINK) $(claws_mail_LDFLAGS) -Wl,claws-mail.exp $(claws_mail_OBJECTS) $(claws_mail_LDADD) $(LIBS) @cp libclaws-mail.a .libs/libclaws-mail.a else -#claws-mail$(EXEEXT): $(claws_mail_OBJECTS) $(claws_mail_DEPENDENCIES) +#claws-mail$(EXEEXT): $(claws_mail_OBJECTS) $(claws_mail_DEPENDENCIES) # @rm -f claws-mail$(EXEEXT) # $(LINK) $(claws_mail_LDFLAGS) $(claws_mail_OBJECTS) $(claws_mail_LDADD) $(LIBS) endif diff --git a/src/adbookbase.h b/src/adbookbase.h @@ -14,7 +14,7 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * */ /* @@ -32,8 +32,6 @@ typedef enum { ADBOOKTYPE_NONE, ADBOOKTYPE_BOOK, ADBOOKTYPE_VCARD, - ADBOOKTYPE_JPILOT, - ADBOOKTYPE_LDAP } AddressBookType; /* diff --git a/src/addrdefs.h b/src/addrdefs.h @@ -14,7 +14,7 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * */ /* @@ -27,7 +27,6 @@ /* Query types */ typedef enum { ADDRQUERY_NONE, - ADDRQUERY_LDAP } AddrQueryType; /* Search type */ diff --git a/src/addrduplicates.c b/src/addrduplicates.c @@ -13,7 +13,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifdef HAVE_CONFIG_H @@ -28,10 +28,6 @@ #include "defs.h" -#ifdef USE_LDAP -#include "ldapserver.h" -#include "ldapupdate.h" -#endif #include "addrduplicates.h" #include "addrbook.h" #include "addressbook.h" @@ -689,7 +685,7 @@ static void detail_row_activated(GtkTreeView *tree_view, gtk_tree_model_get(model, &iter, COL_ITEM, &person, COL_DS, &ds, -1); - if(!((ds->type == ADDR_IF_BOOK) || ds->type == ADDR_IF_LDAP)) { + if(!(ds->type == ADDR_IF_BOOK)) { debug_print("Unsupported address datasource type for editing\n"); return; } @@ -849,16 +845,6 @@ gboolean addrduplicates_delete_item_person(ItemPerson *item, AddressDataSource * item->status = DELETE_ENTRY; item = addrbook_remove_person(abf, item); -#ifdef USE_LDAP - - if (ds && ds->type == ADDR_IF_LDAP) { - LdapServer *server = ds->rawDataSource; - ldapsvr_set_modified(server, TRUE); - ldapsvr_update_book(server, item); - } - -#endif - if(item) { addritem_person_remove_picture(item); addritem_free_item_person(item); diff --git a/src/addressadd.c b/src/addressadd.c @@ -41,8 +41,6 @@ #include "addritem.h" #include "addrbook.h" #include "addrindex.h" - #include "ldapserver.h" - #include "ldapupdate.h" #else #include "addressbook-dbus.h" #endif @@ -196,7 +194,7 @@ static void addressadd_create( void ) { G_CALLBACK(addressadd_key_pressed), NULL ); g_signal_connect(G_OBJECT(window), "size_allocate", G_CALLBACK(addressadd_size_allocate_cb), NULL); - + hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 10); gtk_container_set_border_width(GTK_CONTAINER(hbox), 4); vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8); @@ -224,7 +222,7 @@ static void addressadd_create( void ) { entry_name = gtk_entry_new(); gtk_widget_set_size_request(entry_name, 150, -1); gtk_entry_set_text (GTK_ENTRY(entry_name),""); - + gtk_grid_attach(GTK_GRID(table), entry_name, 1, 0, 1, 1); gtk_widget_set_hexpand(entry_name, TRUE); gtk_widget_set_halign(entry_name, GTK_ALIGN_FILL); @@ -410,8 +408,7 @@ static void addressadd_load_data( AddressIndex *addrIndex ) { list = addrindex_get_interface_list( addrIndex ); while( list ) { AddressInterface *ainterface = list->data; - if( ainterface->type == ADDR_IF_BOOK || - ainterface->type == ADDR_IF_LDAP ) { + if(ainterface->type == ADDR_IF_BOOK) { nodeDS = ainterface->listSource; while( nodeDS ) { ds = nodeDS->data; @@ -475,15 +472,15 @@ static void addressadd_load_data() { } #endif -#ifndef USE_ALT_ADDRBOOK -gboolean addressadd_selection( AddressIndex *addrIndex, const gchar *name, +#ifndef USE_ALT_ADDRBOOK +gboolean addressadd_selection( AddressIndex *addrIndex, const gchar *name, const gchar *address, const gchar *remarks, GdkPixbuf *picture ) { #else gboolean addressadd_selection(const gchar *name, const gchar *address, const gchar *remarks, GdkPixbuf *picture ) { #endif gboolean retVal = FALSE; -#ifndef USE_ALT_ADDRBOOK +#ifndef USE_ALT_ADDRBOOK ItemPerson *person = NULL; #endif FolderInfo *fi = NULL; @@ -529,19 +526,19 @@ gboolean addressadd_selection(const gchar *name, const gchar *address, returned_remarks = gtk_editable_get_chars( GTK_EDITABLE(addressadd_dlg.entry_remarks), 0, -1 ); fi = addressadd_dlg.fiSelected; - + #ifndef USE_ALT_ADDRBOOK - person = addrbook_add_contact( fi->book, fi->folder, - returned_name, - address, + person = addrbook_add_contact( fi->book, fi->folder, + returned_name, + address, returned_remarks); - + if (person != NULL) { person->status = ADD_ENTRY; if (picture) { GError *error = NULL; - gchar *name = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, ADDRBOOK_DIR, G_DIR_SEPARATOR_S, + gchar *name = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, ADDRBOOK_DIR, G_DIR_SEPARATOR_S, ADDRITEM_ID(person), ".png", NULL ); gdk_pixbuf_save(picture, name, "png", &error, NULL); if (error) { @@ -555,18 +552,18 @@ gboolean addressadd_selection(const gchar *name, const gchar *address, #else ContactData* contact = g_new0(ContactData, 1); GError* error = NULL; - + if (returned_name) contact->cn = g_strdup(returned_name); else contact->cn = g_strdup(address); - + contact->name = g_strdup(returned_name); contact->email = g_strdup(address); contact->remarks = g_strdup(returned_remarks); contact->book = g_strdup(fi->book); contact->picture = picture; - + if (addressbook_dbus_add_contact(contact, &error) == 0) { debug_print("Added to addressbook:\n%s\n%s\n%s\n%s\n", returned_name, address, returned_remarks, fi->book); @@ -588,20 +585,6 @@ gboolean addressadd_selection(const gchar *name, const gchar *address, } contact_data_free(&contact); #endif -#ifdef USE_LDAP - if (person != NULL && fi->book->type == ADBOOKTYPE_LDAP) { - LdapServer *server = (LdapServer *) fi->book; - ldapsvr_set_modified(server, TRUE); - ldapsvr_update_book(server, person); - if (server->retVal != LDAPRC_SUCCESS) { - alertpanel( _("Add address(es)"), - _("Can't add the specified address"), - "window-close", _("_Close"), NULL, NULL, - NULL, NULL, ALERTFOCUS_FIRST ); - return server->retVal; - } - } -#endif g_free(returned_name); g_free(returned_remarks); #ifndef USE_ALT_ADDRBOOK diff --git a/src/addressbook.c b/src/addressbook.c @@ -65,33 +65,16 @@ #include "editgroup.h" #include "editaddress.h" #include "editbook.h" -#include "importldif.h" #include "importmutt.h" #include "importpine.h" #include "manual.h" -#ifdef USE_JPILOT -#include "jpilot.h" -#include "editjpilot.h" -#endif - -#ifdef USE_LDAP -#include <pthread.h> -#include "ldapserver.h" -#include "editldap.h" -#include "ldapupdate.h" - -#define ADDRESSBOOK_LDAP_BUSYMSG "Busy" -#endif - #include "addrquery.h" #include "addrselect.h" #include "addrclip.h" #include "addrgather.h" #include "adbookbase.h" #include "exphtmldlg.h" -#include "expldifdlg.h" -#include "browseldap.h" #include "addrcustomattr.h" #ifdef G_OS_WIN32 #undef interface @@ -143,9 +126,7 @@ static GdkPixbuf *interfacexpm = NULL; static GdkPixbuf *bookxpm = NULL; static GdkPixbuf *addressxpm = NULL; static GdkPixbuf *vcardxpm = NULL; -static GdkPixbuf *jpilotxpm = NULL; static GdkPixbuf *categoryxpm = NULL; -static GdkPixbuf *ldapxpm = NULL; static GdkPixbuf *addrsearchxpm = NULL; /* Message buffer */ @@ -257,16 +238,6 @@ static void addressbook_new_book_cb (GtkAction *action, static void addressbook_new_vcard_cb (GtkAction *action, gpointer data); -#ifdef USE_JPILOT -static void addressbook_new_jpilot_cb (GtkAction *action, - gpointer data); -#endif - -#ifdef USE_LDAP -static void addressbook_new_ldap_cb (GtkAction *action, - gpointer data); -#endif - static void addressbook_set_clist (AddressObject *obj, gboolean refresh); @@ -302,11 +273,11 @@ static gboolean addressbook_entry_key_pressed (GtkWidget *widget, static gint addressbook_treenode_compare_func (GtkCMCList *clist, gconstpointer ptr1, gconstpointer ptr2); -static void addressbook_folder_load_one_person (GtkCMCTree *clist, - ItemPerson *person, - AddressTypeControlItem *atci, +static void addressbook_folder_load_one_person (GtkCMCTree *clist, + ItemPerson *person, + AddressTypeControlItem *atci, AddressTypeControlItem *atciMail); -static void addressbook_folder_remove_node (GtkCMCTree *clist, +static void addressbook_folder_remove_node (GtkCMCTree *clist, GtkCMCTreeNode *node); static void addressbook_edit_address( gpointer data, guint action, GtkWidget *widget, @@ -332,13 +303,11 @@ static void addressbook_list_select_add ( AddrItemObject *aio, AddressDataSource *ds ); static void addressbook_list_select_remove ( AddrItemObject *aio ); -static void addressbook_import_ldif_cb ( GtkAction *action, gpointer data ); static void addressbook_find_duplicates_cb ( GtkAction *action, gpointer data ); static void addressbook_edit_custom_attr_cb ( GtkAction *action, gpointer data ); static void addressbook_import_mutt_cb ( GtkAction *action, gpointer data ); static void addressbook_import_pine_cb ( GtkAction *action, gpointer data ); static void addressbook_export_html_cb ( GtkAction *action, gpointer data ); -static void addressbook_export_ldif_cb ( GtkAction *action, gpointer data ); static void addressbook_select_all_cb ( GtkAction *action, gpointer data ); static void addressbook_clip_cut_cb ( GtkAction *action, gpointer data ); static void addressbook_clip_copy_cb ( GtkAction *action, gpointer data ); @@ -350,12 +319,9 @@ static void addressbook_treenode_paste_cb ( GtkAction *action, gpointer data ); static void addressbook_mail_to_cb ( GtkAction *action, gpointer data ); static void addressbook_merge_cb ( GtkAction *action, gpointer data ); -#ifdef USE_LDAP -static void addressbook_browse_entry_cb ( GtkAction *action, gpointer data ); -#endif static void addressbook_edit_clicked(GtkButton *button, gpointer data); -static void addressbook_start_drag(GtkWidget *widget, gint button, +static void addressbook_start_drag(GtkWidget *widget, gint button, GdkEvent *event, void *data); static void addressbook_drag_data_get(GtkWidget *widget, @@ -398,19 +364,12 @@ static GtkActionEntry addressbook_entries[] = {"Book", NULL, N_("_Book"), NULL, NULL, NULL }, {"Edit", NULL, N_("_Edit"), NULL, NULL, NULL }, {"Tools", NULL, N_("_Tools"), NULL, NULL, NULL }, - + /* Book menu */ {"Book/NewBook", NULL, N_("New _Book"), "<control>B", NULL, G_CALLBACK(addressbook_new_book_cb) }, {"Book/NewFolder", NULL, N_("New _Folder"), "<control>R", NULL, G_CALLBACK(addressbook_new_folder_cb) }, {"Book/NewVCard", NULL, N_("New _vCard"), "<control><shift>D", NULL, G_CALLBACK(addressbook_new_vcard_cb) }, - -#ifdef USE_JPILOT - {"Book/NewJPilot", NULL, N_("New _JPilot"), "<control>J", NULL, G_CALLBACK(addressbook_new_jpilot_cb) }, -#endif -#ifdef USE_LDAP - {"Book/NewLDAPServer", NULL, N_("New LDAP _Server"), "<control><shift>S", NULL, G_CALLBACK(addressbook_new_ldap_cb) }, -#endif {"Book/---", NULL, "---", NULL, NULL, NULL }, {"Book/EditBook", NULL, N_("_Edit book"), NULL, NULL, G_CALLBACK(addressbook_treenode_edit_cb) }, @@ -436,14 +395,10 @@ static GtkActionEntry addressbook_entries[] = {"Address/Merge", NULL, N_("_Merge"), "<control>E", NULL, G_CALLBACK(addressbook_merge_cb) }, -/* Tools menu */ - {"Tools/ImportLDIF", NULL, N_("Import _LDIF file..."), NULL, NULL, G_CALLBACK(addressbook_import_ldif_cb) }, {"Tools/ImportMutt", NULL, N_("Import M_utt file..."), NULL, NULL, G_CALLBACK(addressbook_import_mutt_cb) }, {"Tools/ImportPine", NULL, N_("Import _Pine file..."), NULL, NULL, G_CALLBACK(addressbook_import_pine_cb) }, {"Tools/---", NULL, "---", NULL, NULL, NULL }, {"Tools/ExportHTML", NULL, N_("Export _HTML..."), NULL, NULL, G_CALLBACK(addressbook_export_html_cb) }, - {"Tools/ExportLDIF", NULL, N_("Export LDI_F..."), NULL, NULL, G_CALLBACK(addressbook_export_ldif_cb) }, - /* {"Tools/---", NULL, "---", NULL, NULL, NULL },*/ {"Tools/FindDuplicates", NULL, N_("Find duplicates..."), NULL, NULL, G_CALLBACK(addressbook_find_duplicates_cb) }, {"Tools/EditAttrs", NULL, N_("Edit custom attributes..."), NULL, NULL, G_CALLBACK(addressbook_edit_custom_attr_cb) }, }; @@ -479,9 +434,6 @@ static GtkActionEntry addressbook_list_popup_entries[] = {"ABListPopup/Paste", NULL, N_("_Paste"), NULL, NULL, G_CALLBACK(addressbook_clip_paste_cb) }, /* {"ABListPopup/---", NULL, "---", NULL, NULL, NULL }, */ {"ABListPopup/Mailto", NULL, N_("_Mail To"), NULL, NULL, G_CALLBACK(addressbook_mail_to_cb) }, -#ifdef USE_LDAP - {"ABListPopup/BrowseEntry", NULL, N_("_Browse Entry"), NULL, NULL, G_CALLBACK(addressbook_browse_entry_cb) }, -#endif {"ABListPopup/Merge", NULL, N_("_Merge"), NULL, NULL, G_CALLBACK(addressbook_merge_cb) }, }; @@ -515,29 +467,6 @@ static ErrMsgTableEntry _lutErrorsGeneral_[] = { { 0, NULL } }; -#ifdef USE_LDAP -/** - * Lookup table of error messages for LDAP errors. - */ -static ErrMsgTableEntry _lutErrorsLDAP_[] = { - { LDAPRC_SUCCESS, N_("Success") }, - { LDAPRC_CONNECT, N_("Error connecting to LDAP server") }, - { LDAPRC_INIT, N_("Error initializing LDAP") }, - { LDAPRC_BIND, N_("Error binding to LDAP server") }, - { LDAPRC_SEARCH, N_("Error searching LDAP database") }, - { LDAPRC_TIMEOUT, N_("Timeout performing LDAP operation") }, - { LDAPRC_CRITERIA, N_("Error in LDAP search criteria") }, - { LDAPRC_NOENTRIES, N_("No LDAP entries found for search criteria") }, - { LDAPRC_STOP_FLAG, N_("LDAP search terminated on request") }, - { LDAPRC_TLS, N_("Error starting STARTTLS connection") }, - { LDAPRC_NODN, N_("Distinguished Name (dn) is missing") }, - { LDAPRC_NAMING_VIOLATION, N_("Missing required information") }, - { LDAPRC_ALREADY_EXIST, N_("Another contact exists with that key") }, - { LDAPRC_STRONG_AUTH, N_("Strong(er) authentication required") }, - { 0, NULL } -}; -#endif - /** * Lookup message for specified error code. * \param lut Lookup table. @@ -576,7 +505,7 @@ static void addressbook_show_buttons(gboolean add_and_delete, gboolean lookup, g gtk_widget_hide(addrbook.del_btn); gtk_widget_hide(addrbook.reg_btn); } - + if (lookup) { gtk_widget_show(addrbook.lup_btn); gtk_widget_show(addrbook.entry); @@ -721,9 +650,9 @@ static gint list_case_sort( AddrItemObject *aio2 = ((GtkCMCListRow *)ptr2)->data; if( aio1->type == aio2->type ) { - if( row1 ) + if( row1 ) name1 = GTK_CMCELL_TEXT (row1->cell[sort_column_number])->text; - if( row2 ) + if( row2 ) name2 = GTK_CMCELL_TEXT (row2->cell[sort_column_number])->text; if( ! name1 ) return ( name2 != NULL ); if( ! name2 ) return -1; @@ -749,33 +678,33 @@ static void addressbook_sort_list(GtkCMCList *clist, const gint col, sort_column_type = sort_type; gtk_cmclist_set_compare_func(clist, list_case_sort); gtk_cmclist_set_sort_type(clist, sort_type); - gtk_cmclist_set_sort_column(clist, col); + gtk_cmclist_set_sort_column(clist, col); gtk_cmclist_freeze(clist); gtk_cmclist_sort(clist); - + for(pos = 0 ; pos < N_LIST_COLS ; pos++) { hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4); label = gtk_label_new(gettext(list_titles[pos])); gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); - + if(pos == col) { arrow = gtk_image_new_from_icon_name(sort_type == GTK_SORT_ASCENDING ? "pan-down-symbolic" : "pan-up-symbolic", GTK_ICON_SIZE_MENU); gtk_box_pack_end(GTK_BOX(hbox), arrow, FALSE, FALSE, 0); } - + gtk_widget_show_all(hbox); gtk_cmclist_set_column_widget(clist, pos, hbox); } - - gtk_cmclist_thaw(clist); + + gtk_cmclist_thaw(clist); } static void addressbook_name_clicked(GtkWidget *button, GtkCMCList *clist) { static GtkSortType sort_type = GTK_SORT_ASCENDING; - + sort_type = (sort_type == GTK_SORT_ASCENDING) ? GTK_SORT_DESCENDING : GTK_SORT_ASCENDING; addressbook_sort_list(clist, COL_NAME, sort_type); @@ -837,10 +766,10 @@ static gboolean addressbook_address_list_focus_evt_out(GtkWidget *widget, GdkEve static void addressbook_pane_save_position(void) { if (addrbook.hpaned) - prefs_common.addressbook_hpaned_pos = + prefs_common.addressbook_hpaned_pos = gtk_paned_get_position(GTK_PANED(addrbook.hpaned)); if (addrbook.vpaned) - prefs_common.addressbook_vpaned_pos = + prefs_common.addressbook_vpaned_pos = gtk_paned_get_position(GTK_PANED(addrbook.vpaned)); } @@ -940,12 +869,6 @@ static void addressbook_create(void) MENUITEM_ADDUI_MANAGER(ui_manager, "/Menu/Book", "NewBook", "Book/NewBook", GTK_UI_MANAGER_MENUITEM) MENUITEM_ADDUI_MANAGER(ui_manager, "/Menu/Book", "NewFolder", "Book/NewFolder", GTK_UI_MANAGER_MENUITEM) MENUITEM_ADDUI_MANAGER(ui_manager, "/Menu/Book", "NewVCard", "Book/NewVCard", GTK_UI_MANAGER_MENUITEM) -#ifdef USE_JPILOT - MENUITEM_ADDUI_MANAGER(ui_manager, "/Menu/Book", "NewJPilot", "Book/NewJPilot", GTK_UI_MANAGER_MENUITEM) -#endif -#ifdef USE_LDAP - MENUITEM_ADDUI_MANAGER(ui_manager, "/Menu/Book", "NewLDAPServer", "Book/NewLDAPServer", GTK_UI_MANAGER_MENUITEM) -#endif MENUITEM_ADDUI_MANAGER(ui_manager, "/Menu/Book", "Separator1", "Book/---", GTK_UI_MANAGER_SEPARATOR) MENUITEM_ADDUI_MANAGER(ui_manager, "/Menu/Book", "EditBook", "Book/EditBook", GTK_UI_MANAGER_MENUITEM) MENUITEM_ADDUI_MANAGER(ui_manager, "/Menu/Book", "DeleteBook", "Book/DeleteBook", GTK_UI_MANAGER_MENUITEM) @@ -969,13 +892,10 @@ static void addressbook_create(void) MENUITEM_ADDUI_MANAGER(ui_manager, "/Menu/Edit", "Mailto", "Address/Mailto", GTK_UI_MANAGER_MENUITEM) MENUITEM_ADDUI_MANAGER(ui_manager, "/Menu/Edit", "Merge", "Address/Merge", GTK_UI_MANAGER_MENUITEM) -/* Tools menu */ - MENUITEM_ADDUI_MANAGER(ui_manager, "/Menu/Tools", "ImportLDIF", "Tools/ImportLDIF", GTK_UI_MANAGER_MENUITEM) MENUITEM_ADDUI_MANAGER(ui_manager, "/Menu/Tools", "ImportMutt", "Tools/ImportMutt", GTK_UI_MANAGER_MENUITEM) MENUITEM_ADDUI_MANAGER(ui_manager, "/Menu/Tools", "ImportPine", "Tools/ImportPine", GTK_UI_MANAGER_MENUITEM) MENUITEM_ADDUI_MANAGER(ui_manager, "/Menu/Tools", "Separator1", "Tools/---", GTK_UI_MANAGER_SEPARATOR) MENUITEM_ADDUI_MANAGER(ui_manager, "/Menu/Tools", "ExportHTML", "Tools/ExportHTML", GTK_UI_MANAGER_MENUITEM) - MENUITEM_ADDUI_MANAGER(ui_manager, "/Menu/Tools", "ExportLDIF", "Tools/ExportLDIF", GTK_UI_MANAGER_MENUITEM) MENUITEM_ADDUI_MANAGER(ui_manager, "/Menu/Tools", "Separator2", "Tools/---", GTK_UI_MANAGER_SEPARATOR) MENUITEM_ADDUI_MANAGER(ui_manager, "/Menu/Tools", "FindDuplicates", "Tools/FindDuplicates", GTK_UI_MANAGER_MENUITEM) MENUITEM_ADDUI_MANAGER(ui_manager, "/Menu/Tools", "EditAttrs", "Tools/EditAttrs", GTK_UI_MANAGER_MENUITEM) @@ -1094,7 +1014,7 @@ static void addressbook_create(void) g_signal_connect(G_OBJECT(clist), "start_drag", G_CALLBACK(addressbook_start_drag), NULL); g_signal_connect(G_OBJECT(clist), "drag_data_get", - G_CALLBACK(addressbook_drag_data_get), NULL); + G_CALLBACK(addressbook_drag_data_get), NULL); hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4); gtk_box_pack_start(GTK_BOX(clist_vbox), hbox, FALSE, FALSE, 0); @@ -1247,7 +1167,7 @@ static void addressbook_create(void) MENUITEM_ADDUI_MANAGER(ui_manager, "/Popups/ABTreePopup", "Cut", "ABTreePopup/Cut", GTK_UI_MANAGER_MENUITEM) MENUITEM_ADDUI_MANAGER(ui_manager, "/Popups/ABTreePopup", "Copy", "ABTreePopup/Copy", GTK_UI_MANAGER_MENUITEM) MENUITEM_ADDUI_MANAGER(ui_manager, "/Popups/ABTreePopup", "Paste", "ABTreePopup/Paste", GTK_UI_MANAGER_MENUITEM) - + tree_popup = gtk_menu_item_get_submenu(GTK_MENU_ITEM( gtk_ui_manager_get_widget(ui_manager, "/Popups/ABTreePopup"))); @@ -1265,9 +1185,6 @@ static void addressbook_create(void) MENUITEM_ADDUI_MANAGER(ui_manager, "/Popups/ABListPopup", "Paste", "ABListPopup/Paste", GTK_UI_MANAGER_MENUITEM) MENUITEM_ADDUI_MANAGER(ui_manager, "/Popups/ABListPopup", "Separator4", "ABListPopup/---", GTK_UI_MANAGER_SEPARATOR) MENUITEM_ADDUI_MANAGER(ui_manager, "/Popups/ABListPopup", "Mailto", "ABListPopup/Mailto", GTK_UI_MANAGER_MENUITEM) -#ifdef USE_LDAP - MENUITEM_ADDUI_MANAGER(ui_manager, "/Popups/ABListPopup", "BrowseEntry", "ABListPopup/BrowseEntry", GTK_UI_MANAGER_MENUITEM) -#endif MENUITEM_ADDUI_MANAGER(ui_manager, "/Popups/ABListPopup", "Merge", "ABListPopup/Merge", GTK_UI_MANAGER_MENUITEM) list_popup = gtk_menu_item_get_submenu(GTK_MENU_ITEM( gtk_ui_manager_get_widget(ui_manager, "/Popups/ABListPopup"))); @@ -1317,11 +1234,11 @@ static void addressbook_create(void) if (!prefs_common.addressbook_use_editaddress_dialog) { if (prefs_common.addressbook_vpaned_pos > 0) - gtk_paned_set_position(GTK_PANED(vpaned), + gtk_paned_set_position(GTK_PANED(vpaned), prefs_common.addressbook_vpaned_pos); - } + } if (prefs_common.addressbook_hpaned_pos > 0) - gtk_paned_set_position(GTK_PANED(hpaned), + gtk_paned_set_position(GTK_PANED(hpaned), prefs_common.addressbook_hpaned_pos); @@ -1335,9 +1252,9 @@ static gint addressbook_close( void ) { address_completion_end(addrbook.window); if (!prefs_common.addressbook_use_editaddress_dialog) addressbook_edit_person_invalidate(NULL, NULL, NULL); - + addressbook_pane_save_position(); - + gtk_widget_hide(addrbook.window); addressbook_export_to_file(); return TRUE; @@ -1374,7 +1291,7 @@ static void addressbook_ds_show_message( AddressDataSource *ds ) { } else { desc = addressbook_err2string( _lutErrorsGeneral_, retVal ); - g_snprintf( addressbook_msgbuf, + g_snprintf( addressbook_msgbuf, sizeof(addressbook_msgbuf), "%s: %s", name, desc ); } } @@ -1410,7 +1327,7 @@ static void addressbook_del_clicked(GtkButton *button, gpointer data) AddrSelectItem *item; GList *list, *node; gboolean refreshList = FALSE; - + pobj = gtk_cmctree_node_get_row_data(ctree, addrbook.opened ); cm_return_if_fail(pobj != NULL); @@ -1487,7 +1404,7 @@ static void addressbook_del_clicked(GtkButton *button, gpointer data) goto thaw_ret; } } - + /* first, set lists of groups and persons to remove */ node = list; while( node ) { @@ -1552,18 +1469,11 @@ static void addressbook_del_clicked(GtkButton *button, gpointer data) continue; if( aio->type == ITEMTYPE_PERSON ) { ItemPerson *item = ( ItemPerson * ) aio; - item->status = DELETE_ENTRY; + item->status = DELETE_ENTRY; addressbook_folder_remove_one_person( clist, item ); if (pobj->type == ADDR_ITEM_FOLDER) addritem_folder_remove_person(ADAPTER_FOLDER(pobj)->itemFolder, item); item = addrbook_remove_person( abf, item ); -#ifdef USE_LDAP - if (ds && ds->type == ADDR_IF_LDAP) { - LdapServer *server = ds->rawDataSource; - ldapsvr_set_modified(server, TRUE); - ldapsvr_update_book(server, item); - } -#endif if( item ) { addritem_person_remove_picture(item); addritem_free_item_person( item ); @@ -1631,7 +1541,7 @@ static void addressbook_del_clicked(GtkButton *button, gpointer data) gtk_cmctree_node_get_row_data(GTK_CMCTREE(addrbook.ctree), addrbook.opened), TRUE); - + addrbook_set_dirty(abf, TRUE); addressbook_export_to_file(); addressbook_list_menu_setup(); @@ -1755,7 +1665,7 @@ static void addressbook_to_clicked(GtkButton *button, gpointer data) AddressObject *obj = NULL; obj = gtk_cmctree_node_get_row_data( GTK_CMCTREE(addrbook.ctree), addrbook.treeSelected ); - + if( obj && obj->type == ADDR_ITEM_GROUP ) { ItemGroup *itemGroup = ADAPTER_GROUP(obj)->itemGroup; GList *nodeMail = itemGroup->listEMail; @@ -1868,9 +1778,7 @@ static void addressbook_menuitem_set_sensitive( AddressObject *obj, GtkCMCTreeNo cm_menu_set_sensitive_full( addrbook.ui_manager, "Menu/Book/EditBook", canEditTr ); cm_menu_set_sensitive_full( addrbook.ui_manager, "Menu/Book/DeleteBook", canEditTr ); - /* Export data */ cm_menu_set_sensitive_full( addrbook.ui_manager, "Menu/Tools/ExportHTML", canExport ); - cm_menu_set_sensitive_full( addrbook.ui_manager, "Menu/Tools/ExportLDIF", canExport ); } /** @@ -1910,7 +1818,7 @@ static void addressbook_tree_selected(GtkCMCTree *ctree, GtkCMCTreeNode *node, ads = ADAPTER_DSOURCE(obj); ds = ads->dataSource; - if( ds == NULL ) return; + if( ds == NULL ) return; if( addrindex_ds_get_modify_flag( ds ) ) { addrindex_ds_read_data( ds ); @@ -1929,15 +1837,7 @@ static void addressbook_tree_selected(GtkCMCTree *ctree, GtkCMCTreeNode *node, /* Load folders into the tree */ rootFolder = addrindex_ds_get_root_folder( ds ); - if( ds && ds->type == ADDR_IF_JPILOT ) { - aot = ADDR_CATEGORY; - } - else if( ds && ds->type == ADDR_IF_LDAP ) { - aot = ADDR_LDAP_QUERY; - } - else { - aot = ADDR_ITEM_FOLDER; - } + aot = ADDR_ITEM_FOLDER; addressbook_node_add_folder( node, ds, rootFolder, aot ); addrindex_ds_set_access_flag( ds, &tVal ); gtk_cmctree_expand( ctree, node ); @@ -2008,8 +1908,7 @@ static void addressbook_list_menu_setup( void ) { return; if( ! iface->readOnly ) { cm_menu_set_sensitive_full( addrbook.ui_manager, "Popups/ABListPopup/NewAddress", TRUE ); - if (iface->type != ADDR_IF_LDAP) - cm_menu_set_sensitive_full( addrbook.ui_manager, "Popups/ABListPopup/NewGroup", TRUE ); + cm_menu_set_sensitive_full( addrbook.ui_manager, "Popups/ABListPopup/NewGroup", TRUE ); gtk_widget_set_sensitive( addrbook.reg_btn, TRUE ); if( obj ) canEdit = TRUE; @@ -2033,17 +1932,11 @@ static void addressbook_list_menu_setup( void ) { } /* Folder */ if( pobj->type == ADDR_ITEM_FOLDER ) { - if (iface->type != ADDR_IF_LDAP) - cm_menu_set_sensitive_full( addrbook.ui_manager, "Popups/ABListPopup/NewGroup", TRUE ); + cm_menu_set_sensitive_full( addrbook.ui_manager, "Popups/ABListPopup/NewGroup", TRUE ); if( obj ) canEdit = TRUE; } canDelete = canEdit; } - if( iface->type == ADDR_IF_LDAP ) { - if( obj ) canBrowse = TRUE; - canEdit = TRUE; - canDelete = TRUE; - } } if( iface ) { @@ -2106,13 +1999,10 @@ static void addressbook_list_menu_setup( void ) { gtk_widget_set_sensitive( addrbook.del_btn, canDelete ); if (addrbook.target_compose) { - gtk_widget_set_sensitive(addrbook.to_btn, obj ? TRUE : FALSE); + gtk_widget_set_sensitive(addrbook.to_btn, obj ? TRUE : FALSE); gtk_widget_set_sensitive(addrbook.cc_btn, obj ? TRUE : FALSE); gtk_widget_set_sensitive(addrbook.bcc_btn, obj ? TRUE : FALSE); } -#ifdef USE_LDAP - cm_menu_set_sensitive_full( addrbook.ui_manager, "Popups/ABListPopup/BrowseEntry", canBrowse ); -#endif } static void addressbook_select_row_tree (GtkCMCTree *ctree, @@ -2259,7 +2149,7 @@ static void addressbook_clip_paste_cb( GtkAction *action, gpointer data ) { gtk_cmctree_node_get_row_data(GTK_CMCTREE(addrbook.ctree), addrbook.opened), TRUE); - + } @@ -2534,7 +2424,7 @@ static gboolean addressbook_tree_button_pressed(GtkWidget *ctree, gboolean canTreePaste = FALSE; gboolean canLookup = FALSE; GtkCMCTreeNode *node = NULL; - + if( ! event ) return FALSE; /* if( ! event || event->type != GDK_BUTTON_PRESS) return FALSE;*/ @@ -2823,18 +2713,7 @@ static gchar *addressbook_edit_datasource( AddressObject *obj, GtkCMCTreeNode *n } else if( ads->subType == ADDR_VCARD ) { if( addressbook_edit_vcard( _addressIndex_, ads ) == NULL ) return NULL; - } -#ifdef USE_JPILOT - else if( ads->subType == ADDR_JPILOT ) { - if( addressbook_edit_jpilot( _addressIndex_, ads ) == NULL ) return NULL; - } -#endif -#ifdef USE_LDAP - else if( ads->subType == ADDR_LDAP ) { - if( addressbook_edit_ldap( _addressIndex_, ads ) == NULL ) return NULL; - } -#endif - else { + } else { return NULL; } newName = obj->name; @@ -3004,11 +2883,11 @@ static void addressbook_treenode_delete_cb(GtkAction *action, gpointer data) if( obj->type == ADDR_DATASOURCE ) { /* Remove node from tree */ gtk_cmctree_remove_node( ctree, node ); - + if (delType == ADDRTREE_DEL_DATA && ds->interface && ds->interface->type == ADDR_IF_BOOK) addrbook_delete_book_file((AddressBookFile *) ds->rawDataSource); - + /* Remove data source. */ if( addrindex_index_remove_datasource( _addressIndex_, ds ) ) { addrindex_free_datasource( ds ); @@ -3141,21 +3020,13 @@ static ItemFolder * addressbook_setup_subf( GList *children; /* Setup a query */ if( *title == '\0' || strlen( title ) < 1 ) return NULL; - - if( ds && ds->type == ADDR_IF_LDAP ) { -#if USE_LDAP - aoType = ADDR_LDAP_QUERY; -#endif - } - else { - return NULL; - } + return NULL; ctree = GTK_CMCTREE(addrbook.ctree); - /* Get reference to address cache */ + /* Get reference to address cache */ adbase = ( AddrBookBase * ) ds->rawDataSource; cache = adbase->addressCache; - + if ((children = addrcache_get_list_folder(cache)) != NULL) { GList *cur = children; for (; cur; cur = cur->next) { @@ -3176,12 +3047,12 @@ static ItemFolder * addressbook_setup_subf( } gtk_sctree_select( GTK_SCTREE(ctree), nNode ); addrbook.treeSelected = nNode; - } + } return child; } } } - + /* Create a folder */ folder = addrcache_add_new_folder( cache, NULL ); name = g_strdup_printf( "%s", title ); @@ -3223,52 +3094,13 @@ static void addressbook_new_address_cb( GtkAction *action, gpointer data ) { } if( pobj->type == ADDR_DATASOURCE ) { - if (ADAPTER_DSOURCE(pobj)->subType == ADDR_BOOK || - ADAPTER_DSOURCE(pobj)->subType == ADDR_LDAP) { + if (ADAPTER_DSOURCE(pobj)->subType == ADDR_BOOK) { ItemPerson *person; ItemFolder *folder = NULL; -#ifdef USE_LDAP - if (abf && abf->type == ADBOOKTYPE_LDAP) { - GtkCMCTreeNode *parentNode; - ds = addressbook_find_datasource( GTK_CMCTREE_NODE( addrbook.treeSelected ) ); - if( ds == NULL ) return; - - /* We must have a datasource that is an external interface */ - if( ! ds->interface->haveLibrary ) return; - if( ! ds->interface->externalQuery ) return; - - if( pobj->type == ADDR_ITEM_FOLDER ) { - parentNode = GTK_CMCTREE_ROW(GTK_CMCTREE_NODE( addrbook.treeSelected ) )->parent; - } - else { - parentNode = GTK_CMCTREE_NODE( addrbook.treeSelected ); - } - folder = addressbook_setup_subf( ds, _("New Contacts"), parentNode ); - - ds = addressbook_find_datasource( GTK_CMCTREE_NODE(addrbook.treeSelected) ); - if (ds) - abf = ds->rawDataSource; - } -#endif person = addressbook_edit_person( abf, folder, NULL, FALSE, addrbook.editaddress_vbox, addressbook_new_address_from_book_post_cb, TRUE ); -#ifdef USE_LDAP - if (ds && abf && abf->type == ADBOOKTYPE_LDAP) { - LdapServer *server = ds->rawDataSource; - ldapsvr_set_modified(server, TRUE); - ldapsvr_update_book(server, NULL); - if (server->retVal != LDAPRC_SUCCESS) { - alertpanel( _("Add address(es)"), - addressbook_err2string(_lutErrorsLDAP_, server->retVal), - "window-close", _("_Close"), NULL, NULL, NULL, NULL, - ALERTFOCUS_FIRST ); - server->retVal = LDAPRC_SUCCESS; - return; - } - } -#endif if (prefs_common.addressbook_use_editaddress_dialog) addressbook_new_address_from_book_post_cb( person ); } @@ -3277,48 +3109,10 @@ static void addressbook_new_address_cb( GtkAction *action, gpointer data ) { /* New address */ ItemFolder *folder = ADAPTER_FOLDER(pobj)->itemFolder; ItemPerson *person; -#ifdef USE_LDAP - if (abf && abf->type == ADBOOKTYPE_LDAP) { - GtkCMCTreeNode *parentNode; - ds = addressbook_find_datasource( GTK_CMCTREE_NODE( addrbook.treeSelected ) ); - if( ds == NULL ) return; - - /* We must have a datasource that is an external interface */ - if( ! ds->interface->haveLibrary ) return; - if( ! ds->interface->externalQuery ) return; - - if( pobj->type == ADDR_ITEM_FOLDER ) { - parentNode = GTK_CMCTREE_ROW(GTK_CMCTREE_NODE( addrbook.treeSelected ) )->parent; - } - else { - parentNode = GTK_CMCTREE_NODE( addrbook.treeSelected ); - } - folder = addressbook_setup_subf( ds, _("New Contacts"), parentNode ); - if (!folder) - return; - - ds = addressbook_find_datasource( GTK_CMCTREE_NODE(addrbook.treeSelected) ); - if (ds) - abf = ds->rawDataSource; - } -#endif person = addressbook_edit_person( abf, folder, NULL, FALSE, addrbook.editaddress_vbox, addressbook_new_address_from_folder_post_cb, TRUE ); -#ifdef USE_LDAP - if (ds && abf && abf->type == ADBOOKTYPE_LDAP) { - LdapServer *server = ds->rawDataSource; - ldapsvr_set_modified(server, TRUE); - ldapsvr_update_book(server, NULL); - if (server->retVal != LDAPRC_SUCCESS) { - alertpanel( _("Add address(es)"), - addressbook_err2string(_lutErrorsLDAP_, server->retVal), - "window-close", _("_Close"), NULL, NULL, NULL, NULL, ALERTFOCUS_FIRST ); - return; - } - } -#endif if (prefs_common.addressbook_use_editaddress_dialog) addressbook_new_address_from_folder_post_cb( person ); } @@ -3371,7 +3165,8 @@ static AddressBookFile *addressbook_get_book_file() { ds = addressbook_find_datasource( addrbook.treeSelected ); if( ds == NULL ) return NULL; - if( ds->type == ADDR_IF_BOOK || ds->type == ADDR_IF_LDAP ) abf = ds->rawDataSource; + if( ds->type == ADDR_IF_BOOK ) + abf = ds->rawDataSource; return abf; } @@ -3404,14 +3199,6 @@ static void addressbook_move_nodes_up( GtkCMCTree *ctree, GtkCMCTreeNode *node ) static void addressbook_edit_address_post_cb( ItemPerson *person ) { if( person ) { -#ifdef USE_LDAP - AddressBookFile *abf = addressbook_get_book_file(); - - if (abf && abf->type == ADBOOKTYPE_LDAP) { - if (g_strcmp0(person->nickName, ADDRITEM_NAME(person))) - addritem_person_set_nick_name( person, ADDRITEM_NAME(person)); - } -#endif addressbook_folder_refresh_one_person( GTK_CMCTREE(addrbook.clist), person ); invalidate_address_completion(); } @@ -3437,7 +3224,7 @@ void addressbook_address_list_disable_some_actions(void) static void addressbook_edit_address_cb( GtkAction *action, gpointer data ) { addressbook_edit_address(data, 0, NULL, TRUE); } - + static void addressbook_edit_address( gpointer data, guint action, GtkWidget *widget, gboolean force_focus ) { GtkCMCTree *clist = GTK_CMCTREE(addrbook.clist); @@ -3459,7 +3246,7 @@ static void addressbook_edit_address( gpointer data, guint action, GtkWidget *wi if( ds == NULL ) return; abf = addressbook_get_book_file(); - + if( obj->type == ADDR_ITEM_EMAIL ) { ItemEMail *email = ( ItemEMail * ) obj; @@ -3480,13 +3267,7 @@ static void addressbook_edit_address( gpointer data, guint action, GtkWidget *wi if ( addressbook_edit_person( abf, NULL, person, TRUE, addrbook.editaddress_vbox, addressbook_edit_address_post_cb, (prefs_common.addressbook_use_editaddress_dialog||force_focus) ) - != NULL ) { -#ifdef USE_LDAP - if (abf && abf->type == ADBOOKTYPE_LDAP) { - ldapsvr_set_modified( (LdapServer *) abf, TRUE ); - person->status = UPDATE_ENTRY; - } -#endif + != NULL ) { if (prefs_common.addressbook_use_editaddress_dialog) addressbook_edit_address_post_cb( person ); } @@ -3500,12 +3281,6 @@ static void addressbook_edit_address( gpointer data, guint action, GtkWidget *wi addressbook_edit_address_post_cb, (prefs_common.addressbook_use_editaddress_dialog||force_focus) ) != NULL ) { -#ifdef USE_LDAP - if (abf && abf->type == ADBOOKTYPE_LDAP) { - ldapsvr_set_modified( (LdapServer *) abf, TRUE ); - person->status = UPDATE_ENTRY; - } -#endif if (prefs_common.addressbook_use_editaddress_dialog) addressbook_edit_address_post_cb( person ); } @@ -3527,7 +3302,7 @@ static void addressbook_edit_address( gpointer data, guint action, GtkWidget *wi if( node == NULL ) return; addressbook_change_node_name( node, name ); gtk_sctree_sort_node( ctree, parentNode ); - gtk_sctree_select( GTK_SCTREE(ctree), addrbook.opened ); + gtk_sctree_select( GTK_SCTREE(ctree), addrbook.opened ); addressbook_set_clist( gtk_cmctree_node_get_row_data(GTK_CMCTREE(addrbook.ctree), addrbook.opened), @@ -3663,10 +3438,6 @@ static void addressbook_folder_load_one_person( gchar *text[N_LIST_COLS]; gboolean flgFirst = TRUE, haveAddr = FALSE; GList *node; -#ifdef USE_LDAP - AddressBookFile *abf = addressbook_get_book_file(); -#endif - if( person == NULL ) return; text[COL_NAME] = ""; @@ -3685,21 +3456,7 @@ static void addressbook_folder_load_one_person( gchar *str = addressbook_format_item_clist( person, email ); if( str ) { text[COL_NAME] = addressbook_set_col_name_guard(str); - } -#ifdef USE_LDAP - else if( abf && abf->type == ADBOOKTYPE_LDAP && - person && person->nickName ) { - if (person->nickName) { - if (strcmp(person->nickName, "") != 0) { - text[COL_NAME] = addressbook_set_col_name_guard(person->nickName); - } - else { - text[COL_NAME] = addressbook_set_col_name_guard(ADDRITEM_NAME(person)); - } - } - } -#endif - else { + } else { text[COL_NAME] = addressbook_set_col_name_guard(ADDRITEM_NAME(person)); } nodePerson = gtk_sctree_insert_node( @@ -3779,7 +3536,7 @@ static void addressbook_folder_load_person( GtkCMCTree *clist, ItemFolder *itemF g_list_free( items ); } -static void addressbook_folder_remove_node( GtkCMCTree *clist, GtkCMCTreeNode *node ) { +static void addressbook_folder_remove_node( GtkCMCTree *clist, GtkCMCTreeNode *node ) { addrbook.listSelected = NULL; gtk_cmctree_remove_node( clist, node ); addressbook_menubar_set_sensitive( FALSE ); @@ -3797,7 +3554,7 @@ void addressbook_folder_refresh_one_person( GtkCMCTree *clist, ItemPerson *perso if( atciMail == NULL ) return; if( person == NULL ) return; /* unload the person */ - + node = gtk_cmctree_find_by_row_data( clist, NULL, person ); if( node ) addressbook_folder_remove_node( clist, node ); @@ -3806,14 +3563,14 @@ void addressbook_folder_refresh_one_person( GtkCMCTree *clist, ItemPerson *perso node = gtk_cmctree_find_by_row_data( clist, NULL, person ); if( node ) { gtk_sctree_select( GTK_SCTREE(clist), node ); - if (!gtk_cmctree_node_is_visible( clist, node ) ) + if (!gtk_cmctree_node_is_visible( clist, node ) ) gtk_cmctree_node_moveto( clist, node, 0, 0, 0 ); } } void addressbook_folder_remove_one_person( GtkCMCTree *clist, ItemPerson *person ) { GtkCMCTreeNode *node; - + if( person == NULL ) return; node = gtk_cmctree_find_by_row_data( clist, NULL, person ); if( node ) { @@ -4019,7 +3776,7 @@ static void addressbook_set_clist( AddressObject *obj, gboolean refresh ) { * gtk_cmctree_node_set_row_data_full() when node is populated. This function is * called when the address book tree widget node is removed by calling * function gtk_cmctree_remove_node(). - * + * * \param data Tree node's row data. */ static void addressbook_free_treenode( gpointer data ) { @@ -4208,14 +3965,14 @@ static gboolean migrate_addrbook(const gchar *origdir, const gchar *destdir) g_error_free(error); return FALSE; } - + while( ( d = g_dir_read_name( dp ) ) != NULL ) { if (strncmp(d, "addrbook-", strlen("addrbook-"))) continue; else { - gchar *orig_file = g_strconcat(origdir, G_DIR_SEPARATOR_S, + gchar *orig_file = g_strconcat(origdir, G_DIR_SEPARATOR_S, d, NULL); - gchar *dest_file = g_strconcat(destdir, G_DIR_SEPARATOR_S, + gchar *dest_file = g_strconcat(destdir, G_DIR_SEPARATOR_S, d, NULL); if (copy_file(orig_file, dest_file, FALSE) < 0) { failed = TRUE; @@ -4241,7 +3998,7 @@ static gboolean migrate_addrbook(const gchar *origdir, const gchar *destdir) if (strncmp(d, "addrbook-", strlen("addrbook-"))) continue; else { - gchar *orig_file = g_strconcat(origdir, G_DIR_SEPARATOR_S, + gchar *orig_file = g_strconcat(origdir, G_DIR_SEPARATOR_S, d, NULL); claws_unlink(orig_file); g_free(orig_file); @@ -4249,7 +4006,7 @@ static gboolean migrate_addrbook(const gchar *origdir, const gchar *destdir) } g_dir_close( dp ); } - + return !failed; } @@ -4268,7 +4025,7 @@ void addressbook_read_file( void ) { addrindex_initialize(); /* Use new address book index. */ - + if ( !is_dir_exist(indexdir) ) { if ( make_dir(indexdir) < 0 ) { addrindex_set_file_path( addrIndex, get_rc_dir() ); @@ -4421,17 +4178,17 @@ static GtkCMCTreeNode *addressbook_node_add_folder( ItemFolder *rootFolder; /* Only visible folders */ - if( itemFolder == NULL || itemFolder->isHidden ) + if( itemFolder == NULL || itemFolder->isHidden ) return NULL; - if( ds == NULL ) + if( ds == NULL ) return NULL; - if( node == NULL || itemFolder == NULL ) + if( node == NULL || itemFolder == NULL ) return NULL; /* Determine object type */ atci = addrbookctl_lookup( otype ); - if( atci == NULL ) + if( atci == NULL ) return NULL; rootFolder = addrindex_ds_get_root_folder( ds ); @@ -4547,50 +4304,6 @@ static void addressbook_new_vcard_cb( GtkAction *action, gpointer data ) { } } -#ifdef USE_JPILOT -static void addressbook_new_jpilot_cb( GtkAction *action, gpointer data ) { - AdapterDSource *ads; - AdapterInterface *adapter; - AddressInterface *iface; - GtkCMCTreeNode *newNode; - - adapter = addrbookctl_find_interface( ADDR_IF_JPILOT ); - if( adapter == NULL ) return; - iface = adapter->interface; - if( ! iface->haveLibrary ) return; - ads = addressbook_edit_jpilot( _addressIndex_, NULL ); - if( ads ) { - newNode = addressbook_add_object( adapter->treeNode, ADDRESS_OBJECT(ads) ); - if( newNode ) { - gtk_sctree_select( GTK_SCTREE(addrbook.ctree), newNode ); - addrbook.treeSelected = newNode; - } - } -} -#endif - -#ifdef USE_LDAP -static void addressbook_new_ldap_cb( GtkAction *action, gpointer data ) { - AdapterDSource *ads; - AdapterInterface *adapter; - AddressInterface *iface; - GtkCMCTreeNode *newNode; - - adapter = addrbookctl_find_interface( ADDR_IF_LDAP ); - if( adapter == NULL ) return; - iface = adapter->interface; - if( ! iface->haveLibrary ) return; - ads = addressbook_edit_ldap( _addressIndex_, NULL ); - if( ads ) { - newNode = addressbook_add_object( adapter->treeNode, ADDRESS_OBJECT(ads) ); - if( newNode ) { - gtk_sctree_select( GTK_SCTREE(addrbook.ctree), newNode ); - addrbook.treeSelected = newNode; - } - } -} -#endif - /** * Display address search status message. * \param queryType Query type. @@ -4600,13 +4313,6 @@ static void addressbook_search_message( gint queryType, gint sts ) { gchar *desc = NULL; *addressbook_msgbuf = '\0'; - if( sts != MGU_SUCCESS ) { - if( queryType == ADDRQUERY_LDAP ) { -#ifdef USE_LDAP - desc = addressbook_err2string( _lutErrorsLDAP_, sts ); -#endif - } - } if( desc ) { g_snprintf( addressbook_msgbuf, sizeof(addressbook_msgbuf), "%s", desc ); @@ -4705,7 +4411,7 @@ static void addressbook_perform_search( /* Setup a query */ if( *searchTerm == '\0' || strlen( searchTerm ) < 1 ) return; - if( !ds || ds->type != ADDR_IF_LDAP ) return; + if( !ds ) return; /* Create a folder for the search results */ name = g_strdup_printf( _queryFolderLabel_, searchTerm ); @@ -4745,10 +4451,6 @@ static void addressbook_lup_clicked( GtkButton *button, gpointer data ) { AddressInterface *iface; gchar *searchTerm; GtkCMCTreeNode *node, *parentNode; -#ifdef USE_LDAP - LdapServer *ldap_server; - LdapControl *ldap_ctl; -#endif node = addrbook.treeSelected; if( ! node ) return; @@ -4758,8 +4460,7 @@ static void addressbook_lup_clicked( GtkButton *button, gpointer data ) { obj = gtk_cmctree_node_get_row_data( ctree, node ); if( obj == NULL ) return; - if (obj->type != ADDR_DATASOURCE || - ADAPTER_DSOURCE(obj)->subType != ADDR_LDAP) { + if (obj->type != ADDR_DATASOURCE) { addressbook_set_clist( gtk_cmctree_node_get_row_data(GTK_CMCTREE(addrbook.ctree), addrbook.treeSelected), @@ -4774,23 +4475,6 @@ static void addressbook_lup_clicked( GtkButton *button, gpointer data ) { if( ! iface->haveLibrary ) return; if( ! iface->externalQuery ) return; -#ifdef USE_LDAP - if (iface->type == ADDR_IF_LDAP) { - ldap_server = ds->rawDataSource; - ldap_ctl = ldap_server->control; - if (ldap_ctl != NULL && - ldap_ctl->bindDN != NULL && strlen(ldap_ctl->bindDN) > 0) { -#ifndef PASSWORD_CRYPTO_OLD - /* LDAP server is password-protected. */ - if (primary_passphrase() == NULL) { - /* User did not enter primary passphrase, do not start a search. */ - return; - } -#endif /* PASSWORD_CRYPTO_OLD */ - } - } -#endif /* USE_LDAP */ - searchTerm = gtk_editable_get_chars( GTK_EDITABLE(addrbook.entry), 0, -1 ); g_strchomp( searchTerm ); @@ -4802,7 +4486,7 @@ static void addressbook_lup_clicked( GtkButton *button, gpointer data ) { parentNode = node; } addressbook_perform_search( ds, searchTerm, parentNode ); - + gtk_widget_grab_focus( addrbook.entry ); g_free( searchTerm ); @@ -4812,54 +4496,6 @@ static void addressbook_close_clicked( GtkButton *button, gpointer data ) { addressbook_close(); } -#ifdef USE_LDAP -/** - * Browse address entry for highlighted entry. - */ -static void addressbook_browse_entry_cb( GtkAction *action, gpointer data) -{ - GtkCMCTree *clist = GTK_CMCTREE(addrbook.clist); - AddressObject *obj; - AddressDataSource *ds; - AddressInterface *iface; - ItemPerson *person; - ItemEMail *email; - - if(addrbook.listSelected == NULL) - return; - - obj = gtk_cmctree_node_get_row_data(clist, addrbook.listSelected); - if (obj == NULL) - return; - - ds = addressbook_find_datasource(GTK_CMCTREE_NODE(addrbook.treeSelected)); - if(ds == NULL) - return; - - iface = ds->interface; - if(!iface || !iface->haveLibrary ) - return; - - person = NULL; - if (obj->type == ADDR_ITEM_EMAIL) { - email = ( ItemEMail * ) obj; - - person = (ItemPerson *) ADDRITEM_PARENT(email); - } - else if (obj->type == ADDR_ITEM_PERSON) { - person = (ItemPerson *) obj; - } - else { - /* None of these */ - return; - } - - if( iface && iface->type == ADDR_IF_LDAP ) { - browseldap_entry(ds, person->externalID); - } -} -#endif - /* ********************************************************************** * Build lookup tables. * *********************************************************************** @@ -4915,12 +4551,8 @@ static void addrbookctl_build_icons( GtkWidget *window ) { g_object_unref(bookxpm); if (addressxpm) g_object_unref(addressxpm); - if (jpilotxpm) - g_object_unref(jpilotxpm); if (categoryxpm) g_object_unref(categoryxpm); - if (ldapxpm) - g_object_unref(ldapxpm); if (addrsearchxpm) g_object_unref(addrsearchxpm); stock_pixbuf_gdk(STOCK_PIXMAP_INTERFACE, &interfacexpm ); @@ -4930,11 +4562,9 @@ static void addrbookctl_build_icons( GtkWidget *window ) { stock_pixbuf_gdk(STOCK_PIXMAP_VCARD, &vcardxpm); stock_pixbuf_gdk(STOCK_PIXMAP_BOOK, &bookxpm); stock_pixbuf_gdk(STOCK_PIXMAP_ADDRESS, &addressxpm); - stock_pixbuf_gdk(STOCK_PIXMAP_JPILOT, &jpilotxpm); stock_pixbuf_gdk(STOCK_PIXMAP_CATEGORY, &categoryxpm); - stock_pixbuf_gdk(STOCK_PIXMAP_LDAP, &ldapxpm); stock_pixbuf_gdk(STOCK_PIXMAP_ADDRESS_SEARCH, &addrsearchxpm); - + UPDATE_ICON_ATCI(ADDR_INTERFACE,folderxpm,folderopenxpm); UPDATE_ICON_ATCI(ADDR_BOOK,bookxpm,bookxpm); UPDATE_ICON_ATCI(ADDR_ITEM_PERSON,NULL,NULL); @@ -4942,10 +4572,7 @@ static void addrbookctl_build_icons( GtkWidget *window ) { UPDATE_ICON_ATCI(ADDR_ITEM_GROUP,groupxpm,groupxpm); UPDATE_ICON_ATCI(ADDR_ITEM_FOLDER,folderxpm,folderopenxpm); UPDATE_ICON_ATCI(ADDR_VCARD,vcardxpm,vcardxpm); - UPDATE_ICON_ATCI(ADDR_JPILOT,jpilotxpm,jpilotxpm); UPDATE_ICON_ATCI(ADDR_CATEGORY,categoryxpm,categoryxpm); - UPDATE_ICON_ATCI(ADDR_LDAP,ldapxpm,ldapxpm); - UPDATE_ICON_ATCI(ADDR_LDAP_QUERY,addrsearchxpm,addrsearchxpm); } @@ -5042,54 +4669,6 @@ static void addrbookctl_build_map( GtkWidget *window ) { g_hash_table_insert( _addressBookTypeHash_, &atci->objectType, atci ); _addressBookTypeList_ = g_list_append( _addressBookTypeList_, atci ); - /* J-Pilot */ - atci = g_new0( AddressTypeControlItem, 1 ); - atci->objectType = ADDR_JPILOT; - atci->interfaceType = ADDR_IF_JPILOT; - atci->showInTree = TRUE; - atci->treeExpand = TRUE; - atci->treeLeaf = FALSE; - atci->displayName = _( "JPilot" ); - atci->menuCommand = "Menu/Book/NewJPilot"; - g_hash_table_insert( _addressBookTypeHash_, &atci->objectType, atci ); - _addressBookTypeList_ = g_list_append( _addressBookTypeList_, atci ); - - /* Category */ - atci = g_new0( AddressTypeControlItem, 1 ); - atci->objectType = ADDR_CATEGORY; - atci->interfaceType = ADDR_IF_JPILOT; - atci->showInTree = TRUE; - atci->treeExpand = TRUE; - atci->treeLeaf = TRUE; - atci->displayName = _( "JPilot" ); - atci->menuCommand = NULL; - g_hash_table_insert( _addressBookTypeHash_, &atci->objectType, atci ); - _addressBookTypeList_ = g_list_append( _addressBookTypeList_, atci ); - - /* LDAP Server */ - atci = g_new0( AddressTypeControlItem, 1 ); - atci->objectType = ADDR_LDAP; - atci->interfaceType = ADDR_IF_LDAP; - atci->showInTree = TRUE; - atci->treeExpand = TRUE; - atci->treeLeaf = FALSE; - atci->displayName = _( "LDAP servers" ); - atci->menuCommand = "Menu/Book/NewLDAPServer"; - g_hash_table_insert( _addressBookTypeHash_, &atci->objectType, atci ); - _addressBookTypeList_ = g_list_append( _addressBookTypeList_, atci ); - - /* LDAP Query */ - atci = g_new0( AddressTypeControlItem, 1 ); - atci->objectType = ADDR_LDAP_QUERY; - atci->interfaceType = ADDR_IF_LDAP; - atci->showInTree = TRUE; - atci->treeExpand = FALSE; - atci->treeLeaf = TRUE; - atci->displayName = _( "LDAP Query" ); - atci->menuCommand = NULL; - g_hash_table_insert( _addressBookTypeHash_, &atci->objectType, atci ); - _addressBookTypeList_ = g_list_append( _addressBookTypeList_, atci ); - addrbookctl_build_icons(window); } @@ -5479,48 +5058,6 @@ gboolean addressbook_peek_folder_exists( gchar *folderpath, } -/* ********************************************************************** - * Address Import. - * *********************************************************************** - */ - -/** - * Import LDIF file. - */ -static void addressbook_import_ldif_cb( GtkAction *action, gpointer data ) { - AddressDataSource *ds = NULL; - AdapterDSource *ads = NULL; - AddressBookFile *abf = NULL; - AdapterInterface *adapter; - GtkCMCTreeNode *newNode; - - adapter = addrbookctl_find_interface( ADDR_IF_BOOK ); - if( adapter ) { - if( adapter->treeNode ) { - abf = addressbook_imp_ldif( _addressIndex_ ); - if( abf ) { - ds = addrindex_index_add_datasource( - _addressIndex_, ADDR_IF_BOOK, abf ); - ads = addressbook_create_ds_adapter( - ds, ADDR_BOOK, NULL ); - addressbook_ads_set_name( - ads, addrbook_get_name( abf ) ); - newNode = addressbook_add_object( - adapter->treeNode, - ADDRESS_OBJECT(ads) ); - if( newNode ) { - gtk_sctree_select( GTK_SCTREE(addrbook.ctree), - newNode ); - addrbook.treeSelected = newNode; - } - - /* Notify address completion */ - invalidate_address_completion(); - } - } - } -} - /** * Import MUTT file. */ @@ -5659,41 +5196,17 @@ static void addressbook_export_html_cb( GtkAction *action, gpointer data ) { addressbook_exp_html( cache ); } -/** - * Export LDIF file. - */ -static void addressbook_export_ldif_cb( GtkAction *action, gpointer data ) { - GtkCMCTree *ctree = GTK_CMCTREE(addrbook.ctree); - AddressObject *obj; - AddressDataSource *ds = NULL; - AddrBookBase *adbase; - AddressCache *cache; - GtkCMCTreeNode *node = NULL; - - if( ! addrbook.treeSelected ) return; - node = addrbook.treeSelected; - if( GTK_CMCTREE_ROW(node)->level == 1 ) return; - obj = gtk_cmctree_node_get_row_data( ctree, node ); - if( obj == NULL ) return; - - ds = addressbook_find_datasource( node ); - if( ds == NULL ) return; - adbase = ( AddrBookBase * ) ds->rawDataSource; - cache = adbase->addressCache; - addressbook_exp_ldif( cache ); -} - static void addressbook_find_duplicates_cb(GtkAction *action, gpointer data) { - addrduplicates_find(GTK_WINDOW(addrbook.window)); + addrduplicates_find(GTK_WINDOW(addrbook.window)); } static void addressbook_edit_custom_attr_cb(GtkAction *action, gpointer data) { addressbook_custom_attr_edit(); } - -static void addressbook_start_drag(GtkWidget *widget, gint button, + +static void addressbook_start_drag(GtkWidget *widget, gint button, GdkEvent *event, void *data) { @@ -5731,14 +5244,14 @@ static void addressbook_drag_data_get(GtkWidget *widget, return; } - + else if( pobj->type != ADDR_INTERFACE ) { ds = addressbook_find_datasource( addrbook.treeSelected ); if (!ds) return; } - + for(cur = GTK_CMCLIST(addrbook.clist)->selection; cur; cur = cur->next) { aio = (AddrItemObject *)gtk_cmctree_node_get_row_data(GTK_CMCTREE(addrbook.clist), GTK_CMCTREE_NODE(cur->data)); @@ -5756,7 +5269,7 @@ static void addressbook_drag_data_get(GtkWidget *widget, gtk_selection_data_set(selection_data, gtk_selection_data_get_target(selection_data), 8, (const guchar *)"Dummy_addr_move", 15); - } + } } static gboolean addressbook_drag_motion_cb(GtkWidget *widget, @@ -5778,7 +5291,7 @@ static gboolean addressbook_drag_motion_cb(GtkWidget *widget, GtkAdjustment *pos = gtk_scrolled_window_get_vadjustment( GTK_SCROLLED_WINDOW(addrbook.ctree_swin)); gfloat vpos = gtk_adjustment_get_value(pos); - + if (gtk_cmclist_get_selection_info (GTK_CMCLIST(widget), x - 24, y - 24, &row, &column)) { @@ -5794,7 +5307,7 @@ static gboolean addressbook_drag_motion_cb(GtkWidget *widget, AddressObject *obj = gtk_cmctree_node_get_row_data(GTK_CMCTREE(widget), node ); if (obj == NULL) return FALSE; - if( obj->type == ADDR_ITEM_FOLDER + if( obj->type == ADDR_ITEM_FOLDER || obj->type == ADDR_ITEM_GROUP) acceptable = TRUE; else { @@ -5817,7 +5330,7 @@ static gboolean addressbook_drag_motion_cb(GtkWidget *widget, g_signal_handlers_unblock_by_func (G_OBJECT(widget), G_CALLBACK(addressbook_tree_selected), NULL); - gdk_drag_status(context, + gdk_drag_status(context, (gdk_drag_context_get_actions(context) == GDK_ACTION_COPY ? GDK_ACTION_COPY : GDK_ACTION_MOVE) , time); } else { @@ -5840,7 +5353,7 @@ static void addressbook_drag_leave_cb(GtkWidget *widget, (G_OBJECT(widget), G_CALLBACK(addressbook_tree_selected), NULL); } - + } static void addressbook_drag_received_cb(GtkWidget *widget, @@ -5861,13 +5374,13 @@ static void addressbook_drag_received_cb(GtkWidget *widget, (GTK_CMCLIST(widget), x - 24, y - 24, &row, &column) == 0) { return; } - + node = gtk_cmctree_node_nth(GTK_CMCTREE(widget), row); - if( !node || !gtk_cmctree_node_get_row_data(GTK_CMCTREE(addrbook.ctree), node)) + if( !node || !gtk_cmctree_node_get_row_data(GTK_CMCTREE(addrbook.ctree), node)) return; - + gtk_cmclist_freeze(GTK_CMCLIST(addrbook.clist)); - if (gdk_drag_context_get_selected_action(drag_context) == GDK_ACTION_COPY || + if (gdk_drag_context_get_selected_action(drag_context) == GDK_ACTION_COPY || !strcmp(gtk_selection_data_get_data(data), "Dummy_addr_copy")) addressbook_clip_copy_cb(NULL, NULL); else diff --git a/src/addressitem.h b/src/addressitem.h @@ -14,7 +14,7 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * */ /* @@ -49,10 +49,7 @@ typedef enum { ADDR_DATASOURCE, ADDR_BOOK, /* Sub-type */ ADDR_VCARD, /* Sub-type */ - ADDR_JPILOT, /* Sub-type */ ADDR_CATEGORY, /* Sub-type */ - ADDR_LDAP, /* Sub-type */ - ADDR_LDAP_QUERY /* Sub-type */ } AddressObjectType; typedef struct _AddressBook_win AddressBook_win; diff --git a/src/addrindex.c b/src/addrindex.c @@ -51,18 +51,6 @@ #include "vcard.h" -#ifdef USE_JPILOT -#include "jpilot.h" -#endif - -#ifdef USE_LDAP -#include "ldapserver.h" -#include "ldapctrl.h" -#include "ldapquery.h" -#include "ldapupdate.h" -#include "ldaputil.h" -#endif - #ifdef G_OS_WIN32 #undef interface #endif @@ -71,13 +59,9 @@ #define TAG_IF_ADDRESS_BOOK "book_list" #define TAG_IF_VCARD "vcard_list" -#define TAG_IF_JPILOT "jpilot_list" -#define TAG_IF_LDAP "ldap_list" #define TAG_DS_ADDRESS_BOOK "book" #define TAG_DS_VCARD "vcard" -#define TAG_DS_JPILOT "jpilot" -#define TAG_DS_LDAP "server" /* XML Attribute names */ #define ATTAG_BOOK_NAME "name" @@ -86,40 +70,10 @@ #define ATTAG_VCARD_NAME "name" #define ATTAG_VCARD_FILE "file" -#define ATTAG_JPILOT_NAME "name" -#define ATTAG_JPILOT_FILE "file" -#define ATTAG_JPILOT_CUSTOM_1 "custom-1" -#define ATTAG_JPILOT_CUSTOM_2 "custom-2" -#define ATTAG_JPILOT_CUSTOM_3 "custom-3" -#define ATTAG_JPILOT_CUSTOM_4 "custom-4" -#define ATTAG_JPILOT_CUSTOM "custom-" - -#define ATTAG_LDAP_NAME "name" -#define ATTAG_LDAP_HOST "host" -#define ATTAG_LDAP_PORT "port" -#define ATTAG_LDAP_BASE_DN "base-dn" -#define ATTAG_LDAP_BIND_DN "bind-dn" -#define ATTAG_LDAP_BIND_PASS "bind-pass" -#define ATTAG_LDAP_CRITERIA "criteria" -#define ATTAG_LDAP_MAX_ENTRY "max-entry" -#define ATTAG_LDAP_TIMEOUT "timeout" -#define ATTAG_LDAP_MAX_AGE "max-age" -#define ATTAG_LDAP_DYN_SEARCH "dyn-search" -#define ATTAG_LDAP_MATCH_OPT "match-opt" -#define ATTAG_LDAP_ENABLE_TLS "enable-tls" -#define ATTAG_LDAP_ENABLE_SSL "enable-ssl" - -#define ELTAG_LDAP_ATTR_SRCH "attribute" -#define ATTAG_LDAP_ATTR_NAME "name" - /* Attribute values */ #define ATVAL_BOOLEAN_YES "yes" #define ATVAL_BOOLEAN_NO "no" -#define ATVAL_LDAP_MATCH_BEGIN "begin-with" -#define ATVAL_LDAP_MATCH_CONTAINS "contains" -/* New attributes */ -#define ATTAG_LDAP_DEFAULT "default" #define DISP_NEW_COMMON _("Common addresses") #define DISP_NEW_PERSONAL _("Personal addresses") @@ -245,7 +199,7 @@ static void addrindex_build_if_list( AddressIndex *addrIndex ) { iface->setAccessFlag = ( void * ) addrbook_set_accessed; iface->searchOrder = 0; - /* Add to list of interfaces in address book */ + /* Add to list of interfaces in address book */ addrIndex->interfaceList = g_list_append( addrIndex->interfaceList, iface ); ADDRITEM_PARENT(iface) = ADDRITEM_OBJECT(addrIndex); @@ -269,61 +223,6 @@ static void addrindex_build_if_list( AddressIndex *addrIndex ) { g_list_append( addrIndex->interfaceList, iface ); ADDRITEM_PARENT(iface) = ADDRITEM_OBJECT(addrIndex); - /* Create JPilot interface */ - iface = addrindex_create_interface( - ADDR_IF_JPILOT, "J-Pilot", TAG_IF_JPILOT, - TAG_DS_JPILOT ); -#ifdef USE_JPILOT - iface->haveLibrary = jpilot_test_pilot_lib(); - iface->useInterface = iface->haveLibrary; - iface->getModifyFlag = ( void * ) jpilot_get_modified; - iface->getAccessFlag = ( void * ) jpilot_get_accessed; - iface->getReadFlag = ( void * ) jpilot_get_read_flag; - iface->getStatusCode = ( void * ) jpilot_get_status; - iface->getReadData = ( void * ) jpilot_read_data; - iface->getRootFolder = ( void * ) jpilot_get_root_folder; - iface->getListFolder = ( void * ) jpilot_get_list_folder; - iface->getListPerson = ( void * ) jpilot_get_list_person; - iface->getAllPersons = ( void * ) jpilot_get_all_persons; - iface->getName = ( void * ) jpilot_get_name; - iface->setAccessFlag = ( void * ) jpilot_set_accessed; - iface->searchOrder = 0; -#else - iface->useInterface = FALSE; - iface->haveLibrary = FALSE; -#endif - addrIndex->interfaceList = - g_list_append( addrIndex->interfaceList, iface ); - ADDRITEM_PARENT(iface) = ADDRITEM_OBJECT(addrIndex); - - /* Create LDAP interface */ - iface = addrindex_create_interface( - ADDR_IF_LDAP, "LDAP", TAG_IF_LDAP, TAG_DS_LDAP ); -#ifdef USE_LDAP - iface->readOnly = FALSE; - /* iface->haveLibrary = ldapsvr_test_ldap_lib(); */ - iface->haveLibrary = ldaputil_test_ldap_lib(); - iface->useInterface = iface->haveLibrary; - iface->getModifyFlag = ( void * ) ldapsvr_get_modified; - iface->getAccessFlag = ( void * ) ldapsvr_get_accessed; - iface->getReadFlag = ( void * ) ldapsvr_get_read_flag; - iface->getStatusCode = ( void * ) ldapsvr_get_status; - iface->getReadData = ( void * ) ldapsvr_read_data; - iface->getRootFolder = ( void * ) ldapsvr_get_root_folder; - iface->getListFolder = ( void * ) ldapsvr_get_list_folder; - iface->getListPerson = ( void * ) ldapsvr_get_list_person; - iface->getName = ( void * ) ldapsvr_get_name; - iface->setAccessFlag = ( void * ) ldapsvr_set_accessed; - iface->externalQuery = TRUE; - iface->searchOrder = 1; -#else - iface->useInterface = FALSE; - iface->haveLibrary = FALSE; -#endif - addrIndex->interfaceList = - g_list_append( addrIndex->interfaceList, iface ); - ADDRITEM_PARENT(iface) = ADDRITEM_OBJECT(addrIndex); - /* Two old legacy data sources (pre 0.7.0) */ iface = addrindex_create_interface( ADDR_IF_COMMON, "Old Address - common", @@ -420,22 +319,7 @@ void addrindex_free_datasource( AddressDataSource *ds ) { VCardFile *vcf = ds->rawDataSource; vcard_free( vcf ); } -#ifdef USE_JPILOT - else if( iface->type == ADDR_IF_JPILOT ) { - JPilotFile *jpf = ds->rawDataSource; - jpilot_free( jpf ); - } -#endif -#ifdef USE_LDAP - else if( iface->type == ADDR_IF_LDAP ) { - LdapServer *server = ds->rawDataSource; - ldapsvr_free( server ); - } -#endif - else { - } - } - else { + } else { AddressIfFragment *fragment = ds->rawDataSource; addrindex_free_fragment( fragment ); } @@ -720,7 +604,7 @@ void addrindex_free_index( AddressIndex *addrIndex ) { g_free( addrIndex->filePath ); g_free( addrIndex->fileName ); - /* Clear pointers */ + /* Clear pointers */ ADDRITEM_TYPE(addrIndex) = ITEMTYPE_NONE; ADDRITEM_ID(addrIndex) = NULL; ADDRITEM_NAME(addrIndex) = NULL; @@ -735,7 +619,7 @@ void addrindex_free_index( AddressIndex *addrIndex ) { addrIndex->lastType = ADDR_IF_NONE; addrIndex->dirtyFlag = FALSE; - /* Free up interfaces */ + /* Free up interfaces */ node = addrIndex->interfaceList; while( node ) { AddressInterface *iface = node->data; @@ -807,7 +691,7 @@ static AddressInterface *addrindex_get_interface( * * \param addrIndex Address index. * \param ifType Interface type to add. - * \param dataSource Actual raw data source to add. + * \param dataSource Actual raw data source to add. * \return Data source added, or NULL if invalid interface type. */ AddressDataSource *addrindex_index_add_datasource( @@ -837,7 +721,7 @@ AddressDataSource *addrindex_index_add_datasource( /** * Remove specified data source from index. * \param addrIndex Address index. - * \param dataSource Data source to add. + * \param dataSource Data source to add. * \return Reference to data source if removed, or NULL if data source was not * found in index. Note the this object must still be freed. */ @@ -937,7 +821,7 @@ static AddressInterface *addrindex_tag_get_datasource( */ static int addrindex_write_elem_s( FILE *fp, const gint lvl, const gchar *name ) { gint i; - for( i = 0; i < lvl; i++ ) + for( i = 0; i < lvl; i++ ) if (claws_fputs( " ", fp ) == EOF) return -1; if (claws_fputs( "<", fp ) == EOF) @@ -955,7 +839,7 @@ static int addrindex_write_elem_s( FILE *fp, const gint lvl, const gchar *name ) */ static int addrindex_write_elem_e( FILE *fp, const gint lvl, const gchar *name ) { gint i; - for( i = 0; i < lvl; i++ ) + for( i = 0; i < lvl; i++ ) if (claws_fputs( " ", fp ) == EOF) return -1; if (claws_fputs( "</", fp ) == EOF) @@ -987,118 +871,6 @@ static int addrindex_write_attr( FILE *fp, const gchar *name, const gchar *value return 0; } -#if !defined(USE_LDAP) || !defined(USE_JPILOT) -/** - * Return DOM fragment for current XML tag from file. - * \param file XML file being processed. - * \return Fragment representing DOM fragment for configuration element. - */ -static AddressIfFragment *addrindex_read_fragment( XMLFile *file ) { - AddressIfFragment *fragment; - AddressIfFragment *child; - AddressIfAttrib *nv; - XMLTag *xtag; - GList *list; - GList *attr; - gchar *name; - gchar *value; - guint prevLevel; - gint rc; - - /* g_print( "addrindex_read_fragment\n" ); */ - - prevLevel = file->level; - - /* Get current tag name */ - xtag = xml_get_current_tag( file ); - - /* Create new fragment */ - fragment = g_new0( AddressIfFragment, 1 ); - fragment->type = ADBOOKTYPE_NONE; - fragment->addressCache = NULL; - fragment->name = g_strdup( xtag->tag ); - fragment->children = NULL; - fragment->attributes = NULL; - - /* Read attributes */ - list = NULL; - attr = xml_get_current_tag_attr( file ); - while( attr ) { - name = ((XMLAttr *)attr->data)->name; - value = ((XMLAttr *)attr->data)->value; - nv = g_new0( AddressIfAttrib, 1 ); - nv->name = g_strdup( name ); - nv->value = g_strdup( value ); - list = g_list_append( list, nv ); - attr = g_list_next( attr ); - } - fragment->attributes = list; - - /* Now read the children */ - while( TRUE ) { - rc = xml_parse_next_tag( file ); - if( rc != 0 ) { - /* End of file? */ - break; - } - if( file->level < prevLevel ) { - /* We must be above level we start at */ - break; - } - child = addrindex_read_fragment( file ); - fragment->children = g_list_append( fragment->children, child ); - } - - return fragment; -} - -/** - * Write DOM fragment to file. - * \param fp File to write. - * \param fragment DOM fragment for configuration element. - * \param lvl Indent level. - */ -static int addrindex_write_fragment( - FILE *fp, const AddressIfFragment *fragment, const gint lvl ) -{ - GList *node; - - if( fragment ) { - if (addrindex_write_elem_s( fp, lvl, fragment->name ) < 0) - return -1; - node = fragment->attributes; - while( node ) { - AddressIfAttrib *nv = node->data; - if (addrindex_write_attr( fp, nv->name, nv->value ) < 0) - return -1; - node = g_list_next( node ); - } - if( fragment->children ) { - if (claws_fputs(" >\n", fp) == EOF) - return -1; - - /* Output children */ - node = fragment->children; - while( node ) { - AddressIfFragment *child = node->data; - if (addrindex_write_fragment( fp, child, 1+lvl ) < 0) - return -1; - node = g_list_next( node ); - } - - /* Output closing tag */ - if (addrindex_write_elem_e( fp, lvl, fragment->name ) < 0) - return -1; - } - else { - if (claws_fputs(" />\n", fp) == EOF) - return -1; - } - } - - return 0; -} -#endif /** * Read/parse address index file, creating a data source for a regular * intrinsic XML addressbook. @@ -1181,393 +953,6 @@ static int addrindex_write_vcard( FILE *fp, AddressDataSource *ds, gint lvl ) { return 0; } -#ifdef USE_JPILOT -static AddressDataSource *addrindex_parse_jpilot( XMLFile *file ) { - AddressDataSource *ds; - JPilotFile *jpf; - GList *attr; - - ds = addrindex_create_datasource( ADDR_IF_JPILOT ); - jpf = jpilot_create(); - attr = xml_get_current_tag_attr( file ); - while( attr ) { - gchar *name = ((XMLAttr *)attr->data)->name; - gchar *value = ((XMLAttr *)attr->data)->value; - if( strcmp( name, ATTAG_JPILOT_NAME ) == 0 ) { - jpilot_set_name( jpf, value ); - } - else if( strcmp( name, ATTAG_JPILOT_FILE ) == 0 ) { - jpilot_set_file( jpf, value ); - } - else if( strcmp( name, ATTAG_JPILOT_CUSTOM_1 ) == 0 ) { - jpilot_add_custom_label( jpf, value ); - } - else if( strcmp( name, ATTAG_JPILOT_CUSTOM_2 ) == 0 ) { - jpilot_add_custom_label( jpf, value ); - } - else if( strcmp( name, ATTAG_JPILOT_CUSTOM_3 ) == 0 ) { - jpilot_add_custom_label( jpf, value ); - } - else if( strcmp( name, ATTAG_JPILOT_CUSTOM_4 ) == 0 ) { - jpilot_add_custom_label( jpf, value ); - } - attr = g_list_next( attr ); - } - ds->rawDataSource = jpf; - return ds; -} - -static int addrindex_write_jpilot( FILE *fp,AddressDataSource *ds, gint lvl ) { - JPilotFile *jpf = ds->rawDataSource; - if( jpf ) { - gint ind; - GList *node; - GList *customLbl = jpilot_get_custom_labels( jpf ); - if (addrindex_write_elem_s( fp, lvl, TAG_DS_JPILOT ) < 0) - return -1; - if (addrindex_write_attr( fp, ATTAG_JPILOT_NAME, jpilot_get_name( jpf ) ) < 0) - return -1; - if (addrindex_write_attr( fp, ATTAG_JPILOT_FILE, jpf->path ) < 0) - return -1; - node = customLbl; - ind = 1; - while( node ) { - gchar name[256]; - g_snprintf( name, sizeof(name), "%s%d", - ATTAG_JPILOT_CUSTOM, ind ); - if (addrindex_write_attr( fp, name, node->data ) < 0) - return -1; - ind++; - node = g_list_next( node ); - } - if (claws_fputs( " />\n", fp ) == EOF) - return -1; - } - return 0; -} - -#else -/* - * Just read/write DOM fragments (preserve data found in file). - */ -static AddressDataSource *addrindex_parse_jpilot( XMLFile *file ) { - AddressDataSource *ds; - - ds = addrindex_create_datasource( ADDR_IF_JPILOT ); - ds->rawDataSource = addrindex_read_fragment( file ); - return ds; -} - -static int addrindex_write_jpilot( FILE *fp, AddressDataSource *ds, gint lvl ) { - AddressIfFragment *fragment = ds->rawDataSource; - if( fragment ) { - if (addrindex_write_fragment( fp, fragment, lvl ) < 0) - return -1; - } - return 0; -} -#endif - -#ifdef USE_LDAP -/** - * Parse LDAP criteria attribute data from XML file. - * \param file Index file. - * \param ctl LDAP control object to populate. - */ -static void addrindex_parse_ldap_attrlist( XMLFile *file, LdapControl *ctl ) { - guint prevLevel; - XMLTag *xtag; - XMLTag *xtagPrev; - gint rc; - GList *attr; - GList *list; - GList *node; - - if( file == NULL ) { - return; - } - - list = NULL; - prevLevel = file->level; - xtagPrev = xml_get_current_tag( file ); - while( TRUE ) { - rc = xml_parse_next_tag( file ); - if( rc != 0 ) { - /* Terminate prematurely */ - g_list_free_full( list, g_free ); - list = NULL; - return; - } - if( file->level < prevLevel ) { - /* We must be above level we start at */ - break; - } - - /* Get a tag (element) */ - xtag = xml_get_current_tag( file ); - if( strcmp( xtag->tag, ELTAG_LDAP_ATTR_SRCH ) == 0 ) { - /* LDAP criteria attribute */ - attr = xml_get_current_tag_attr( file ); - while( attr ) { - gchar *name = ((XMLAttr *)attr->data)->name; - gchar *value = ((XMLAttr *)attr->data)->value; - if( strcmp( name, ATTAG_LDAP_ATTR_NAME ) == 0 ) { - if( value && strlen( value ) > 0 ) { - list = g_list_append( - list, g_strdup( value ) ); - } - } - attr = g_list_next( attr ); - } - } - else { - if( xtag != xtagPrev ) { - /* Found a new tag */ - break; - } - } - } - - /* Build list of search attributes */ - ldapctl_criteria_list_clear( ctl ); - node = list; - while( node ) { - ldapctl_criteria_list_add( ctl, node->data ); - g_free( node->data ); - node->data = NULL; - node = g_list_next( node ); - } - g_list_free( list ); - list = NULL; - -} - -void ldapsvr_set_control( LdapServer *server, LdapControl *ctl ); -/** - * Parse LDAP control data from XML file. - * \param file Index file. - * \return Initialized data soruce object. - */ -static AddressDataSource *addrindex_parse_ldap( XMLFile *file ) { - AddressDataSource *ds; - LdapServer *server; - LdapControl *ctl; - GList *attr; - gchar *serverName = NULL; - gchar *criteria = NULL; - gboolean bDynSearch; - gboolean bTLS, bSSL; - gint iMatch; - gchar *password = NULL; - - /* g_print( "addrindex_parse_ldap\n" ); */ - /* Set up some defaults */ - bDynSearch = FALSE; - bTLS = FALSE; - bSSL = FALSE; - iMatch = LDAPCTL_MATCH_BEGINWITH; - - ds = addrindex_create_datasource( ADDR_IF_LDAP ); - ctl = ldapctl_create(); - attr = xml_get_current_tag_attr( file ); - while( attr ) { - gchar *name = ((XMLAttr *)attr->data)->name; - gchar *value = ((XMLAttr *)attr->data)->value; - gint ivalue = atoi( value ); - - if( strcmp( name, ATTAG_LDAP_NAME ) == 0 ) { - g_free( serverName ); - serverName = g_strdup( value ); - } - else if( strcmp( name, ATTAG_LDAP_HOST ) == 0 ) { - ldapctl_set_host( ctl, value ); - } - else if( strcmp( name, ATTAG_LDAP_PORT ) == 0 ) { - ldapctl_set_port( ctl, ivalue ); - } - else if( strcmp( name, ATTAG_LDAP_BASE_DN ) == 0 ) { - ldapctl_set_base_dn( ctl, value ); - } - else if( strcmp( name, ATTAG_LDAP_BIND_DN ) == 0 ) { - ldapctl_set_bind_dn( ctl, value ); - } - else if( strcmp( name, ATTAG_LDAP_BIND_PASS ) == 0 ) { - password = value; - } - else if( strcmp( name, ATTAG_LDAP_CRITERIA ) == 0 ) { - g_free( criteria ); - criteria = g_strdup( value ); - g_print("criteria %s\n", criteria); - } - else if( strcmp( name, ATTAG_LDAP_MAX_ENTRY ) == 0 ) { - ldapctl_set_max_entries( ctl, ivalue ); - } - else if( strcmp( name, ATTAG_LDAP_TIMEOUT ) == 0 ) { - ldapctl_set_timeout( ctl, ivalue ); - } - else if( strcmp( name, ATTAG_LDAP_MAX_AGE ) == 0 ) { - ldapctl_set_max_query_age( ctl, ivalue ); - } - else if( strcmp( name, ATTAG_LDAP_DYN_SEARCH ) == 0 ) { - bDynSearch = FALSE; - if( strcmp( value, ATVAL_BOOLEAN_YES ) == 0 ) { - bDynSearch = TRUE; - } - } - else if( strcmp( name, ATTAG_LDAP_MATCH_OPT ) == 0 ) { - iMatch = LDAPCTL_MATCH_BEGINWITH; - if( strcmp( value, ATVAL_LDAP_MATCH_CONTAINS ) == 0 ) { - iMatch = LDAPCTL_MATCH_CONTAINS; - } - } - else if( strcmp( name, ATTAG_LDAP_ENABLE_TLS ) == 0 ) { - bTLS = FALSE; - if( strcmp( value, ATVAL_BOOLEAN_YES ) == 0 ) { - bTLS = TRUE; - } - } - else if( strcmp( name, ATTAG_LDAP_ENABLE_SSL ) == 0 ) { - bSSL = FALSE; - if( strcmp( value, ATVAL_BOOLEAN_YES ) == 0 ) { - bSSL = TRUE; - } - } - attr = g_list_next( attr ); - } - - if (password != NULL) - passwd_store_set(PWS_CORE, "LDAP", ctl->hostName, password, TRUE); - - server = ldapsvr_create_noctl(); - ldapsvr_set_name( server, serverName ); - ldapsvr_set_search_flag( server, bDynSearch ); - ldapctl_set_matching_option( ctl, iMatch ); - ldapctl_set_tls( ctl, bTLS ); - ldapctl_set_ssl( ctl, bSSL ); - g_free( serverName ); - ldapsvr_set_control( server, ctl ); - ds->rawDataSource = server; - - addrindex_parse_ldap_attrlist( file, ctl ); - /* - * If criteria have been specified and no attributes were listed, then - * convert old style criteria into an attribute list. Any criteria will - * be dropped when saving data. - */ - if( criteria ) { - if( ! ldapctl_get_criteria_list( ctl ) ) { - ldapctl_parse_ldap_search( ctl, criteria ); - } - g_free( criteria ); - } -#ifdef DEBUG_LDAP - ldapsvr_print_data( server, stdout ); -#endif - - return ds; -} - -static int addrindex_write_ldap( FILE *fp, AddressDataSource *ds, gint lvl ) { - LdapServer *server = ds->rawDataSource; - LdapControl *ctl = NULL; - GList *node; - gchar value[256]; - - if( server ) { - ctl = server->control; - } - if( ctl == NULL ) return 0; - - /* Output start element with attributes */ - if (addrindex_write_elem_s( fp, lvl, TAG_DS_LDAP ) < 0) - return -1; - if (addrindex_write_attr( fp, ATTAG_LDAP_NAME, ldapsvr_get_name( server ) ) < 0) - return -1; - if (addrindex_write_attr( fp, ATTAG_LDAP_HOST, ctl->hostName ) < 0) - return -1; - - sprintf( value, "%d", ctl->port ); - if (addrindex_write_attr( fp, ATTAG_LDAP_PORT, value ) < 0) - return -1; - - if (addrindex_write_attr( fp, ATTAG_LDAP_BASE_DN, ctl->baseDN ) < 0) - return -1; - if (addrindex_write_attr( fp, ATTAG_LDAP_BIND_DN, ctl->bindDN ) < 0) - return -1; - - sprintf( value, "%d", ctl->maxEntries ); - if (addrindex_write_attr( fp, ATTAG_LDAP_MAX_ENTRY, value ) < 0) - return -1; - sprintf( value, "%d", ctl->timeOut ); - if (addrindex_write_attr( fp, ATTAG_LDAP_TIMEOUT, value ) < 0) - return -1; - sprintf( value, "%d", ctl->maxQueryAge ); - if (addrindex_write_attr( fp, ATTAG_LDAP_MAX_AGE, value ) < 0) - return -1; - - if (addrindex_write_attr( fp, ATTAG_LDAP_DYN_SEARCH, - server->searchFlag ? - ATVAL_BOOLEAN_YES : ATVAL_BOOLEAN_NO ) < 0) - return -1; - - if (addrindex_write_attr( fp, ATTAG_LDAP_MATCH_OPT, - ( ctl->matchingOption == LDAPCTL_MATCH_CONTAINS ) ? - ATVAL_LDAP_MATCH_CONTAINS : ATVAL_LDAP_MATCH_BEGIN ) < 0) - return -1; - - if (addrindex_write_attr( fp, ATTAG_LDAP_ENABLE_TLS, - ctl->enableTLS ? - ATVAL_BOOLEAN_YES : ATVAL_BOOLEAN_NO ) < 0) - return -1; - if (addrindex_write_attr( fp, ATTAG_LDAP_ENABLE_SSL, - ctl->enableSSL ? - ATVAL_BOOLEAN_YES : ATVAL_BOOLEAN_NO ) < 0) - return -1; - - if (claws_fputs(" >\n", fp) == EOF) - return -1; - - /* Output attributes */ - node = ldapctl_get_criteria_list( ctl ); - while( node ) { - if (addrindex_write_elem_s( fp, 1+lvl, ELTAG_LDAP_ATTR_SRCH ) < 0) - return -1; - if (addrindex_write_attr( fp, ATTAG_LDAP_ATTR_NAME, node->data ) < 0) - return -1; - if (claws_fputs(" />\n", fp) == EOF) - return -1; - node = g_list_next( node ); - } - - /* End of element */ - if (addrindex_write_elem_e( fp, lvl, TAG_DS_LDAP ) < 0) - return -1; - - return 0; -} - -#else -/* - * Just read/write DOM fragments (preserve data found in file). - */ -static AddressDataSource *addrindex_parse_ldap( XMLFile *file ) { - AddressDataSource *ds; - - ds = addrindex_create_datasource( ADDR_IF_LDAP ); - ds->rawDataSource = addrindex_read_fragment( file ); - return ds; -} - -static int addrindex_write_ldap( FILE *fp, AddressDataSource *ds, gint lvl ) { - AddressIfFragment *fragment = ds->rawDataSource; - if( fragment ) { - if (addrindex_write_fragment( fp, fragment, lvl ) < 0) - return -1; - } - return 0; -} -#endif - /* ********************************************************************** * Address index I/O functions. * *********************************************************************** @@ -1613,12 +998,6 @@ static void addrindex_read_index( AddressIndex *addrIndex, XMLFile *file ) { else if( addrIndex->lastType == ADDR_IF_VCARD ) { ds = addrindex_parse_vcard( file ); } - else if( addrIndex->lastType == ADDR_IF_JPILOT ) { - ds = addrindex_parse_jpilot( file ); - } - else if( addrIndex->lastType == ADDR_IF_LDAP ) { - ds = addrindex_parse_ldap( file ); - } if( ds ) { ds->interface = dsIFace; addrindex_hash_add_cache( addrIndex, ds ); @@ -1726,14 +1105,6 @@ static int addrindex_write_index( AddressIndex *addrIndex, FILE *fp ) { if (addrindex_write_vcard( fp, ds, lvlItem ) < 0) return -1; } - if( iface->type == ADDR_IF_JPILOT ) { - if (addrindex_write_jpilot( fp, ds, lvlItem ) < 0) - return -1; - } - if( iface->type == ADDR_IF_LDAP ) { - if (addrindex_write_ldap( fp, ds, lvlItem ) < 0) - return -1; - } } nodeDS = g_list_next( nodeDS ); } @@ -1811,45 +1182,8 @@ fail: * return: Status code, from addrIndex->retVal. */ gint addrindex_save_data( AddressIndex *addrIndex ) { -#ifdef USE_LDAP - GList *nodeIf; - GList *nodeDS; -#endif - cm_return_val_if_fail( addrIndex != NULL, -1 ); -#ifdef USE_LDAP - nodeIf = addrIndex->interfaceList; - /* save LDAP interfaces */ - while ( nodeIf ) { - AddressInterface *iface = nodeIf->data; - if( iface->type == ADDR_IF_LDAP ) { - nodeDS = iface->listSource; - while( nodeDS ) { - AddressDataSource *ds = nodeDS->data; - LdapServer *abf = ds->rawDataSource; - if( ldapsvr_get_read_flag( abf ) ) { - if( ldapsvr_get_modified( abf ) ) { - ldapsvr_update_book( abf, NULL ); - if( abf->retVal != LDAPRC_SUCCESS ) { - alertpanel( _("Address(es) update"), - _("Update failed. Changes not written to Directory."), - "window-close", _("_Close"), NULL, NULL, - NULL, NULL, ALERTFOCUS_FIRST ); - } - else { - abf->retVal = MGU_SUCCESS; - ldapsvr_set_modified( abf, FALSE ); - } - } - } - nodeDS = g_list_next( nodeDS ); - } - break; - } - nodeIf = g_list_next( nodeIf ); - } -#endif addrIndex->retVal = MGU_NO_FILE; if( addrIndex->fileName == NULL || *addrIndex->fileName == '\0' ) return addrIndex->retVal; if( addrIndex->filePath == NULL || *addrIndex->filePath == '\0' ) return addrIndex->retVal; @@ -2560,20 +1894,6 @@ gint addrindex_setup_search( return queryID; } -#ifdef USE_LDAP - -/* - * Function prototypes (not in header file or circular reference errors are - * encountered!) - */ -LdapQuery *ldapsvr_new_dynamic_search( - LdapServer *server, QueryRequest *req ); -LdapQuery *ldapsvr_new_explicit_search( - LdapServer *server, QueryRequest *req, ItemFolder *folder ); -void ldapsvr_execute_query( LdapServer *server, LdapQuery *qry ); - -#endif - /** * Execute the previously registered dynamic search. * @@ -2606,26 +1926,6 @@ static gboolean addrindex_start_dynamic( QueryRequest *req ) { while( nodeDS ) { ds = nodeDS->data; nodeDS = g_list_next( nodeDS ); -#ifdef USE_LDAP - if( type == ADDR_IF_LDAP ) { - LdapServer *server; - LdapQuery *qry; - - server = ds->rawDataSource; - if( ! server->searchFlag ) { - continue; - } - if( ldapsvr_reuse_previous( server, req ) ) { - continue; - } - - /* Start a new dynamic search */ - qry = ldapsvr_new_dynamic_search( server, req ); - if( qry ) { - ldapsvr_execute_query( server, qry ); - } - } -#endif } } return TRUE; @@ -2652,12 +1952,6 @@ void addrindex_stop_search( const gint queryID ){ node = req->queryList; while( node ) { aqo = node->data; -#ifdef USE_LDAP - if( aqo->queryType == ADDRQUERY_LDAP ) { - LdapQuery *qry = ( LdapQuery * ) aqo; - ldapqry_set_stop_flag( qry, TRUE ); - } -#endif node->data = NULL; node = g_list_next( node ); } @@ -2694,7 +1988,7 @@ gint addrindex_setup_explicit_search( mySearch = g_strdup("*@"); else mySearch = g_strdup(searchTerm); - + req = qrymgr_add_request( mySearch, callBackEnd, callBackEntry ); g_free(mySearch); @@ -2702,55 +1996,14 @@ gint addrindex_setup_explicit_search( qryreq_set_search_type( req, ADDRSEARCH_EXPLICIT ); queryID = req->queryID; - if( ds->type == ADDR_IF_LDAP ) { -#ifdef USE_LDAP - LdapServer *server; - - server = ds->rawDataSource; - ldapsvr_new_explicit_search( server, req, folder ); -#endif - } - else { - qrymgr_delete_request( queryID ); - queryID = 0; - } + qrymgr_delete_request( queryID ); + queryID = 0; g_free( name ); return queryID; } /** - * Execute the previously registered explicit search. - * - * \param req Address query request object to execute. - * \return <i>TRUE</i> if search started successfully, or <i>FALSE</i> if - * failed. - */ -static gboolean addrindex_start_explicit( QueryRequest *req ) { - gboolean retVal; - AddrQueryObject *aqo; - - retVal = FALSE; - - /* Note: there should only be one query in the list. */ - aqo = req->queryList->data; -#ifdef USE_LDAP - if( aqo->queryType == ADDRQUERY_LDAP ) { - LdapServer *server; - LdapQuery *qry; - - qry = ( LdapQuery * ) aqo; - server = qry->server; - - /* Start the search */ - retVal = TRUE; - ldapsvr_execute_query( server, qry ); - } -#endif - return retVal; -} - -/** * Start the previously registered search. * * \param queryID ID of search query to be executed. @@ -2774,7 +2027,7 @@ gboolean addrindex_start_search( const gint queryID ) { retVal = addrindex_start_dynamic( req ); } else if( searchType == ADDRSEARCH_EXPLICIT ) { - retVal = addrindex_start_explicit( req ); + retVal = FALSE; } return retVal; @@ -2800,31 +2053,6 @@ void addrindex_remove_results( AddressDataSource *ds, ItemFolder *folder ) { /* Hide folder to prevent re-display */ addritem_folder_set_hidden( folder, TRUE ); - if( ds->type == ADDR_IF_LDAP ) { -#ifdef USE_LDAP - LdapQuery *qry; - gboolean delFlag; - - qry = ( LdapQuery * ) folder->folderData; - queryID = ADDRQUERY_ID(qry); - /* g_print( "calling ldapquery_remove_results...queryID=%d\n", queryID ); */ - delFlag = ldapquery_remove_results( qry ); - if (delFlag) { - ldapqry_free( qry ); - } - /* g_print( "calling ldapquery_remove_results...done\n" ); */ - /* - if( delFlag ) { - g_print( "delFlag IS-TRUE\n" ); - } - else { - g_print( "delFlag IS-FALSE\n" ); - } - */ -#endif - } - /* g_print( "addrindex_remove_results/end\n" ); */ - /* Delete query request */ if( queryID > 0 ) { qrymgr_delete_request( queryID ); @@ -2837,7 +2065,7 @@ void addrindex_remove_results( AddressDataSource *ds, ItemFolder *folder ) { */ static void addrindex_load_completion_load_persons( - gint (*callBackFunc) ( const gchar *, const gchar *, + gint (*callBackFunc) ( const gchar *, const gchar *, const gchar *, const gchar *, GList * ), AddressDataSource *ds) { @@ -2889,7 +2117,7 @@ static void addrindex_load_completion_load_persons( while( nodeM ) { ItemEMail *email = nodeM->data; - callBackFunc( sName, email->address, person->nickName, + callBackFunc( sName, email->address, person->nickName, ADDRITEM_NAME(email), NULL ); nodeM = g_list_next( nodeM ); @@ -2899,7 +2127,7 @@ static void addrindex_load_completion_load_persons( /* Free up the list */ g_list_free( listP ); -} +} /** * This function is used by the address completion function to load @@ -2913,7 +2141,7 @@ static void addrindex_load_completion_load_persons( */ gboolean addrindex_load_completion( - gint (*callBackFunc) ( const gchar *, const gchar *, + gint (*callBackFunc) ( const gchar *, const gchar *, const gchar *, const gchar *, GList * ), gchar *folderpath ) { @@ -2927,7 +2155,7 @@ gboolean addrindex_load_completion( subpath against the book/folder structure in order and restrict loading of addresses to that subpart (if matches). book/folder path must exist and folderpath must not be empty or NULL */ - + if( ! addressbook_peek_folder_exists( folderpath, &book, &folder ) ) { g_warning("addrindex_load_completion: folder path '%s' doesn't exist", folderpath); return FALSE; @@ -2958,7 +2186,7 @@ gboolean addrindex_load_completion( while( nodeM ) { ItemEMail *email = nodeM->data; - callBackFunc( sName, email->address, person->nickName, + callBackFunc( sName, email->address, person->nickName, ADDRITEM_NAME(email), NULL ); nodeM = g_list_next( nodeM ); @@ -3070,7 +2298,7 @@ gboolean addrindex_load_person_attribute( /* Process each User Attribute */ while( nodeA ) { UserAttribute *attrib = nodeA->data; - if( attrib->name && + if( attrib->name && !strcmp( attrib->name,attr ) ) { callBackFunc(person, cur_bname); } @@ -3150,7 +2378,7 @@ gchar *addrindex_get_picture_file(const gchar *emailaddr) gboolean found = FALSE; gchar *filename = NULL; gchar *raw_addr = NULL; - + if (!emailaddr) return NULL; @@ -3190,8 +2418,8 @@ gchar *addrindex_get_picture_file(const gchar *emailaddr) ItemEMail *email = nodeM->data; if (email->address && !strcasecmp(raw_addr, email->address)) { found = TRUE; - filename = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, - ADDRBOOK_DIR, G_DIR_SEPARATOR_S, + filename = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, + ADDRBOOK_DIR, G_DIR_SEPARATOR_S, person->picture, ".png", NULL ); break; } @@ -3209,52 +2437,6 @@ gchar *addrindex_get_picture_file(const gchar *emailaddr) return filename; } -#ifdef USE_LDAP -GSList *addrindex_get_password_protected_ldap_servers() -{ - AddressInterface *iface; - AddressDataSource *ds; - GList *nodeIf; - GList *nodeDS; - GSList *list = NULL; - LdapServer *server; - LdapControl *ctl; - - nodeIf = _addressIndex_->searchOrder; - while (nodeIf) { - iface = nodeIf->data; - nodeIf = g_list_next(nodeIf); - - if (!iface->useInterface) - continue; - if (!iface->externalQuery) - continue; - if (iface->type != ADDR_IF_LDAP) - continue; - - nodeDS = iface->listSource; - while (nodeDS) { - ds = nodeDS->data; - nodeDS = g_list_next(nodeDS); - server = ds->rawDataSource; - if (!server->searchFlag) - continue; - - ctl = server->control; - - if (!ctl) - continue; - - if (ctl->bindDN != NULL && strlen(ctl->bindDN)) { - list = g_slist_append(list, server); - } - } - } - - return list; -} -#endif /* USE_LDAP */ - /* * End of Source. */ diff --git a/src/addrindex.h b/src/addrindex.h @@ -14,7 +14,7 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * */ /* @@ -38,8 +38,6 @@ typedef enum { ADDR_IF_NONE, ADDR_IF_BOOK, ADDR_IF_VCARD, - ADDR_IF_JPILOT, - ADDR_IF_LDAP, ADDR_IF_COMMON, ADDR_IF_PERSONAL } AddressIfType; @@ -159,8 +157,8 @@ gint addrindex_setup_static_search ( AddressDataSource *ds, gboolean addrindex_start_search ( const gint queryID ); void addrindex_stop_search ( const gint queryID ); -gint addrindex_setup_explicit_search ( AddressDataSource *ds, - const gchar *searchTerm, +gint addrindex_setup_explicit_search ( AddressDataSource *ds, + const gchar *searchTerm, ItemFolder *folder, void *callBackEnd, void *callBackEntry ); @@ -169,7 +167,7 @@ void addrindex_remove_results ( AddressDataSource *ds, gboolean addrindex_load_completion( gint (*callBackFunc) - ( const gchar *, const gchar *, + ( const gchar *, const gchar *, const gchar *, const gchar *, GList * ), gchar *folderpath ); @@ -179,11 +177,7 @@ gboolean addrindex_load_person_attribute( const gchar *attr, gboolean addrindex_load_person_ds( gint (*callBackFunc) ( ItemPerson *, AddressDataSource * ) ); -gchar *addrindex_get_picture_file(const gchar *emailaddr); - -#ifdef USE_LDAP -GSList *addrindex_get_password_protected_ldap_servers(); -#endif +gchar *addrindex_get_picture_file(const gchar *emailaddr); #endif /* __ADDRINDEX_H__ */ diff --git a/src/addrmerge.c b/src/addrmerge.c @@ -12,7 +12,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ @@ -28,10 +28,6 @@ #include "defs.h" -#ifdef USE_LDAP -#include "ldapserver.h" -#include "ldapupdate.h" -#endif #include "addrbook.h" #include "addressbook.h" #include "addressitem.h" @@ -147,13 +143,6 @@ static void addrmerge_do_merge(struct AddrMergePage *page) addrbook_set_dirty( page->abf, TRUE ); addressbook_export_to_file(); -#ifdef USE_LDAP - if (page->ds && page->ds->type == ADDR_IF_LDAP) { - LdapServer *server = page->ds->rawDataSource; - ldapsvr_set_modified(server, TRUE); - ldapsvr_update_book(server, NULL); - } -#endif gtk_cmclist_thaw(GTK_CMCLIST(page->clist)); addrmerge_done(page); @@ -190,7 +179,7 @@ static void addrmerge_picture_selected(GtkTreeView *treeview, GList *list; ItemPerson *pictureTarget; - /* Get selected picture target */ + /* Get selected picture target */ model = gtk_icon_view_get_model(GTK_ICON_VIEW(page->iconView)); list = gtk_icon_view_get_selected_items(GTK_ICON_VIEW(page->iconView)); page->target = NULL; diff --git a/src/addrquery.h b/src/addrquery.h @@ -14,7 +14,7 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * */ /* @@ -31,7 +31,6 @@ /* Query types */ #define ADDRQUERY_NONE 0 -#define ADDRQUERY_LDAP 1 /* Search type */ typedef enum { diff --git a/src/browseldap.c b/src/browseldap.c @@ -1,444 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2003-2024 the Claws Mail team and Match Grun - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * Browse LDAP entry. - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#include "claws-features.h" -#endif - -#ifdef USE_LDAP - -#include "defs.h" - -#include <glib.h> -#include <glib/gi18n.h> -#include <gdk/gdkkeysyms.h> -#include <gtk/gtk.h> - -#include <pthread.h> -#include "gtkutils.h" -#include "stock_pixmap.h" -#include "prefs_common.h" -#include "browseldap.h" -#include "addritem.h" -#include "addrindex.h" -#include "manage_window.h" - -#include "ldapquery.h" -#include "ldapserver.h" -#include "ldaplocate.h" - -typedef enum { - COL_NAME, - COL_VALUE, - N_COLS -} LDAPEntryColumnPos; - -#define BROWSELDAP_WIDTH 450 -#define BROWSELDAP_HEIGHT 420 - -#define COL_WIDTH_NAME 140 -#define COL_WIDTH_VALUE 140 - -static struct _LDAPEntry_dlg { - GtkWidget *window; - GtkWidget *label_server; - GtkWidget *label_address; - GtkWidget *list_view; - GtkWidget *close_btn; -} browseldap_dlg; - -/** - * Message queue. - */ -static GList *_displayQueue_ = NULL; - -/** - * Mutex to protect callback from multiple threads. - */ -static pthread_mutex_t _browseMutex_ = PTHREAD_MUTEX_INITIALIZER; - -/** - * Current query ID. - */ -static gint _queryID_ = 0; - -/** - * Completion idle ID. - */ -static guint _browseIdleID_ = 0; - -/** - * Search complete indicator. - */ -static gboolean _searchComplete_ = FALSE; - -/** - * Callback entry point for each LDAP entry processed. The background thread - * (if any) appends the address list to the display queue. - * - * \param qry LDAP query object. - * \param queryID Query ID of search request. - * \param listEMail List of zero of more email objects that met search - * criteria. - * \param data User data. - */ -static gint browse_callback_entry( - LdapQuery *qry, gint queryID, GList *listValues, gpointer data ) -{ - GList *node; - NameValuePair *nvp; - - debug_print("browse_callback_entry...\n"); - pthread_mutex_lock( & _browseMutex_ ); - /* Append contents to end of display queue */ - node = listValues; - while( node ) { - nvp = ( NameValuePair * ) node->data; - debug_print("adding to list: %s->%s\n", - nvp->name?nvp->name:"null", - nvp->value?nvp->value:"null"); - _displayQueue_ = g_list_append( _displayQueue_, nvp ); - node->data = NULL; - node = g_list_next( node ); - } - pthread_mutex_unlock( & _browseMutex_ ); - /* g_print( "browse_callback_entry...done\n" ); */ - - return 0; -} - -/** - * Callback entry point for end of LDAP locate search. - * - * \param qry LDAP query object. - * \param queryID Query ID of search request. - * \param status Status/error code. - * \param data User data. - */ -static gint browse_callback_end( - LdapQuery *qry, gint queryID, gint status, gpointer data ) -{ - debug_print("search completed\n"); - _searchComplete_ = TRUE; - return 0; -} - -/** - * Clear the display queue. - */ -static void browse_clear_queue( void ) { - /* Clear out display queue */ - pthread_mutex_lock( & _browseMutex_ ); - - ldapqry_free_list_name_value( _displayQueue_ ); - _displayQueue_ = NULL; - - pthread_mutex_unlock( & _browseMutex_ ); -} - -/** - * Close window callback. - * \param widget Widget. - * \param event Event. - * \param cancelled Cancelled flag. - */ -static gint browse_delete_event( - GtkWidget *widget, GdkEventAny *event, gboolean *cancelled ) -{ - gtk_main_quit(); - return TRUE; -} - -/** - * Respond to key press in window. - * \param widget Widget. - * \param event Event. - * \param cancelled Cancelled flag. - */ -static void browse_key_pressed( - GtkWidget *widget, GdkEventKey *event, gboolean *cancelled ) -{ - if (event && event->keyval == GDK_KEY_Escape) { - gtk_main_quit(); - } -} - -/** - * Callback to close window. - * \param widget Widget. - * \param cancelled Cancelled flag. - */ -static void browse_close( GtkWidget *widget, gboolean *cancelled ) { - gtk_main_quit(); -} - -/** - * Create the window to display data. - */ -static void browse_create( void ) { - GtkWidget *window; - GtkWidget *vbox; - GtkWidget *table; - GtkWidget *label; - GtkWidget *label_server; - GtkWidget *label_addr; - GtkWidget *vlbox; - GtkWidget *tree_win; - GtkWidget *hbbox; - GtkWidget *close_btn; - GtkWidget *content_area; - GtkWidget *view; - GtkListStore *store; - GtkTreeSelection *sel; - GtkCellRenderer *rdr; - GtkTreeViewColumn *col; - - debug_print("creating browse widget\n"); - window = gtk_dialog_new(); - gtk_widget_set_size_request( window, BROWSELDAP_WIDTH, BROWSELDAP_HEIGHT ); - gtk_container_set_border_width( GTK_CONTAINER(window), 0 ); - gtk_window_set_title( GTK_WINDOW(window), _("Browse Directory Entry") ); - gtk_window_set_position( GTK_WINDOW(window), GTK_WIN_POS_MOUSE ); - g_signal_connect(G_OBJECT(window), "delete_event", - G_CALLBACK(browse_delete_event), NULL); - g_signal_connect(G_OBJECT(window), "key_press_event", - G_CALLBACK(browse_key_pressed), NULL); - - vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8); - content_area = gtk_dialog_get_content_area(GTK_DIALOG(window)); - gtk_box_pack_start(GTK_BOX(content_area), vbox, TRUE, TRUE, 0); - gtk_container_set_border_width( GTK_CONTAINER(vbox), 8 ); - - table = gtk_grid_new(); - gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); - gtk_container_set_border_width( GTK_CONTAINER(table), 8 ); - gtk_grid_set_row_spacing(GTK_GRID(table), 8); - gtk_grid_set_column_spacing(GTK_GRID(table), 8); - - /* First row */ - label = gtk_label_new(_("Server Name:")); - gtk_grid_attach(GTK_GRID(table), label, 0, 0, 1, 1); - gtk_label_set_xalign(GTK_LABEL(label), 1.0); - - label_server = gtk_label_new(""); - gtk_label_set_xalign(GTK_LABEL(label_server), 0.0); - gtk_grid_attach(GTK_GRID(table), label, 1, 0, 1, 1); - gtk_widget_set_hexpand(label_server, TRUE); - gtk_widget_set_halign(label_server, GTK_ALIGN_FILL); - - /* Second row */ - label = gtk_label_new(_("Distinguished Name (dn):")); - gtk_label_set_xalign(GTK_LABEL(label), 1.0); - gtk_grid_attach(GTK_GRID(table), label, 0, 1, 1, 1); - - label_addr = gtk_label_new(""); - gtk_label_set_xalign(GTK_LABEL(label_addr), 0.0); - gtk_grid_attach(GTK_GRID(table), label_addr, 1, 1, 1, 1); - gtk_widget_set_hexpand(label_addr, TRUE); - gtk_widget_set_halign(label_addr, GTK_ALIGN_FILL); - - /* Address book/folder tree */ - vlbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8); - gtk_box_pack_start(GTK_BOX(vbox), vlbox, TRUE, TRUE, 0); - gtk_container_set_border_width( GTK_CONTAINER(vlbox), 8 ); - - tree_win = gtk_scrolled_window_new( NULL, NULL ); - gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(tree_win), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC ); - gtk_box_pack_start( GTK_BOX(vlbox), tree_win, TRUE, TRUE, 0 ); - - store = gtk_list_store_new(N_COLS, - G_TYPE_STRING, G_TYPE_STRING, - -1); - - view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); - gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), TRUE); - gtk_tree_view_set_reorderable(GTK_TREE_VIEW(view), FALSE); - sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); - gtk_tree_selection_set_mode(sel, GTK_SELECTION_NONE); - - rdr = gtk_cell_renderer_text_new(); - col = gtk_tree_view_column_new_with_attributes(_("LDAP Name"), rdr, - "markup", COL_NAME, NULL); - gtk_tree_view_column_set_min_width(col, COL_WIDTH_NAME); - gtk_tree_view_append_column(GTK_TREE_VIEW(view), col); - - rdr = gtk_cell_renderer_text_new(); - col = gtk_tree_view_column_new_with_attributes(_("Attribute Value"), rdr, - "markup", COL_VALUE, NULL); - gtk_tree_view_column_set_min_width(col, COL_WIDTH_VALUE); - gtk_tree_view_append_column(GTK_TREE_VIEW(view), col); - - gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), - COL_NAME, GTK_SORT_ASCENDING); - g_object_unref(store); - - gtk_container_add( GTK_CONTAINER(tree_win), view ); - - /* Button panel */ - gtkut_stock_button_set_create(&hbbox, &close_btn, "window-close", _("_Close"), - NULL, NULL, NULL, NULL, NULL, NULL); - gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0); - gtk_container_set_border_width( GTK_CONTAINER(hbbox), 0 ); - - g_signal_connect(G_OBJECT(close_btn), "clicked", - G_CALLBACK(browse_close), NULL); - gtk_widget_grab_default(close_btn); - - gtk_widget_show_all(vbox); - - browseldap_dlg.window = window; - browseldap_dlg.label_server = label_server; - browseldap_dlg.label_address = label_addr; - browseldap_dlg.list_view = view; - browseldap_dlg.close_btn = close_btn; - - gtk_widget_show_all( window ); - -} - -/** - * Idler function. This function is called by the main (UI) thread during UI - * idle time while an address search is in progress. Items from the display - * queue are processed and appended to the address list. - * - * \param data Target data object. - * \return <i>TRUE</i> to ensure that idle event do not get ignored. - */ -static gboolean browse_idle( gpointer data ) { - GList *node; - NameValuePair *nvp; - GtkWidget *view = browseldap_dlg.list_view; - GtkListStore *store = GTK_LIST_STORE( - gtk_tree_view_get_model(GTK_TREE_VIEW(view))); - GtkTreeIter iter; - - /* Process all entries in display queue */ - pthread_mutex_lock( & _browseMutex_ ); - if( _displayQueue_ ) { - node = _displayQueue_; - while( node ) { - /* Add entry into list */ - nvp = ( NameValuePair * ) node->data; - debug_print("Adding row to list: %s->%s\n", - nvp->name?nvp->name:"null", - nvp->value?nvp->value:"null"); - gtk_list_store_append(store, &iter); - gtk_list_store_set(store, &iter, - COL_NAME, nvp->name, - COL_VALUE, nvp->value, - -1); - - /* Free up entry */ - ldapqry_free_name_value( nvp ); - node->data = NULL; - node = g_list_next( node ); - } - g_list_free( _displayQueue_ ); - _displayQueue_ = NULL; - } - pthread_mutex_unlock( & _browseMutex_ ); - - if( _searchComplete_ ) { - /* Remove idler */ - if( _browseIdleID_ != 0 ) { - g_source_remove( _browseIdleID_ ); - _browseIdleID_ = 0; - } - } - - return TRUE; -} - -/** - * Main entry point to browse LDAP entries. - * \param ds Data source to process. - * \param dn Distinguished name to retrieve. - * \return <code>TRUE</code> - */ -gboolean browseldap_entry( AddressDataSource *ds, const gchar *dn ) { - LdapServer *server; - GtkWidget *view; - GtkListStore *store; - - _queryID_ = 0; - _browseIdleID_ = 0; - - server = ds->rawDataSource; - - if( ! browseldap_dlg.window ) browse_create(); - gtk_widget_grab_focus(browseldap_dlg.close_btn); - gtk_widget_show(browseldap_dlg.window); - manage_window_set_transient(GTK_WINDOW(browseldap_dlg.window)); - gtk_window_set_modal(GTK_WINDOW(browseldap_dlg.window), TRUE); - gtk_widget_show(browseldap_dlg.window); - - gtk_label_set_text( GTK_LABEL(browseldap_dlg.label_address ), "" ); - if( dn ) { - gtk_label_set_text( - GTK_LABEL(browseldap_dlg.label_address ), dn ); - } - gtk_label_set_text( - GTK_LABEL(browseldap_dlg.label_server ), - ldapsvr_get_name( server ) ); - - debug_print("browsing server: %s\n", ldapsvr_get_name(server)); - /* Setup search */ - _searchComplete_ = FALSE; - _queryID_ = ldaplocate_search_setup( - server, dn, browse_callback_entry, browse_callback_end ); - debug_print("query id: %d\n", _queryID_); - _browseIdleID_ = g_idle_add( (GSourceFunc) browse_idle, NULL ); - - /* Start search */ - debug_print("starting search\n"); - ldaplocate_search_start( _queryID_ ); - - /* Display dialog */ - gtk_main(); - gtk_widget_hide( browseldap_dlg.window ); - gtk_window_set_modal(GTK_WINDOW(browseldap_dlg.window), FALSE); - /* Stop query */ - debug_print("stopping search\n"); - ldaplocate_search_stop( _queryID_ ); - - if( _browseIdleID_ != 0 ) { - g_source_remove( _browseIdleID_ ); - _browseIdleID_ = 0; - } - browse_clear_queue(); - - view = browseldap_dlg.list_view; - store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(view))); - gtk_list_store_clear(store); - - return TRUE; -} - -#endif /* USE_LDAP */ - -/* -* End of Source. -*/ - diff --git a/src/browseldap.h b/src/browseldap.h @@ -1,35 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2003-2012 Match Grun and the Claws Mail team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -/* - * Browse LDAP entry. - */ - -#ifndef __BROWSE_LDAP_H__ -#define __BROWSE_LDAP_H__ - -#ifdef USE_LDAP - -#include "addrindex.h" - -gboolean browseldap_entry( AddressDataSource *ds, const gchar *dn ); - -#endif /* USE_LDAP */ - -#endif /* __BROWSE_LDAP_H__ */ diff --git a/src/compose.c b/src/compose.c @@ -114,11 +114,6 @@ #include "headers.h" #include "file-utils.h" -#ifdef USE_LDAP -#include "password.h" -#include "ldapserver.h" -#endif - enum { COL_MIMETYPE = 0, @@ -233,7 +228,7 @@ static Compose *compose_followup_and_reply_to (MsgInfo *msginfo, gboolean to_all, gboolean to_sender, const gchar *body); -static Compose *compose_forward_multiple (PrefsAccount *account, +static Compose *compose_forward_multiple (PrefsAccount *account, GSList *msginfo_list); static Compose *compose_reply (MsgInfo *msginfo, ComposeQuoteMode quote_mode, @@ -241,8 +236,8 @@ static Compose *compose_reply (MsgInfo *msginfo, gboolean to_ml, gboolean to_sender, const gchar *body); -static Compose *compose_reply_mode (ComposeMode mode, - GSList *msginfo_list, +static Compose *compose_reply_mode (ComposeMode mode, + GSList *msginfo_list, gchar *body); static void compose_template_apply_fields(Compose *compose, Template *tmpl); static void compose_update_privacy_systems_menu(Compose *compose); @@ -406,9 +401,9 @@ static gboolean compose_edit_size_alloc (GtkEditable *widget, GtkSHRuler *shruler); static void account_activated (GtkComboBox *optmenu, gpointer data); -static void attach_selected (GtkTreeView *tree_view, +static void attach_selected (GtkTreeView *tree_view, GtkTreePath *tree_path, - GtkTreeViewColumn *column, + GtkTreeViewColumn *column, Compose *compose); static gboolean attach_button_pressed (GtkWidget *widget, GdkEventButton *event, @@ -499,7 +494,7 @@ static void compose_toggle_encrypt_cb (GtkToggleAction *action, gpointer data); static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data); static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn); -static void compose_activate_privacy_system (Compose *compose, +static void compose_activate_privacy_system (Compose *compose, PrefsAccount *account, gboolean warn); static void compose_apply_folder_privacy_settings(Compose *compose, FolderItem *folder_item); @@ -711,7 +706,7 @@ static GtkActionEntry compose_entries[] = {"Options/Encoding/Thai", NULL, N_("Thai"), NULL, NULL, NULL }, /* Tools menu */ - {"Tools/AddressBook", NULL, N_("_Address book"), "<shift><control>A", NULL, G_CALLBACK(compose_address_cb) }, + {"Tools/AddressBook", NULL, N_("_Address book"), "<shift><control>A", NULL, G_CALLBACK(compose_address_cb) }, {"Tools/Template", NULL, N_("_Template"), NULL, NULL, NULL }, {"Tools/Template/PlaceHolder", NULL, "Placeholder", NULL, NULL, G_CALLBACK(compose_nothing_cb) }, @@ -719,7 +714,7 @@ static GtkActionEntry compose_entries[] = {"Tools/Actions/PlaceHolder", NULL, "Placeholder", NULL, NULL, G_CALLBACK(compose_nothing_cb) }, /* Help menu */ - {"Help/About", NULL, N_("_About"), NULL, NULL, G_CALLBACK(about_show_cb) }, + {"Help/About", NULL, N_("_About"), NULL, NULL, G_CALLBACK(about_show_cb) }, }; static GtkToggleActionEntry compose_toggle_entries[] = @@ -798,9 +793,9 @@ static gboolean compose_put_existing_to_front(MsgInfo *info) { const GList *compose_list = compose_get_compose_list(); const GList *elem = NULL; - + if (compose_list) { - for (elem = compose_list; elem != NULL && elem->data != NULL; + for (elem = compose_list; elem != NULL && elem->data != NULL; elem = elem->next) { Compose *c = (Compose*)elem->data; @@ -855,7 +850,7 @@ static void compose_create_tags(GtkTextView *text, Compose *compose) signature_color = prefs_common.color[COL_SIGNATURE]; uri_color = prefs_common.color[COL_URI]; } else { - signature_color = quote_color1 = quote_color2 = quote_color3 = + signature_color = quote_color1 = quote_color2 = quote_color3 = quote_bgcolor1 = quote_bgcolor2 = quote_bgcolor3 = uri_color = black; } @@ -883,11 +878,11 @@ static void compose_create_tags(GtkTextView *text, Compose *compose) "foreground-rgba", &quote_color3, NULL); } - + compose->signature_tag = gtk_text_buffer_create_tag(buffer, "signature", "foreground-rgba", &signature_color, NULL); - + compose->uri_tag = gtk_text_buffer_create_tag(buffer, "link", "foreground-rgba", &uri_color, NULL); @@ -944,7 +939,7 @@ static gchar *compose_get_save_to(Compose *compose) gchar *result = NULL; entry = GTK_EDITABLE(gtk_bin_get_child(GTK_BIN(compose->savemsg_combo))); result = gtk_editable_get_chars(entry, 0, -1); - + if (result) { combobox_unset_popdown_strings(GTK_COMBO_BOX_TEXT(compose->savemsg_combo)); prefs_common.compose_save_to_history = add_history( @@ -1087,7 +1082,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI * CLAWS: just don't allow return receipt request, even if the user * may want to send an email. simple but foolproof. */ - cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Options/RequestRetRcpt", FALSE); + cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Options/RequestRetRcpt", FALSE); } compose_add_field_list( compose, listAddress ); @@ -1205,7 +1200,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI } /* Place cursor according to provided input (mfield) */ - switch (mfield) { + switch (mfield) { case NO_FIELD_PRESENT: if (compose->header_last) gtk_widget_grab_focus(compose->header_last->entry); @@ -1228,7 +1223,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI mark = gtk_text_buffer_get_insert(textbuf); gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark); gtk_text_buffer_insert(textbuf, &iter, "", -1); - /* + /* * SUBJECT_FIELD_PRESENT and BODY_FIELD_PRESENT * only defers where it comes to the variable body * is not null. If no body is present compose->text @@ -1303,7 +1298,7 @@ static void compose_force_encryption(Compose *compose, PrefsAccount *account, compose_update_privacy_system_menu_item(compose, FALSE); compose_use_encryption(compose, TRUE); } -} +} static void compose_force_signing(Compose *compose, PrefsAccount *account, const gchar *system) { @@ -1334,14 +1329,14 @@ static void compose_force_signing(Compose *compose, PrefsAccount *account, const compose_update_privacy_system_menu_item(compose, FALSE); compose_use_signing(compose, TRUE); } -} +} static Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body) { MsgInfo *msginfo; guint list_len; Compose *compose = NULL; - + cm_return_val_if_fail(msginfo_list != NULL, NULL); msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0); @@ -1356,11 +1351,11 @@ static Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar FALSE, prefs_common.default_reply_list, FALSE, body); break; case COMPOSE_REPLY_WITH_QUOTE: - compose = compose_reply(msginfo, COMPOSE_QUOTE_FORCED, + compose = compose_reply(msginfo, COMPOSE_QUOTE_FORCED, FALSE, prefs_common.default_reply_list, FALSE, body); break; case COMPOSE_REPLY_WITHOUT_QUOTE: - compose = compose_reply(msginfo, COMPOSE_QUOTE_SKIP, + compose = compose_reply(msginfo, COMPOSE_QUOTE_SKIP, FALSE, prefs_common.default_reply_list, FALSE, NULL); break; case COMPOSE_REPLY_TO_SENDER: @@ -1373,11 +1368,11 @@ static Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar FALSE, FALSE, body); break; case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE: - compose = compose_reply(msginfo, COMPOSE_QUOTE_FORCED, + compose = compose_reply(msginfo, COMPOSE_QUOTE_FORCED, FALSE, FALSE, TRUE, body); break; case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE: - compose = compose_reply(msginfo, COMPOSE_QUOTE_SKIP, + compose = compose_reply(msginfo, COMPOSE_QUOTE_SKIP, FALSE, FALSE, TRUE, NULL); break; case COMPOSE_REPLY_TO_ALL: @@ -1385,11 +1380,11 @@ static Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar TRUE, FALSE, FALSE, body); break; case COMPOSE_REPLY_TO_ALL_WITH_QUOTE: - compose = compose_reply(msginfo, COMPOSE_QUOTE_FORCED, + compose = compose_reply(msginfo, COMPOSE_QUOTE_FORCED, TRUE, FALSE, FALSE, body); break; case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE: - compose = compose_reply(msginfo, COMPOSE_QUOTE_SKIP, + compose = compose_reply(msginfo, COMPOSE_QUOTE_SKIP, TRUE, FALSE, FALSE, NULL); break; case COMPOSE_REPLY_TO_LIST: @@ -1397,11 +1392,11 @@ static Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar FALSE, TRUE, FALSE, body); break; case COMPOSE_REPLY_TO_LIST_WITH_QUOTE: - compose = compose_reply(msginfo, COMPOSE_QUOTE_FORCED, + compose = compose_reply(msginfo, COMPOSE_QUOTE_FORCED, FALSE, TRUE, FALSE, body); break; case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE: - compose = compose_reply(msginfo, COMPOSE_QUOTE_SKIP, + compose = compose_reply(msginfo, COMPOSE_QUOTE_SKIP, FALSE, TRUE, FALSE, NULL); break; case COMPOSE_FORWARD: @@ -1418,7 +1413,7 @@ static Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar if (list_len == 1) { compose = compose_forward(NULL, msginfo, FALSE, body, FALSE, FALSE); break; - } + } /* more messages FALL THROUGH */ case COMPOSE_FORWARD_AS_ATTACH: compose = compose_forward_multiple(NULL, msginfo_list); @@ -1429,7 +1424,7 @@ static Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar default: g_warning("compose_reply_mode(): invalid Write Mode: %d", mode); } - + if (compose == NULL) { alertpanel_error(_("Unable to reply. The original email probably doesn't exist.")); return NULL; @@ -1476,10 +1471,10 @@ static Compose *compose_reply(MsgInfo *msginfo, ComposeQuoteMode quote_mode, gboolean to_all, gboolean to_ml, - gboolean to_sender, + gboolean to_sender, const gchar *body) { - return compose_generic_reply(msginfo, quote_mode, to_all, to_ml, + return compose_generic_reply(msginfo, quote_mode, to_all, to_ml, to_sender, FALSE, body); } @@ -1489,7 +1484,7 @@ static Compose *compose_followup_and_reply_to(MsgInfo *msginfo, gboolean to_sender, const gchar *body) { - return compose_generic_reply(msginfo, quote_mode, to_all, FALSE, + return compose_generic_reply(msginfo, quote_mode, to_all, FALSE, to_sender, TRUE, body); } @@ -1509,7 +1504,7 @@ static void compose_extract_original_charset(Compose *compose) while (partinfo && partinfo->type != MIMETYPE_TEXT) partinfo = procmime_mimeinfo_next(partinfo); if (partinfo) { - compose->orig_charset = + compose->orig_charset = g_strdup(procmime_mimeinfo_get_parameter( partinfo, "charset")); } @@ -1571,7 +1566,7 @@ static Compose *compose_generic_reply(MsgInfo *msginfo, compose->replyinfo = procmsg_msginfo_copy(msginfo); compose_extract_original_charset(compose); - + if (msginfo->folder && msginfo->folder->ret_rcpt) cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Options/RequestRetRcpt", TRUE); @@ -1687,7 +1682,7 @@ static Compose *compose_generic_reply(MsgInfo *msginfo, COMPOSE_PRIVACY_WARNING(); SIGNAL_BLOCK(textbuf); - + if (account->auto_sig) compose_insert_sig(compose, FALSE); @@ -1699,21 +1694,21 @@ static Compose *compose_generic_reply(MsgInfo *msginfo, gtkaspell_unblock_check(compose->gtkaspell); #endif SIGNAL_UNBLOCK(textbuf); - + gtk_widget_grab_focus(compose->text); undo_unblock(compose->undostruct); if (prefs_common.auto_exteditor) compose_exec_ext_editor(compose); - + compose->modified = FALSE; compose_set_title(compose); compose->updating = FALSE; compose->draft_timeout_tag = COMPOSE_DRAFT_TIMEOUT_UNSET; /* desinhibit auto-drafting after loading */ SCROLL_TO_CURSOR(compose); - + if (compose->deferred_destroy) { compose_destroy(compose); return NULL; @@ -1780,7 +1775,7 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo, buf2 = g_strdup_printf("Fw: %s", buf); gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2); - + g_free(buf); g_free(buf2); } @@ -1829,7 +1824,7 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo, textview = GTK_TEXT_VIEW(compose->text); textbuf = gtk_text_view_get_buffer(textview); compose_create_tags(textview, compose); - + undo_block(compose->undostruct); if (as_attach) { gchar *msgfile; @@ -1898,7 +1893,7 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo, gtkaspell_unblock_check(compose->gtkaspell); #endif SIGNAL_UNBLOCK(textbuf); - + if (privacy_system_can_sign(compose->privacy_system) == FALSE && (account->default_encrypt || account->default_sign)) COMPOSE_PRIVACY_WARNING(); @@ -1911,7 +1906,7 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo, if (!no_extedit && prefs_common.auto_exteditor) compose_exec_ext_editor(compose); - + /*save folder*/ if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) { gchar *folderidentifier; @@ -1924,7 +1919,7 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo, } undo_unblock(compose->undostruct); - + compose->modified = FALSE; compose_set_title(compose); @@ -1953,7 +1948,7 @@ static Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_ GSList *msginfo; gchar *msgfile; gboolean single_mail = TRUE; - + cm_return_val_if_fail(msginfo_list != NULL, NULL); if (g_slist_length(msginfo_list) > 1) @@ -1964,7 +1959,7 @@ static Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_ return NULL; /* guess account from first selected message */ - if (!account && + if (!account && !(account = compose_find_account(msginfo_list->data))) account = cur_account; @@ -2030,7 +2025,7 @@ static Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_ textview = GTK_TEXT_VIEW(compose->text); textbuf = gtk_text_view_get_buffer(textview); compose_create_tags(textview, compose); - + undo_block(compose->undostruct); for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) { msgfile = procmsg_get_message_file((MsgInfo *)msginfo->data); @@ -2042,7 +2037,7 @@ static Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_ "message/rfc822", NULL); g_free(msgfile); } - + if (single_mail) { MsgInfo *info = (MsgInfo *)msginfo_list->data; if (info->subject && *info->subject) { @@ -2064,14 +2059,14 @@ static Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_ } SIGNAL_BLOCK(textbuf); - + if (account->auto_sig) compose_insert_sig(compose, FALSE); compose_wrap_all(compose); SIGNAL_UNBLOCK(textbuf); - + gtk_text_buffer_get_start_iter(textbuf, &iter); gtk_text_buffer_place_cursor(textbuf, &iter); @@ -2097,7 +2092,7 @@ static Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_ return compose; } -static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, GtkTextIter *iter) +static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, GtkTextIter *iter) { GtkTextIter start = *iter; GtkTextIter end_iter; @@ -2105,7 +2100,7 @@ static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbu gchar *str = NULL; if (!compose->account->sig_sep) return FALSE; - + gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter, start_pos+strlen(compose->account->sig_sep)); @@ -2124,7 +2119,7 @@ static gboolean compose_is_sig_separator(Compose *compose, GtkTextBuffer *textbu g_free(tmp); return TRUE; } - g_free(tmp); + g_free(tmp); } g_free(str); @@ -2244,82 +2239,82 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch) gint id, param; /* Select Account from queue headers */ - if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, + if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, "X-Claws-Account-Id:")) { id = atoi(&queueheader_buf[strlen("X-Claws-Account-Id:")]); account = account_find_from_id(id); g_free(queueheader_buf); } - if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, + if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, "X-Sylpheed-Account-Id:")) { id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]); account = account_find_from_id(id); g_free(queueheader_buf); } - if (!account && !procheader_get_header_from_msginfo(msginfo, &queueheader_buf, + if (!account && !procheader_get_header_from_msginfo(msginfo, &queueheader_buf, "NAID:")) { id = atoi(&queueheader_buf[strlen("NAID:")]); account = account_find_from_id(id); g_free(queueheader_buf); } - if (!account && !procheader_get_header_from_msginfo(msginfo, &queueheader_buf, + if (!account && !procheader_get_header_from_msginfo(msginfo, &queueheader_buf, "MAID:")) { id = atoi(&queueheader_buf[strlen("MAID:")]); account = account_find_from_id(id); g_free(queueheader_buf); } - if (!account && !procheader_get_header_from_msginfo(msginfo, &queueheader_buf, + if (!account && !procheader_get_header_from_msginfo(msginfo, &queueheader_buf, "S:")) { account = account_find_from_address(queueheader_buf, FALSE); g_free(queueheader_buf); } - if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, + if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, "X-Claws-Sign:")) { param = atoi(&queueheader_buf[strlen("X-Claws-Sign:")]); use_signing = param; g_free(queueheader_buf); } - if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, + if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, "X-Sylpheed-Sign:")) { param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]); use_signing = param; g_free(queueheader_buf); } - if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, + if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, "X-Claws-Encrypt:")) { param = atoi(&queueheader_buf[strlen("X-Claws-Encrypt:")]); use_encryption = param; g_free(queueheader_buf); } - if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, + if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, "X-Sylpheed-Encrypt:")) { param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]); use_encryption = param; g_free(queueheader_buf); } - if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, + if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, "X-Claws-Auto-Wrapping:")) { param = atoi(&queueheader_buf[strlen("X-Claws-Auto-Wrapping:")]); autowrap = param; g_free(queueheader_buf); } - if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, + if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, "X-Claws-Auto-Indent:")) { param = atoi(&queueheader_buf[strlen("X-Claws-Auto-Indent:")]); autoindent = param; g_free(queueheader_buf); } - if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, + if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, "X-Claws-Privacy-System:")) { privacy_system = g_strdup(&queueheader_buf[strlen("X-Claws-Privacy-System:")]); g_free(queueheader_buf); } - if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, + if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, "X-Sylpheed-Privacy-System:")) { privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]); g_free(queueheader_buf); } - if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, + if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, "X-Priority: ")) { param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */ priority = param; @@ -2338,7 +2333,7 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch) g_strfreev(tokens); g_free(queueheader_buf); } - if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, + if (!procheader_get_header_from_msginfo(msginfo, &queueheader_buf, "FMID:")) { gchar **tokens = g_strsplit(&queueheader_buf[strlen("FMID:")], "\t", 0); if (tokens && tokens[0] && tokens[1] && tokens[2]) { @@ -2437,7 +2432,7 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch) g_free(queueheader_buf); } } - + if (compose_parse_header(compose, msginfo) < 0) { compose->updating = FALSE; compose_destroy(compose); @@ -2457,7 +2452,7 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch) g_signal_handlers_block_by_func(G_OBJECT(textbuf), G_CALLBACK(compose_changed_cb), compose); - + if (MSG_IS_ENCRYPTED(msginfo->flags)) { fp = procmime_get_first_encrypted_text_content(msginfo); if (fp) { @@ -2482,7 +2477,7 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch) UNBLOCK_WRAP(); claws_fclose(fp); } - + compose_attach_parts(compose, msginfo); compose_colorize_signature(compose); @@ -2517,9 +2512,9 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch) compose_destroy(compose); return NULL; } - + compose->sig_str = account_get_signature_str(compose->account); - + hooks_invoke(COMPOSE_CREATED_HOOKLIST, compose); return compose; @@ -2561,7 +2556,7 @@ Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo, } compose->redirect_filename = filename; - + /* Set save folder */ item = msginfo->folder; if (item && item->prefs && item->prefs->save_copy_to_folder) { @@ -2602,7 +2597,7 @@ Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo, cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Options", FALSE); cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Tools/ShowRuler", FALSE); cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Tools/Actions", FALSE); - + if (compose->toolbar->sendl_btn) gtk_widget_set_sensitive(compose->toolbar->sendl_btn, FALSE); if (compose->toolbar->draft_btn) @@ -2634,7 +2629,7 @@ Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo, compose_destroy(compose); return NULL; } - + hooks_invoke(COMPOSE_CREATED_HOOKLIST, compose); return compose; @@ -2678,13 +2673,13 @@ void compose_entry_append(Compose *compose, const gchar *address, break; } header = prefs_common_translated_header_name(header); - + cur = begin = (gchar *)address; - + /* we separate the line by commas, but not if we're inside a quoted * string */ while (*cur != '\0') { - if (*cur == '"') + if (*cur == '"') in_quote = !in_quote; if (*cur == ',' && !in_quote) { gchar *tmp = g_strdup(begin); @@ -2709,7 +2704,7 @@ void compose_entry_append(Compose *compose, const gchar *address, tmp++; compose_add_header_entry(compose, header, tmp, pref_type); compose_entry_indicate(compose, tmp); - g_free(o_tmp); + g_free(o_tmp); } } @@ -2718,10 +2713,10 @@ static void compose_entry_indicate(Compose *compose, const gchar *mailto) GSList *h_list; GtkEntry *entry; GdkColor color; - + for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) { entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry); - if (gtk_entry_get_text(entry) && + if (gtk_entry_get_text(entry) && !g_utf8_collate(gtk_entry_get_text(entry), mailto)) { /* Modify background color */ GTKUT_GDKRGBA_TO_GDKCOLOR(default_header_bgcolor, color); @@ -2742,7 +2737,7 @@ void compose_toolbar_cb(gint action, gpointer data) { ToolbarItem *toolbar_item = (ToolbarItem*)data; Compose *compose = (Compose*)toolbar_item->parent; - + cm_return_if_fail(compose != NULL); switch(action) { @@ -2891,7 +2886,7 @@ static MailField compose_entries_set(Compose *compose, const gchar *mailto, Comp g_free(body); g_strfreev(attach); g_free(inreplyto); - + return mfield; } @@ -2979,7 +2974,7 @@ static gint compose_parse_header(Compose *compose, MsgInfo *msginfo) extract_address(hentry[H_LIST_POST].body); if (hentry[H_LIST_POST].body[0] != '\0') { start = strstr(hentry[H_LIST_POST].body, "mailto:"); - + scan_mailto_url(start ? start : hentry[H_LIST_POST].body, NULL, &to, NULL, NULL, NULL, NULL, NULL, NULL); @@ -2996,19 +2991,19 @@ static gint compose_parse_header(Compose *compose, MsgInfo *msginfo) if (compose->mode == COMPOSE_REEDIT) if (hentry[H_X_PRIORITY].body != NULL) { gint priority; - + priority = atoi(hentry[H_X_PRIORITY].body); g_free(hentry[H_X_PRIORITY].body); - + hentry[H_X_PRIORITY].body = NULL; - - if (priority < PRIORITY_HIGHEST || + + if (priority < PRIORITY_HIGHEST || priority > PRIORITY_LOWEST) priority = PRIORITY_NORMAL; - + compose->priority = priority; } - + if (compose->mode == COMPOSE_REEDIT) { if (msginfo->inreplyto && *msginfo->inreplyto) compose->inreplyto = g_strdup(msginfo->inreplyto); @@ -3133,7 +3128,7 @@ static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo, GtkTextBuffer *buffer = gtk_text_view_get_buffer(text); GtkTextIter iter; GtkTextMark *mark; - + SIGNAL_BLOCK(buffer); @@ -3203,7 +3198,7 @@ static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo, mark = gtk_text_buffer_get_insert(buffer); gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark); - if (g_utf8_validate(buf, -1, NULL)) { + if (g_utf8_validate(buf, -1, NULL)) { gtk_text_buffer_insert(buffer, &iter, buf, -1); } else { gchar *tmpout = NULL; @@ -3254,22 +3249,22 @@ static gboolean is_subscription(const gchar *ml_post, const gchar *from) gchar *left_from = NULL; gchar *right_from = NULL; gboolean result = FALSE; - + if (!ml_post || !from) return FALSE; - + left_ml = g_strdup(ml_post); if (strstr(left_ml, "@")) { right_ml = strstr(left_ml, "@")+1; *(strstr(left_ml, "@")) = '\0'; } - + left_from = g_strdup(from); if (strstr(left_from, "@")) { right_from = strstr(left_from, "@")+1; *(strstr(left_from, "@")) = '\0'; } - + if (right_ml && right_from && !strncmp(left_from, left_ml, strlen(left_ml)) && !strcmp(right_from, right_ml)) { @@ -3277,7 +3272,7 @@ static gboolean is_subscription(const gchar *ml_post, const gchar *from) } g_free(left_ml); g_free(left_from); - + return result; } @@ -3319,7 +3314,7 @@ static void compose_reply_set_subject(Compose *compose, MsgInfo *msginfo) { gchar *buf, *buf2; gchar *p; - + if (!compose || !msginfo) return; @@ -3356,14 +3351,14 @@ static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo, reply_to_ml = to_ml && compose->ml_post; - default_reply_to = msginfo->folder && + default_reply_to = msginfo->folder && msginfo->folder->prefs->enable_default_reply_to; if (compose->account->protocol != A_NNTP) { compose_set_folder_prefs(compose, msginfo->folder, FALSE); if (reply_to_ml && !default_reply_to) { - + gboolean is_subscr = is_subscription(compose->ml_post, msginfo->from); if (!is_subscr) { @@ -3437,21 +3432,21 @@ static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo, } } } else { - if (to_sender || (compose->followup_to && + if (to_sender || (compose->followup_to && !strncmp(compose->followup_to, "poster", 6))) compose_entry_append - (compose, + (compose, (compose->replyto ? compose->replyto : msginfo->from ? msginfo->from : ""), COMPOSE_TO, PREF_NONE); - + else if (followup_and_reply_to || to_all) { compose_entry_append (compose, (compose->replyto ? compose->replyto : msginfo->from ? msginfo->from : ""), - COMPOSE_TO, PREF_NONE); - + COMPOSE_TO, PREF_NONE); + compose_entry_append (compose, compose->followup_to ? compose->followup_to : @@ -3462,8 +3457,8 @@ static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo, (compose, msginfo->cc ? msginfo->cc : "", COMPOSE_CC, PREF_NONE); - } - else + } + else compose_entry_append (compose, compose->followup_to ? compose->followup_to : @@ -3486,7 +3481,7 @@ static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo, if (replyto && from) cc_list = address_list_append_with_comments(cc_list, from); - if (to_all && msginfo->folder && + if (to_all && msginfo->folder && msginfo->folder->prefs->enable_default_reply_to) cc_list = address_list_append_with_comments(cc_list, msginfo->folder->prefs->default_reply_to); @@ -3499,7 +3494,7 @@ static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo, for (cur = cc_list; cur != NULL; cur = cur->next) { gchar *addr = g_utf8_strdown(cur->data, -1); extract_address(addr); - + if (strcmp(ac_email, addr)) compose_entry_append(compose, (gchar *)cur->data, COMPOSE_CC, PREF_NONE); @@ -3508,10 +3503,10 @@ static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo, g_free(addr); } - + slist_free_strings_full(cc_list); } - + g_free(ac_email); } @@ -3558,7 +3553,7 @@ static void compose_insert_sig(Compose *compose, gboolean replace) gboolean prev_autowrap; gboolean found = FALSE; gboolean exists = FALSE; - + cm_return_if_fail(compose->account != NULL); BLOCK_WRAP(); @@ -3566,7 +3561,7 @@ static void compose_insert_sig(Compose *compose, gboolean replace) g_signal_handlers_block_by_func(G_OBJECT(buffer), G_CALLBACK(compose_changed_cb), compose); - + mark = gtk_text_buffer_get_insert(buffer); gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark); cur_pos = gtk_text_iter_get_offset (&iter); @@ -3601,8 +3596,8 @@ static void compose_insert_sig(Compose *compose, gboolean replace) gtk_text_buffer_delete(buffer, &start_iter, &end_iter); iter = start_iter; } - } - } + } + } g_free(compose->sig_str); compose->sig_str = account_get_signature_str(compose->account); @@ -3629,20 +3624,20 @@ static void compose_insert_sig(Compose *compose, gboolean replace) cur_pos = gtk_text_buffer_get_char_count (buffer); } - /* put the cursor where it should be + /* put the cursor where it should be * either where the quote_fmt says, either where it was */ if (compose->set_cursor_pos < 0) gtk_text_buffer_get_iter_at_offset(buffer, &iter, ins_pos); else - gtk_text_buffer_get_iter_at_offset(buffer, &iter, + gtk_text_buffer_get_iter_at_offset(buffer, &iter, compose->set_cursor_pos); - + compose->set_cursor_pos = -1; gtk_text_buffer_place_cursor(buffer, &iter); g_signal_handlers_unblock_by_func(G_OBJECT(buffer), G_CALLBACK(compose_changed_cb), compose); - + UNBLOCK_WRAP(); } @@ -3840,7 +3835,7 @@ static gboolean compose_attach_append(Compose *compose, const gchar *file, /* In batch mode, we allow 0-length files to be attached no questions asked */ if (size == 0 && !compose->batch) { gchar * msg = g_strdup_printf(_("File %s is empty."), filename); - AlertValue aval = alertpanel_full(_("Empty file"), msg, + AlertValue aval = alertpanel_full(_("Empty file"), msg, NULL, _("_Cancel"), NULL, _("_Attach anyway"), NULL, NULL, ALERTFOCUS_SECOND, FALSE, NULL, ALERT_WARNING); g_free(msg); @@ -3857,7 +3852,7 @@ static gboolean compose_attach_append(Compose *compose, const gchar *file, ainfo = g_new0(AttachInfo, 1); auto_ainfo = g_auto_pointer_new_with_free - (ainfo, (GFreeFunc) compose_attach_info_free); + (ainfo, (GFreeFunc) compose_attach_info_free); ainfo->file = g_strdup(file); if (content_type) { @@ -3903,7 +3898,7 @@ static gboolean compose_attach_append(Compose *compose, const gchar *file, else ainfo->encoding = ENC_BASE64; name = g_path_get_basename(filename ? filename : file); - ainfo->name = g_strdup(name); + ainfo->name = g_strdup(name); g_free(name); } @@ -3925,9 +3920,9 @@ static gboolean compose_attach_append(Compose *compose, const gchar *file, store = GTK_LIST_STORE(gtk_tree_view_get_model (GTK_TREE_VIEW(compose->attach_clist))); - + gtk_list_store_append(store, &iter); - gtk_list_store_set(store, &iter, + gtk_list_store_set(store, &iter, COL_MIMETYPE, ainfo->content_type, COL_SIZE, size_text, COL_NAME, ainfo->name, @@ -3935,7 +3930,7 @@ static gboolean compose_attach_append(Compose *compose, const gchar *file, COL_DATA, ainfo, COL_AUTODATA, auto_ainfo, -1); - + g_auto_pointer_free(auto_ainfo); compose_attach_update_label(compose); return TRUE; @@ -4009,7 +4004,7 @@ static void compose_attach_parts(Compose *compose, MsgInfo *msginfo) child = procmime_mimeinfo_next(child); continue; } - + if (child == firsttext) { child = procmime_mimeinfo_next(child); continue; @@ -4034,7 +4029,7 @@ static void compose_attach_parts(Compose *compose, MsgInfo *msginfo) partname = procmime_mimeinfo_get_parameter(child, "name"); if (partname == NULL) partname = ""; - compose_attach_append(compose, outfile, + compose_attach_append(compose, outfile, partname, content_type, procmime_mimeinfo_get_parameter(child, "charset")); } else { @@ -4259,7 +4254,7 @@ static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer, gtk_text_iter_forward_to_line_end(&line_end); str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE); len = g_utf8_strlen(str, -1); - + if (len == 0) { g_free(str); g_warning("compose_get_line_break_pos: len = 0!"); @@ -4304,7 +4299,7 @@ static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer, if ((!g_unichar_iswide(wc) || attr->is_line_break) && can_break && was_white && !prev_dont_break) pos = i; - + was_white = attr->is_white; /* don't wrap URI */ @@ -4525,9 +4520,9 @@ static gboolean compose_beautify_paragraph(Compose *compose, GtkTextIter *par_it /* move to line start */ gtk_text_iter_set_line_offset(&iter, 0); } - + itemized_len = compose_itemized_length(buffer, &iter); - + if (!itemized_len) { itemized_len = compose_left_offset_length(buffer, &iter); item_continuation = TRUE; @@ -4575,7 +4570,7 @@ static gboolean compose_beautify_paragraph(Compose *compose, GtkTextIter *par_it gint n; gchar *o_walk = NULL, *walk = NULL, *bp = NULL, *ep = NULL; gint walk_pos; - + start = FALSE; if (!prev_autowrap && num_blocks == 0) { num_blocks++; @@ -4592,7 +4587,7 @@ static gboolean compose_beautify_paragraph(Compose *compose, GtkTextIter *par_it if (quote_str) { /* debug_print("compose_beautify_paragraph(): quote_str = '%s'\n", quote_str); */ - if (startq_offset == -1) + if (startq_offset == -1) startq_offset = gtk_text_iter_get_offset(&iter); quotelevel = get_quote_level(quote_str, prefs_common.quote_chars); if (quotelevel > 2) { @@ -4640,7 +4635,7 @@ static gboolean compose_beautify_paragraph(Compose *compose, GtkTextIter *par_it if (!item_continuation) gtk_text_buffer_insert(buffer, &break_pos, " ", 2); } - } else + } else goto colorize; /* remove trailing spaces */ cur = break_pos; @@ -4678,7 +4673,7 @@ static gboolean compose_beautify_paragraph(Compose *compose, GtkTextIter *par_it g_free(quote_str); quote_str = NULL; } - continue; + continue; } else { /* move iter to next line start */ iter = break_pos; @@ -4712,7 +4707,7 @@ colorize: scanpos = tmp; last_index = n; } - } + } } bp = ep = 0; @@ -4725,7 +4720,7 @@ colorize: } else walk = scanpos + strlen(parser[last_index].needle); - } + } if (bp && ep) { uri_start = walk_pos + (bp - o_walk); uri_stop = walk_pos + (ep - o_walk); @@ -4742,7 +4737,7 @@ colorize: endquote = iter; switch (quotelevel) { - case 0: + case 0: if (!gtk_text_iter_has_tag(&startquote, compose->quote0_tag) || !gtk_text_iter_has_tag(&end_of_line, compose->quote0_tag)) { gtk_text_buffer_apply_tag_by_name( @@ -4754,7 +4749,7 @@ colorize: modified = TRUE; } break; - case 1: + case 1: if (!gtk_text_iter_has_tag(&startquote, compose->quote1_tag) || !gtk_text_iter_has_tag(&end_of_line, compose->quote1_tag)) { gtk_text_buffer_apply_tag_by_name( @@ -4766,7 +4761,7 @@ colorize: modified = TRUE; } break; - case 2: + case 2: if (!gtk_text_iter_has_tag(&startquote, compose->quote2_tag) || !gtk_text_iter_has_tag(&end_of_line, compose->quote2_tag)) { gtk_text_buffer_apply_tag_by_name( @@ -4802,7 +4797,7 @@ colorize: } noq_offset = -1; } - + if (uri_start != nouri_start && uri_stop != nouri_stop) { GtkTextIter nouri_start_iter, nouri_end_iter; gtk_text_buffer_get_iter_at_offset( @@ -4833,7 +4828,7 @@ colorize: modified = TRUE; if (removed && !modified_before_remove) { modified = FALSE; - } + } } } if (!modified) { @@ -4888,16 +4883,16 @@ static void compose_set_title(Compose *compose) gchar *str; gchar *edited; gchar *subject; - + edited = compose->modified ? _(" [Edited]") : ""; - + subject = gtk_editable_get_chars( GTK_EDITABLE(compose->subject_entry), 0, -1); #ifndef GENERIC_UMPC if (subject && strlen(subject)) str = g_strdup_printf(_("%s - Write message%s"), - subject, edited); + subject, edited); else str = g_strdup_printf(_("[no subject] - Write message%s"), edited); #else @@ -4911,11 +4906,11 @@ static void compose_set_title(Compose *compose) /** * compose_current_mail_account: - * + * * Find a current mail account (the currently selected account, or the * default account, if a news account is currently selected). If a * mail account cannot be found, display an error message. - * + * * Return value: Mail account, or NULL if not found. **/ static PrefsAccount * @@ -5037,12 +5032,12 @@ static void compose_select_account(Compose *compose, PrefsAccount *account, compose_insert_sig(compose, TRUE); undo_unblock(compose->undostruct); } - + header_entry = (ComposeHeaderEntry *) compose->header_list->data; if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(header_entry->combo), &iter)) gtk_tree_model_get(gtk_combo_box_get_model(GTK_COMBO_BOX( header_entry->combo)), &iter, COMBOBOX_TEXT, &header, -1); - + if (header && !strlen(gtk_entry_get_text(GTK_ENTRY(header_entry->entry)))) { if (account->protocol == A_NNTP) { if (!strcmp(header, _("To:"))) @@ -5055,10 +5050,10 @@ static void compose_select_account(Compose *compose, PrefsAccount *account, GTK_COMBO_BOX(header_entry->combo), _("To:")); } - + } g_free(header); - + #ifdef USE_ENCHANT /* use account's dict info if set */ if (compose->gtkaspell) { @@ -5085,7 +5080,7 @@ gboolean compose_check_for_valid_recipient(Compose *compose) { /* free to and newsgroup list */ slist_free_strings_full(compose->to_list); compose->to_list = NULL; - + slist_free_strings_full(compose->newsgroup_list); compose->newsgroup_list = NULL; @@ -5368,7 +5363,7 @@ gint compose_send(Compose *compose) if (discard_window) { compose->sending = FALSE; compose_close(compose); - /* No more compose access in the normal codepath + /* No more compose access in the normal codepath * after this point! */ compose = NULL; } @@ -5405,7 +5400,7 @@ gint compose_send(Compose *compose) debug_print("removing %d via %s\n", tmp->msgnum, tmsgid); folder_item_remove_msg(folder, tmp->msgnum); procmsg_msginfo_free(&tmp); - } + } } } } @@ -5439,7 +5434,7 @@ gint compose_send(Compose *compose) "the main window to retry.")); } if (!discard_window) { - goto bail; + goto bail; } inc_unlock(); g_free(tmsgid); @@ -5456,21 +5451,21 @@ bail: g_free(tmsgid); compose_allow_user_actions (compose, TRUE); compose->sending = FALSE; - compose->modified = TRUE; + compose->modified = TRUE; toolbar_main_set_sensitive(mainwin); main_window_set_menu_sensitive(mainwin); return -1; } -static gboolean compose_use_attach(Compose *compose) +static gboolean compose_use_attach(Compose *compose) { GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW(compose->attach_clist)); return gtk_tree_model_iter_n_children(model, NULL) > 0; } -static gint compose_redirect_write_headers_from_headerlist(Compose *compose, +static gint compose_redirect_write_headers_from_headerlist(Compose *compose, FILE *fp) { gchar buf[BUFFSIZE]; @@ -5544,7 +5539,7 @@ static gint compose_redirect_write_headers_from_headerlist(Compose *compose, if (!first_cc_address) { err |= (fprintf(fp, "\n") < 0); } - + return (err ? -1:0); } @@ -5873,7 +5868,7 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gbool encoding = ENC_QUOTED_PRINTABLE; } } - + if (prefs_common.rewrite_first_from && (encoding == ENC_8BIT || encoding == ENC_7BIT)) { if (!strncmp(buf, "From ", sizeof("From ")-1) || strstr(buf, "\nFrom ") != NULL) { @@ -5886,14 +5881,14 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gbool mimetext->tmp = TRUE; /* must free content later */ /* dup'ed because procmime_encode_content can turn it into a tmpfile * and free the data, which we need later. */ - mimetext->data.mem = g_strdup(buf); + mimetext->data.mem = g_strdup(buf); mimetext->type = MIMETYPE_TEXT; mimetext->subtype = g_strdup("plain"); g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"), g_strdup(out_codeset)); - + /* protect trailing spaces when signing message */ - if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing && + if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing && privacy_system_can_sign(compose->privacy_system)) { encoding = ENC_QUOTED_PRINTABLE; } @@ -5948,9 +5943,9 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gbool g_free(spec); } /* sign message if sending */ - if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing && + if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing && privacy_system_can_sign(compose->privacy_system)) - if (!privacy_sign(compose->privacy_system, mimemsg, + if (!privacy_sign(compose->privacy_system, mimemsg, compose->account, from_addr)) { g_free(from_name); g_free(from_addr); @@ -6013,7 +6008,7 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gbool g_free(tmp_enc_file); procmime_write_mimeinfo(mimemsg, fp); - + procmime_mimeinfo_free_all(&mimemsg); return 0; @@ -6088,7 +6083,7 @@ static gint compose_remove_reedit_target(Compose *compose, gboolean force) if (procmsg_msg_exist(msginfo) && (folder_has_parent_of_type(item, F_QUEUE) || - folder_has_parent_of_type(item, F_DRAFT) + folder_has_parent_of_type(item, F_DRAFT) || msginfo == compose->autosaved_draft)) { if (folder_item_remove_msg(item, msginfo->msgnum) < 0) { g_warning("can't remove the old message"); @@ -6123,7 +6118,7 @@ static gboolean compose_warn_encryption(Compose *compose) { const gchar *warning = privacy_get_encrypt_warning(compose->privacy_system); AlertValue val = G_ALERTALTERNATE; - + if (warning == NULL) return TRUE; @@ -6141,10 +6136,10 @@ static gboolean compose_warn_encryption(Compose *compose) return TRUE; } else { return FALSE; - } + } } -static ComposeQueueResult compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, +static ComposeQueueResult compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gchar **msgpath, gboolean perform_checks, gboolean remove_reedit_target) { @@ -6187,7 +6182,7 @@ static ComposeQueueResult compose_queue_sub(Compose *compose, gint *msgnum, Fold else { alertpanel_error(_("Selected account isn't NNTP: Posting is impossible.")); return COMPOSE_QUEUE_ERROR_NO_MSG; - } + } } /* write queue header */ @@ -6251,7 +6246,7 @@ static ComposeQueueResult compose_queue_sub(Compose *compose, gint *msgnum, Fold if (newsac) err |= (fprintf(fp, "NAID:%d\n", newsac->account_id) < 0); - + if (compose->privacy_system != NULL) { err |= (fprintf(fp, "X-Claws-Privacy-System:%s\n", compose->privacy_system) < 0); err |= (fprintf(fp, "X-Claws-Sign:%d\n", compose->use_signing) < 0); @@ -6273,12 +6268,12 @@ static ComposeQueueResult compose_queue_sub(Compose *compose, gint *msgnum, Fold if (compose->encdata != NULL) { if (strcmp(compose->encdata, "_DONT_ENCRYPT_")) { err |= (fprintf(fp, "X-Claws-Encrypt:%d\n", compose->use_encryption) < 0); - err |= (fprintf(fp, "X-Claws-Encrypt-Data:%s\n", + err |= (fprintf(fp, "X-Claws-Encrypt-Data:%s\n", compose->encdata) < 0); } /* else we finally dont want to encrypt */ } else { err |= (fprintf(fp, "X-Claws-Encrypt:%d\n", compose->use_encryption) < 0); - /* and if encdata was null, it means there's been a problem in + /* and if encdata was null, it means there's been a problem in * key selection */ if (err == TRUE) g_warning("failed to write queue message"); @@ -6293,7 +6288,7 @@ static ComposeQueueResult compose_queue_sub(Compose *compose, gint *msgnum, Fold /* Save copy folder */ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) { gchar *savefolderid; - + savefolderid = compose_get_save_to(compose); err |= (fprintf(fp, "SCF:%s\n", savefolderid) < 0); g_free(savefolderid); @@ -6317,7 +6312,7 @@ static ComposeQueueResult compose_queue_sub(Compose *compose, gint *msgnum, Fold /* Message-ID of message forwarding to */ if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) { gchar *folderid = NULL; - + if (compose->fwdinfo->folder) folderid = folder_item_get_identifier(compose->fwdinfo->folder); if (folderid == NULL) @@ -6381,7 +6376,7 @@ static ComposeQueueResult compose_queue_sub(Compose *compose, gint *msgnum, Fold g_free(tmp); return COMPOSE_QUEUE_ERROR_NO_MSG; } - + if (msgpath == NULL) { claws_unlink(tmp); g_free(tmp); @@ -6432,12 +6427,12 @@ static int compose_add_attachments(Compose *compose, MimeInfo *parent, gint acti GtkTreeIter iter; model = gtk_tree_view_get_model(tree_view); - + if (!gtk_tree_model_get_iter_first(model, &iter)) return 0; do { gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1); - + if (!is_file_exist(ainfo->file)) { gchar *msg = g_strdup_printf(_("Attachment %s doesn't exist anymore. Ignore?"), ainfo->file); AlertValue val = alertpanel_full(_("Warning"), msg, NULL, @@ -6489,13 +6484,13 @@ static int compose_add_attachments(Compose *compose, MimeInfo *parent, gint acti mimepart->subtype = g_strdup(subtype); g_free(type); - if (mimepart->type == MIMETYPE_MESSAGE && + if (mimepart->type == MIMETYPE_MESSAGE && !g_ascii_strcasecmp(mimepart->subtype, "rfc822")) { mimepart->disposition = DISPOSITIONTYPE_INLINE; } else if (mimepart->type == MIMETYPE_TEXT) { if (!ainfo->name && g_ascii_strcasecmp(mimepart->subtype, "plain")) { /* Text parts with no name come from multipart/alternative - * forwards. Make sure the recipient won't look at the + * forwards. Make sure the recipient won't look at the * original HTML part by mistake. */ mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT; ainfo->name = g_strdup_printf(_("Original %s part"), @@ -6506,7 +6501,7 @@ static int compose_add_attachments(Compose *compose, MimeInfo *parent, gint acti g_strdup("charset"), g_strdup(ainfo->charset)); } if (ainfo->name && mimepart->type != MIMETYPE_MESSAGE) { - if (mimepart->type == MIMETYPE_APPLICATION && + if (mimepart->type == MIMETYPE_APPLICATION && !g_strcmp0(mimepart->subtype, "octet-stream")) g_hash_table_insert(mimepart->typeparameters, g_strdup("name"), g_strdup(ainfo->name)); @@ -6529,7 +6524,7 @@ static int compose_add_attachments(Compose *compose, MimeInfo *parent, gint acti g_node_append(parent->node, mimepart->node); } while (gtk_tree_model_iter_next(model, &iter)); - + return 0; } @@ -6615,8 +6610,8 @@ static const gchar *compose_untranslated_header_name(gchar *header_name) return header_name; } -static void compose_add_headerfield_from_headerlist(Compose *compose, - GString *header, +static void compose_add_headerfield_from_headerlist(Compose *compose, + GString *header, const gchar *fieldname, const gchar *seperator) { @@ -6705,7 +6700,7 @@ static gchar *compose_get_manual_headers_info(Compose *compose) headername = g_strdup(strtok(tmp, ":")); } g_free(tmp); - + string = std_headers; while (*string != NULL) { headername_trans = prefs_common_translated_header_name(*string); @@ -6748,7 +6743,7 @@ static gchar *compose_get_header(Compose *compose) g_string_append_printf(header, "Date: %s\n", date); /* From */ - + if (compose->account->name && *compose->account->name) { gchar *buf; QUOTE_IF_REQUIRED(buf, compose->account->name); @@ -6778,8 +6773,8 @@ static gchar *compose_get_header(Compose *compose) g_free(spec); } g_free(tmp); - - + + if (from_name && *from_name) { gchar *qname; compose_convert_header @@ -6787,7 +6782,7 @@ static gchar *compose_get_header(Compose *compose) strlen("From: "), TRUE); QUOTE_IF_REQUIRED(name, buf); qname = escape_internal_quotes(name, '"'); - + g_string_append_printf(header, "From: %s <%s>\n", qname, from_address); if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To") && @@ -6819,8 +6814,8 @@ static gchar *compose_get_header(Compose *compose) compose_add_headerfield_from_headerlist(compose, header, "Cc", ", "); /* Bcc */ - /* - * If this account is a NNTP account remove Bcc header from + /* + * If this account is a NNTP account remove Bcc header from * message body since it otherwise will be publicly shown */ if (compose->account->protocol != A_NNTP) @@ -6849,7 +6844,7 @@ static gchar *compose_get_header(Compose *compose) /* In-Reply-To */ if (compose->inreplyto && compose->to_list) g_string_append_printf(header, "In-Reply-To: <%s>\n", compose->inreplyto); - + /* References */ if (compose->references) g_string_append_printf(header, "References: %s\n", compose->references); @@ -6969,7 +6964,7 @@ static gchar *compose_get_header(Compose *compose) headername = g_strdup(strtok(tmp, ":")); } g_free(tmp); - + entry_str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry)); Xstrdup_a(headervalue, entry_str, { g_free(headername); @@ -6996,7 +6991,7 @@ static gchar *compose_get_header(Compose *compose) } } g_free(headername); - g_free(headername_wcolon); + g_free(headername_wcolon); } return g_string_free(header, FALSE); @@ -7029,10 +7024,10 @@ static void compose_convert_header(Compose *compose, gchar *dest, gint len, gcha } codeconv_set_strict(TRUE); - conv_encode_header_full(dest, len, tmpstr, header_len, addr_field, + conv_encode_header_full(dest, len, tmpstr, header_len, addr_field, conv_get_charset_str(compose->out_encoding)); codeconv_set_strict(FALSE); - + if (!dest || *dest == '\0') { gchar *test_conv_global_out = NULL; gchar *test_conv_reply = NULL; @@ -7060,7 +7055,7 @@ static void compose_convert_header(Compose *compose, gchar *dest, gint len, gcha } g_free(test_conv_global_out); g_free(test_conv_reply); - conv_encode_header_full(dest, len, tmpstr, header_len, addr_field, + conv_encode_header_full(dest, len, tmpstr, header_len, addr_field, out_codeset); codeconv_set_strict(FALSE); } @@ -7164,18 +7159,7 @@ extra_headers_done: g_slist_foreach(extra_headers, (GFunc)compose_add_extra_header, (gpointer)model); } -#ifdef USE_LDAP -static void _ldap_srv_func(gpointer data, gpointer user_data) -{ - LdapServer *server = (LdapServer *)data; - gboolean *enable = (gboolean *)user_data; - - debug_print("%s server '%s'\n", (*enable == TRUE ? "enabling" : "disabling"), server->control->hostName); - server->searchFlag = *enable; -} -#endif - -static void compose_create_header_entry(Compose *compose) +static void compose_create_header_entry(Compose *compose) { gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL}; @@ -7189,7 +7173,7 @@ static void compose_create_header_entry(Compose *compose) gboolean standard_header = FALSE; GtkListStore *model; GtkTreeIter iter; - + headerentry = g_new0(ComposeHeaderEntry, 1); /* Combo box model */ @@ -7201,7 +7185,7 @@ static void compose_create_header_entry(Compose *compose) COMBOBOX_ADD(model, prefs_common_translated_header_name("Bcc:"), COMPOSE_BCC); COMBOBOX_ADD(model, prefs_common_translated_header_name("Newsgroups:"), - COMPOSE_NEWSGROUPS); + COMPOSE_NEWSGROUPS); COMBOBOX_ADD(model, prefs_common_translated_header_name("Reply-To:"), COMPOSE_REPLYTO); COMBOBOX_ADD(model, prefs_common_translated_header_name("Followup-To:"), @@ -7241,7 +7225,7 @@ static void compose_create_header_entry(Compose *compose) default: header = prefs_common_translated_header_name("To:"); break; - } + } } if (header) gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((combo)))), header); @@ -7258,7 +7242,7 @@ static void compose_create_header_entry(Compose *compose) gtk_widget_show(button); CLAWS_SET_TIP(button, _("Delete entry contents")); - entry = gtk_entry_new(); + entry = gtk_entry_new(); gtk_widget_show(entry); CLAWS_SET_TIP(entry, _("Use <tab> to autocomplete from addressbook")); @@ -7271,21 +7255,21 @@ static void compose_create_header_entry(Compose *compose) gtk_widget_set_hexpand(hbox, TRUE); gtk_widget_set_halign(hbox, GTK_ALIGN_FILL); - g_signal_connect(G_OBJECT(entry), "key-press-event", - G_CALLBACK(compose_headerentry_key_press_event_cb), + g_signal_connect(G_OBJECT(entry), "key-press-event", + G_CALLBACK(compose_headerentry_key_press_event_cb), headerentry); - g_signal_connect(G_OBJECT(entry), "changed", - G_CALLBACK(compose_headerentry_changed_cb), + g_signal_connect(G_OBJECT(entry), "changed", + G_CALLBACK(compose_headerentry_changed_cb), headerentry); g_signal_connect_after(G_OBJECT(entry), "grab_focus", G_CALLBACK(compose_grab_focus_cb), compose); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(compose_headerentry_button_clicked_cb), - headerentry); - + headerentry); + /* email dnd */ - gtk_drag_dest_set(entry, GTK_DEST_DEFAULT_ALL, compose_mime_types, + gtk_drag_dest_set(entry, GTK_DEST_DEFAULT_ALL, compose_mime_types, sizeof(compose_mime_types)/sizeof(compose_mime_types[0]), GDK_ACTION_COPY | GDK_ACTION_MOVE); g_signal_connect(G_OBJECT(entry), "drag_data_received", @@ -7298,23 +7282,6 @@ static void compose_create_header_entry(Compose *compose) G_CALLBACK(compose_entry_popup_extend), NULL); -#ifdef USE_LDAP -#ifndef PASSWORD_CRYPTO_OLD - GSList *pwd_servers = addrindex_get_password_protected_ldap_servers(); - if (pwd_servers != NULL && primary_passphrase() == NULL) { - gboolean enable = FALSE; - debug_print("Primary passphrase not available, disabling password-protected LDAP servers for this write window.\n"); - /* Temporarily disable password-protected LDAP servers, - * because user did not provide a primary passphrase. - * We can safely enable searchFlag on all servers in this list - * later, since addrindex_get_password_protected_ldap_servers() - * includes servers which have it enabled initially. */ - g_slist_foreach(pwd_servers, _ldap_srv_func, &enable); - compose->passworded_ldap_servers = pwd_servers; - } -#endif /* PASSWORD_CRYPTO_OLD */ -#endif /* USE_LDAP */ - address_completion_register_entry(GTK_ENTRY(entry), TRUE); headerentry->compose = compose; @@ -7326,29 +7293,29 @@ static void compose_create_header_entry(Compose *compose) headerentry->type = PREF_NONE; compose->header_nextrow++; - compose->header_last = headerentry; + compose->header_last = headerentry; compose->header_list = g_slist_append(compose->header_list, headerentry); } static void compose_add_header_entry(Compose *compose, const gchar *header, - gchar *text, ComposePrefType pref_type) + gchar *text, ComposePrefType pref_type) { ComposeHeaderEntry *last_header = compose->header_last; gchar *tmp = g_strdup(text), *email; gboolean replyto_hdr; - + replyto_hdr = (!strcasecmp(header, prefs_common_translated_header_name("Reply-To:")) || !strcasecmp(header, prefs_common_translated_header_name("Followup-To:")) || !strcasecmp(header, prefs_common_translated_header_name("In-Reply-To:"))); - + extract_address(tmp); email = g_utf8_strdown(tmp, -1); - + if (replyto_hdr == FALSE && g_hash_table_lookup(compose->email_hashtable, email) != NULL) { @@ -7358,7 +7325,7 @@ static void compose_add_header_entry(Compose *compose, const gchar *header, g_free(tmp); return; } - + if (!strcasecmp(header, prefs_common_translated_header_name("In-Reply-To:"))) gtk_entry_set_text(GTK_ENTRY( gtk_bin_get_child(GTK_BIN(last_header->combo))), header); @@ -7372,11 +7339,11 @@ static void compose_add_header_entry(Compose *compose, const gchar *header, GUINT_TO_POINTER(1)); else g_free(email); - + g_free(tmp); } -static void compose_destroy_headerentry(Compose *compose, +static void compose_destroy_headerentry(Compose *compose, ComposeHeaderEntry *headerentry) { gchar *text = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1); @@ -7387,7 +7354,7 @@ static void compose_destroy_headerentry(Compose *compose, g_hash_table_remove(compose->email_hashtable, email); g_free(text); g_free(email); - + gtk_widget_destroy(headerentry->combo); gtk_widget_destroy(headerentry->entry); gtk_widget_destroy(headerentry->button); @@ -7395,7 +7362,7 @@ static void compose_destroy_headerentry(Compose *compose, g_free(headerentry); } -static void compose_remove_header_entries(Compose *compose) +static void compose_remove_header_entries(Compose *compose) { GSList *list; for (list = compose->header_list; list; list = list->next) @@ -7408,7 +7375,7 @@ static void compose_remove_header_entries(Compose *compose) compose_create_header_entry(compose); } -static GtkWidget *compose_create_header(Compose *compose) +static GtkWidget *compose_create_header(Compose *compose) { GtkWidget *from_optmenu_hbox; GtkWidget *header_table_main; @@ -7457,7 +7424,7 @@ static gboolean popup_attach_button_pressed(GtkWidget *widget, gpointer data) { Compose *compose = (Compose *)data; GdkEventButton event; - + event.button = 3; event.time = gtk_get_current_event_time(); @@ -7481,7 +7448,7 @@ static GtkWidget *compose_create_attach(Compose *compose) GTK_POLICY_AUTOMATIC); gtk_widget_set_size_request(attach_scrwin, -1, 80); - store = gtk_list_store_new(N_ATTACH_COLS, + store = gtk_list_store_new(N_ATTACH_COLS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, @@ -7493,22 +7460,22 @@ static GtkWidget *compose_create_attach(Compose *compose) (GTK_TREE_MODEL(store))); gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist); g_object_unref(store); - + renderer = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes - (_("Mime type"), renderer, "text", + (_("Mime type"), renderer, "text", COL_MIMETYPE, NULL); - gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column); - + gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column); + renderer = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes - (_("Size"), renderer, "text", + (_("Size"), renderer, "text", COL_SIZE, NULL); - gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column); - + gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column); + renderer = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes - (_("Name"), renderer, "text", + (_("Name"), renderer, "text", COL_NAME, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(attach_clist), column); @@ -7526,7 +7493,7 @@ static GtkWidget *compose_create_attach(Compose *compose) /* drag and drop */ gtk_drag_dest_set(attach_clist, - GTK_DEST_DEFAULT_ALL, compose_mime_types, + GTK_DEST_DEFAULT_ALL, compose_mime_types, sizeof(compose_mime_types)/sizeof(compose_mime_types[0]), GDK_ACTION_COPY | GDK_ACTION_MOVE); g_signal_connect(G_OBJECT(attach_clist), "drag_data_received", @@ -7550,7 +7517,7 @@ static GtkWidget *compose_create_others(Compose *compose) GtkWidget *savemsg_checkbtn; GtkWidget *savemsg_combo; GtkWidget *savemsg_select; - + guint rowcount = 0; gchar *folderidentifier; @@ -7602,7 +7569,7 @@ static GtkWidget *compose_create_others(Compose *compose) G_CALLBACK(compose_savemsg_select_cb), compose); - return table; + return table; } static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose) @@ -7655,7 +7622,7 @@ static gboolean text_clicked(GtkWidget *text, GdkEventButton *event, gtk_text_buffer_place_cursor (buffer, &iter); /* reselect stuff */ - if (stuff_selected + if (stuff_selected && gtk_text_iter_in_range(&iter, &sel_start, &sel_end)) { gtk_text_buffer_select_range(buffer, &sel_start, &sel_end); @@ -7673,8 +7640,8 @@ static gboolean text_clicked(GtkWidget *text, GdkEventButton *event, &x, &y); gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text), &iter, x, y); - - entry_paste_clipboard(compose, text, + + entry_paste_clipboard(compose, text, prefs_common.linewrap_pastes, GDK_SELECTION_PRIMARY, &iter); UNBLOCK_WRAP(); @@ -7696,10 +7663,10 @@ static void compose_spell_menu_changed(void *data) if (compose->gtkaspell == NULL) return; - parent_item = gtk_ui_manager_get_widget(compose->ui_manager, + parent_item = gtk_ui_manager_get_widget(compose->ui_manager, "/Menu/Spelling/Options"); - /* setting the submenu removes '/Spelling/Options' from the factory + /* setting the submenu removes '/Spelling/Options' from the factory * so we need to save it */ if (parent_item == NULL) { @@ -7728,7 +7695,7 @@ static void compose_dict_changed(void *data) Compose *compose = (Compose *) data; if(!compose->gtkaspell) - return; + return; if(compose->gtkaspell->recheck_when_changing_dict == FALSE) return; @@ -7741,7 +7708,7 @@ static gboolean compose_popup_menu(GtkWidget *widget, gpointer data) { Compose *compose = (Compose *)data; GdkEventButton event; - + event.button = 3; event.time = gtk_get_current_event_time(); event.x = 0; @@ -7763,7 +7730,7 @@ static Compose *compose_create(PrefsAccount *account, GtkWidget *handlebox; GtkWidget *notebook; - + GtkWidget *attach_hbox; GtkWidget *attach_lab1; GtkWidget *attach_lab2; @@ -7809,7 +7776,7 @@ static Compose *compose_create(PrefsAccount *account, compose->batch = batch; compose->account = account; compose->folder = folder; - + g_mutex_init(&compose->mutex); compose->set_cursor_pos = -1; @@ -7836,9 +7803,9 @@ static Compose *compose_create(PrefsAccount *account, gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry, GDK_HINT_MIN_SIZE); -#ifndef GENERIC_UMPC +#ifndef GENERIC_UMPC if (compose_force_window_origin) - gtk_window_move(GTK_WINDOW(window), prefs_common.compose_x, + gtk_window_move(GTK_WINDOW(window), prefs_common.compose_x, prefs_common.compose_y); #endif g_signal_connect(G_OBJECT(window), "delete_event", @@ -7955,7 +7922,7 @@ static Compose *compose_create(PrefsAccount *account, MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options", "Sign", "Options/Sign", GTK_UI_MANAGER_MENUITEM) MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options", "Encrypt", "Options/Encrypt", GTK_UI_MANAGER_MENUITEM) - + MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options", "Separator2", "Options/---", GTK_UI_MANAGER_SEPARATOR) MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options", "Priority", "Options/Priority", GTK_UI_MANAGER_MENU) MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu/Options/Priority", "Highest", "Options/Priority/Highest", GTK_UI_MANAGER_MENUITEM) @@ -8057,7 +8024,7 @@ static Compose *compose_create(PrefsAccount *account, vbox2 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 2); gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0); gtk_container_set_border_width(GTK_CONTAINER(vbox2), 0); - + /* Notebook */ notebook = gtk_notebook_new(); gtk_widget_show(notebook); @@ -8069,15 +8036,15 @@ static Compose *compose_create(PrefsAccount *account, /* attachment list */ attach_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); gtk_widget_show(attach_hbox); - + attach_lab1 = gtk_label_new_with_mnemonic(_("_Attachments")); gtk_widget_show(attach_lab1); gtk_box_pack_start(GTK_BOX(attach_hbox), attach_lab1, TRUE, TRUE, 0); - + attach_lab2 = gtk_label_new(""); gtk_widget_show(attach_lab2); gtk_box_pack_start(GTK_BOX(attach_hbox), attach_lab2, FALSE, FALSE, 0); - + gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_attach(compose), attach_hbox); @@ -8115,7 +8082,7 @@ static Compose *compose_create(PrefsAccount *account, gtk_widget_show(subject_entry); compose->subject_entry = subject_entry; gtk_container_add(GTK_CONTAINER(subject_frame), subject); - + edit_vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0); @@ -8148,7 +8115,7 @@ static Compose *compose_create(PrefsAccount *account, gtk_text_view_set_editable(GTK_TEXT_VIEW(text), TRUE); clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); gtk_text_buffer_add_selection_clipboard(buffer, clipboard); - + gtk_container_add(GTK_CONTAINER(scrolledwin), text); g_signal_connect_after(G_OBJECT(text), "size_allocate", G_CALLBACK(compose_edit_size_alloc), @@ -8169,7 +8136,7 @@ static Compose *compose_create(PrefsAccount *account, G_CALLBACK(compose_subject_entry_activated), compose); /* drag and drop */ - gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, + gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, sizeof(compose_mime_types)/sizeof(compose_mime_types[0]), GDK_ACTION_COPY | GDK_ACTION_MOVE); g_signal_connect(G_OBJECT(text), "drag_data_received", @@ -8214,7 +8181,7 @@ static Compose *compose_create(PrefsAccount *account, MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Popup/Compose", "Remove", "Compose/Remove", GTK_UI_MANAGER_MENUITEM) MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Popup/Compose", "Separator1", "Compose/---", GTK_UI_MANAGER_SEPARATOR) MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Popup/Compose", "Properties", "Compose/Properties", GTK_UI_MANAGER_MENUITEM) - + popupmenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(gtk_ui_manager_get_widget(compose->ui_manager, "/Popup/Compose"))); cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Edit/Undo", FALSE); @@ -8262,7 +8229,7 @@ static Compose *compose_create(PrefsAccount *account, compose->email_hashtable = g_hash_table_new_full(g_str_hash, g_str_equal, (GDestroyNotify) g_free, NULL); - + compose->replyto = NULL; compose->cc = NULL; compose->bcc = NULL; @@ -8345,9 +8312,9 @@ static Compose *compose_create(PrefsAccount *account, if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT) compose_entry_append(compose, account->auto_cc, COMPOSE_CC, PREF_ACCOUNT); - if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT) + if (account->set_autobcc && account->auto_bcc && mode != COMPOSE_REEDIT) compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC, PREF_ACCOUNT); - + if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT) compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO, PREF_ACCOUNT); @@ -8361,7 +8328,7 @@ static Compose *compose_create(PrefsAccount *account, #ifndef USE_ALT_ADDRBOOK addressbook_set_target_compose(compose); -#endif +#endif if (mode != COMPOSE_REDIRECT) compose_set_template_menu(compose); else { @@ -8372,7 +8339,7 @@ static Compose *compose_create(PrefsAccount *account, if (!prefs_common.show_ruler) gtk_widget_hide(ruler_hbox); - + cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Tools/ShowRuler", prefs_common.show_ruler); /* Priority */ @@ -8380,7 +8347,7 @@ static Compose *compose_create(PrefsAccount *account, compose_update_priority_menu_item(compose); compose_set_out_encoding(compose); - + /* Actions menu */ compose_update_actions_menu(compose); @@ -8394,7 +8361,7 @@ static Compose *compose_create(PrefsAccount *account, } else { gtk_widget_show(window); } - + return compose; } @@ -8410,7 +8377,7 @@ static GtkWidget *compose_account_option_menu_create(Compose *compose) GtkWidget *from_name = NULL; gint num = 0, def_menu = 0; - + accounts = account_get_list(); cm_return_val_if_fail(accounts != NULL, NULL); @@ -8420,7 +8387,7 @@ static GtkWidget *compose_account_option_menu_create(Compose *compose) hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, HSPACING_NARROW); from_name = gtk_entry_new(); - + g_signal_connect_after(G_OBJECT(from_name), "grab_focus", G_CALLBACK(compose_grab_focus_cb), compose); g_signal_connect_after(G_OBJECT(from_name), "activate", @@ -8434,7 +8401,7 @@ static GtkWidget *compose_account_option_menu_create(Compose *compose) name = g_markup_printf_escaped("<i>%s</i>", ac->account_name); - + if (ac == compose->account) { if (ac->name && *ac->name) { gchar *buf; @@ -8480,7 +8447,7 @@ static GtkWidget *compose_account_option_menu_create(Compose *compose) gtk_box_pack_start(GTK_BOX(hbox), fromlabel, FALSE, FALSE, 4); gtk_box_pack_start(GTK_BOX(hbox), optmenubox, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox), from_name, TRUE, TRUE, 0); - + CLAWS_SET_TIP(optmenubox, _("Account to use for this email")); CLAWS_SET_TIP(from_name, @@ -8508,9 +8475,9 @@ static void compose_reply_change_mode(Compose *compose, gboolean was_modified = compose->modified; gboolean all = FALSE, ml = FALSE, sender = FALSE, followup = FALSE; - + cm_return_if_fail(compose->replyinfo != NULL); - + if (action == COMPOSE_REPLY && prefs_common.default_reply_list) ml = TRUE; if (action == COMPOSE_REPLY && compose->rmode == COMPOSE_FOLLOWUP_AND_REPLY_TO) @@ -8527,9 +8494,9 @@ static void compose_reply_change_mode(Compose *compose, if (compose->account->set_autocc && compose->account->auto_cc) compose_entry_append(compose, compose->account->auto_cc, COMPOSE_CC, PREF_ACCOUNT); - if (compose->account->set_autobcc && compose->account->auto_bcc) + if (compose->account->set_autobcc && compose->account->auto_bcc) compose_entry_append(compose, compose->account->auto_bcc, COMPOSE_BCC, PREF_ACCOUNT); - + if (compose->account->set_autoreplyto && compose->account->auto_replyto) compose_entry_append(compose, compose->account->auto_replyto, COMPOSE_REPLYTO, PREF_ACCOUNT); compose_show_first_last_header(compose, TRUE); @@ -8542,7 +8509,7 @@ static void compose_reply_change_mode_cb(GtkAction *action, GtkRadioAction *curr gboolean active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (current)); gint value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (current)); Compose *compose = (Compose *) data; - + if (active) compose_reply_change_mode(compose, value); } @@ -8573,7 +8540,7 @@ static void compose_update_priority_menu_item(Compose * compose) break; } gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE); -} +} static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data) { @@ -8648,8 +8615,8 @@ static void compose_update_privacy_system_menu_item(Compose * compose, gboolean can_encrypt = privacy_system_can_encrypt(systemid); found = TRUE; break; - } - } else if (strlen(compose->privacy_system) == 0 && + } + } else if (strlen(compose->privacy_system) == 0 && GTK_IS_CHECK_MENU_ITEM(amenu->data)) { menuitem = GTK_WIDGET(amenu->data); @@ -8664,13 +8631,13 @@ static void compose_update_privacy_system_menu_item(Compose * compose, gboolean g_list_free(children); if (menuitem != NULL) gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE); - + if (warn && !found && strlen(compose->privacy_system)) { alertpanel_warning(_("The privacy system '%s' cannot be loaded. You " "will not be able to sign or encrypt this message."), compose->privacy_system); } - } + } cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Options/Sign", can_sign); cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Options/Encrypt", can_encrypt); @@ -8741,7 +8708,7 @@ static void compose_set_template_menu(Compose *compose) menu = gtk_menu_new(); - gtk_menu_set_accel_group (GTK_MENU (menu), + gtk_menu_set_accel_group (GTK_MENU (menu), gtk_ui_manager_get_accel_group(compose->ui_manager)); for (cur = tmpl_list; cur != NULL; cur = cur->next) { Template *tmpl = (Template *)cur->data; @@ -8928,13 +8895,13 @@ static void compose_template_apply(Compose *compose, Template *tmpl, procmsg_msginfo_free( &dummyinfo ); g_free( tmp ); - } + } } else { if (replace) gtk_text_buffer_set_text(buffer, "", -1); mark = gtk_text_buffer_get_insert(buffer); gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark); - } + } if (replace && parsed_str && compose->account->auto_sig) compose_insert_sig(compose, FALSE); @@ -8943,7 +8910,7 @@ static void compose_template_apply(Compose *compose, Template *tmpl, gtk_text_buffer_get_start_iter(buffer, &iter); gtk_text_buffer_place_cursor(buffer, &iter); } - + if (parsed_str) { cursor_pos = quote_fmt_get_cursor_pos(); compose->set_cursor_pos = cursor_pos; @@ -9136,13 +9103,6 @@ static void compose_destroy(Compose *compose) compose_list = g_list_remove(compose_list, compose); -#ifdef USE_LDAP - gboolean enable = TRUE; - g_slist_foreach(compose->passworded_ldap_servers, - _ldap_srv_func, &enable); - g_slist_free(compose->passworded_ldap_servers); -#endif - if (compose->updating) { debug_print("danger, not destroying anything now\n"); compose->deferred_destroy = TRUE; @@ -9254,7 +9214,7 @@ static void compose_attach_update_label(Compose *compose) model = gtk_tree_view_get_model(GTK_TREE_VIEW(compose->attach_clist)); if (!gtk_tree_model_get_iter_first(model, &iter)) { - gtk_label_set_text(GTK_LABEL(compose->attach_label), ""); + gtk_label_set_text(GTK_LABEL(compose->attach_label), ""); return; } @@ -9297,7 +9257,7 @@ static void compose_attach_remove_selected(GtkAction *action, gpointer data) if (gtk_tree_model_get_iter(model, &iter, path)) gtk_list_store_remove(GTK_LIST_STORE(model), &iter); - + gtk_tree_path_free(path); gtk_tree_row_reference_free(ref); } @@ -9318,7 +9278,7 @@ static struct _AttachProperty } attach_prop; static void gtk_tree_path_free_(gpointer ptr, gpointer data) -{ +{ gtk_tree_path_free((GtkTreePath *)ptr); } @@ -9337,7 +9297,7 @@ static void compose_attach_property(GtkAction *action, gpointer data) /* only if one selected */ selection = gtk_tree_view_get_selection(tree_view); - if (gtk_tree_selection_count_selected_rows(selection) != 1) + if (gtk_tree_selection_count_selected_rows(selection) != 1) return; sel = gtk_tree_selection_get_selected_rows(selection, &model); @@ -9345,13 +9305,13 @@ static void compose_attach_property(GtkAction *action, gpointer data) path = (GtkTreePath *) sel->data; gtk_tree_model_get_iter(model, &iter, path); - gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1); - + gtk_tree_model_get(model, &iter, COL_DATA, &ainfo, -1); + if (!ainfo) { g_list_foreach(sel, gtk_tree_path_free_, NULL); g_list_free(sel); return; - } + } g_list_free(sel); if (!attach_prop.window) @@ -9387,7 +9347,7 @@ static void compose_attach_property(GtkAction *action, gpointer data) gtk_widget_hide(attach_prop.window); gtk_window_set_modal(GTK_WINDOW(attach_prop.window), FALSE); - + if (cancelled) break; @@ -9447,7 +9407,7 @@ static void compose_attach_property(GtkAction *action, gpointer data) COL_NAME, ainfo->name, COL_CHARSET, ainfo->charset, -1); - + break; } @@ -9504,7 +9464,7 @@ static void compose_attach_property_create(gboolean *cancelled) gtk_grid_set_row_spacing(GTK_GRID(table), 8); gtk_grid_set_column_spacing(GTK_GRID(table), 8); - label = gtk_label_new(_("MIME type")); + label = gtk_label_new(_("MIME type")); gtk_grid_attach(GTK_GRID(table), label, 0, 0, 1, 1); gtk_label_set_xalign(GTK_LABEL(label), 0.0); mimetype_entry = gtk_combo_box_text_new_with_entry(); @@ -9528,14 +9488,14 @@ static void compose_attach_property_create(gboolean *cancelled) (GCompareFunc)g_strcmp0); } - for (mime_type_list = strlist; mime_type_list != NULL; + for (mime_type_list = strlist; mime_type_list != NULL; mime_type_list = mime_type_list->next) { gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(mimetype_entry), mime_type_list->data); g_free(mime_type_list->data); } g_list_free(strlist); - gtk_combo_box_set_active(GTK_COMBO_BOX(mimetype_entry), 0); - mimetype_entry = gtk_bin_get_child(GTK_BIN((mimetype_entry))); + gtk_combo_box_set_active(GTK_COMBO_BOX(mimetype_entry), 0); + mimetype_entry = gtk_bin_get_child(GTK_BIN((mimetype_entry))); label = gtk_label_new(_("Encoding")); gtk_grid_attach(GTK_GRID(table), label, 0, 1, 1, 1); @@ -10091,7 +10051,7 @@ static void account_activated(GtkComboBox *optmenu, gpointer data) for (list = compose->header_list; list; list = list->next) { ComposeHeaderEntry *hentry=(ComposeHeaderEntry *)list->data; - + if (hentry->type == PREF_ACCOUNT || !list->next) { compose_destroy_headerentry(compose, hentry); continue; @@ -10112,7 +10072,7 @@ static void account_activated(GtkComboBox *optmenu, gpointer data) compose->header_list = NULL; compose->header_nextrow = 1; compose_create_header_entry(compose); - + if (ac->set_autocc && ac->auto_cc) compose_entry_append(compose, ac->auto_cc, COMPOSE_CC, PREF_ACCOUNT); @@ -10122,7 +10082,7 @@ static void account_activated(GtkComboBox *optmenu, gpointer data) if (ac->set_autoreplyto && ac->auto_replyto) compose_entry_append(compose, ac->auto_replyto, COMPOSE_REPLYTO, PREF_ACCOUNT); - + for (list = saved_list; list; list = list->next) { state = (HeaderEntryState *) list->data; @@ -10136,7 +10096,7 @@ static void account_activated(GtkComboBox *optmenu, gpointer data) g_slist_free(saved_list); combobox_select_by_data(GTK_COMBO_BOX(compose->header_last->combo), - (ac->protocol == A_NNTP) ? + (ac->protocol == A_NNTP) ? COMPOSE_NEWSGROUPS : COMPOSE_TO); } @@ -10174,7 +10134,7 @@ static gboolean attach_button_pressed(GtkWidget *widget, GdkEventButton *event, GtkTreeSelection *attach_selection; gint attach_nr_selected; GtkTreePath *path; - + if (!event || compose->redirect_filename != NULL) return FALSE; @@ -10203,10 +10163,10 @@ static gboolean attach_button_pressed(GtkWidget *widget, GdkEventButton *event, /* Properties menu item makes no sense with more than one row * selected, the properties dialog can only edit one attachment. */ cm_menu_set_sensitive_full(compose->ui_manager, "Popup/Compose/Properties", (attach_nr_selected == 1)); - + gtk_menu_popup_at_pointer(GTK_MENU(compose->popupmenu), NULL); - return TRUE; + return TRUE; } return FALSE; @@ -10234,11 +10194,11 @@ static void compose_allow_user_actions (Compose *compose, gboolean allow) cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Edit", allow); #if USE_ENCHANT cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Spelling", allow); -#endif +#endif cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Options", allow); cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Tools", allow); cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Help", allow); - + gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), allow); } @@ -10253,12 +10213,12 @@ static void compose_send_cb(GtkAction *action, gpointer data) return; } #endif - if (prefs_common.work_offline && + if (prefs_common.work_offline && !inc_offline_should_override(TRUE, _("Claws Mail needs network access in order " "to send this email."))) return; - + if (compose->draft_timeout_tag >= 0) { /* CLAWS: disable draft timeout */ g_source_remove(compose->draft_timeout_tag); compose->draft_timeout_tag = COMPOSE_DRAFT_TIMEOUT_UNSET; @@ -10293,18 +10253,18 @@ static void compose_register_draft(MsgInfo *info) gchar *filepath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, DRAFTED_AT_EXIT, NULL); FILE *fp = claws_fopen(filepath, "ab"); - + if (fp) { gchar *name = folder_item_get_identifier(info->folder); fprintf(fp, "%s\t%d\n", name, info->msgnum); g_free(name); claws_fclose(fp); } - - g_free(filepath); + + g_free(filepath); } -gboolean compose_draft (gpointer data, guint action) +gboolean compose_draft (gpointer data, guint action) { Compose *compose = (Compose *)data; FolderItem *draft; @@ -10327,7 +10287,7 @@ gboolean compose_draft (gpointer data, guint action) draft = account_get_special_folder(compose->account, F_DRAFT); cm_return_val_if_fail(draft != NULL, FALSE); - + if (!g_mutex_trylock(&compose->mutex)) { /* we don't want to lock the mutex once it's available, * because as the only other part of compose.c locking @@ -10426,11 +10386,11 @@ gboolean compose_draft (gpointer data, guint action) if (claws_safe_fclose(fp) == EOF) { goto warn_err; } - + flag.perm_flags = MSG_NEW|MSG_UNREAD; if (compose->targetinfo) { target_locked = MSG_IS_LOCKED(compose->targetinfo->flags); - if (target_locked) + if (target_locked) flag.perm_flags |= MSG_LOCKED; } flag.tmp_flags = MSG_DRAFT; @@ -10504,9 +10464,9 @@ warn_err: } procmsg_msginfo_free(&newmsginfo); } - + folder_item_scan(draft); - + if (action == COMPOSE_QUIT_EDITING || action == COMPOSE_DRAFT_FOR_EXIT) { lock = FALSE; g_mutex_unlock(&compose->mutex); /* must be done before closing */ @@ -10566,7 +10526,7 @@ warn_err: if (target_locked) procmsg_msginfo_set_flags(compose->targetinfo, MSG_LOCKED, 0); compose->mode = COMPOSE_REEDIT; - + if (action == COMPOSE_AUTO_SAVE) { compose->modified = FALSE; compose->autosaved_draft = compose->targetinfo; @@ -10585,7 +10545,7 @@ void compose_clear_exit_drafts(void) DRAFTED_AT_EXIT, NULL); if (is_file_exist(filepath)) claws_unlink(filepath); - + g_free(filepath); } @@ -10595,13 +10555,13 @@ void compose_reopen_exit_drafts(void) DRAFTED_AT_EXIT, NULL); FILE *fp = claws_fopen(filepath, "rb"); gchar buf[1024]; - + if (fp) { while (claws_fgets(buf, sizeof(buf), fp)) { gchar **parts = g_strsplit(buf, "\t", 2); const gchar *folder = parts[0]; int msgnum = parts[1] ? atoi(parts[1]):-1; - + if (folder && *folder && msgnum > -1) { FolderItem *item = folder_find_item_from_identifier(folder); MsgInfo *info = folder_item_get_msginfo(item, msgnum); @@ -10609,9 +10569,9 @@ void compose_reopen_exit_drafts(void) compose_reedit(info, FALSE); } g_strfreev(parts); - } + } claws_fclose(fp); - } + } g_free(filepath); compose_clear_exit_drafts(); } @@ -10699,8 +10659,8 @@ static void compose_insert_file_cb(GtkAction *action, gpointer data) g_list_free(file_list); } -#ifdef USE_ENCHANT - if (files_inserted > 0 && compose->gtkaspell && +#ifdef USE_ENCHANT + if (files_inserted > 0 && compose->gtkaspell && compose->gtkaspell->check_while_typing) gtkaspell_highlight_all(compose->gtkaspell); #endif @@ -10879,7 +10839,7 @@ static void compose_redo_cb(GtkAction *action, gpointer data) { Compose *compose = (Compose *)data; gboolean prev_autowrap = compose->autowrap; - + compose->autowrap = FALSE; undo_redo(compose->undostruct); compose->autowrap = prev_autowrap; @@ -11045,7 +11005,7 @@ int attach_image(Compose *compose, GtkSelectionData *data, const gchar *subtype) type = g_strconcat("image/", subtype, NULL); - compose_attach_append(compose, (const gchar *)file, + compose_attach_append(compose, (const gchar *)file, (const gchar *)file, type, NULL); alertpanel_notice(_("The pasted image has been attached as: \n%s"), file); @@ -11056,7 +11016,7 @@ int attach_image(Compose *compose, GtkSelectionData *data, const gchar *subtype) return 0; } -static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, +static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, gboolean wrap, GdkAtom clip, GtkTextIter *insert_place) { if (GTK_IS_TEXT_VIEW(entry)) { @@ -11126,9 +11086,9 @@ static void entry_allsel(GtkWidget *entry) gtk_text_buffer_get_start_iter(textbuf, &startiter); gtk_text_buffer_get_end_iter(textbuf, &enditer); - gtk_text_buffer_move_mark_by_name(textbuf, + gtk_text_buffer_move_mark_by_name(textbuf, "selection_bound", &startiter); - gtk_text_buffer_move_mark_by_name(textbuf, + gtk_text_buffer_move_mark_by_name(textbuf, "insert", &enditer); } } @@ -11136,7 +11096,7 @@ static void entry_allsel(GtkWidget *entry) static void compose_cut_cb(GtkAction *action, gpointer data) { Compose *compose = (Compose *)data; - if (compose->focused_editable + if (compose->focused_editable #ifndef GENERIC_UMPC && gtk_widget_has_focus(compose->focused_editable) #endif @@ -11147,7 +11107,7 @@ static void compose_cut_cb(GtkAction *action, gpointer data) static void compose_copy_cb(GtkAction *action, gpointer data) { Compose *compose = (Compose *)data; - if (compose->focused_editable + if (compose->focused_editable #ifndef GENERIC_UMPC && gtk_widget_has_focus(compose->focused_editable) #endif @@ -11166,7 +11126,7 @@ static void compose_paste_cb(GtkAction *action, gpointer data) && gtk_widget_has_focus(compose->focused_editable) #endif ) - entry_paste_clipboard(compose, compose->focused_editable, + entry_paste_clipboard(compose, compose->focused_editable, prefs_common.linewrap_pastes, GDK_SELECTION_CLIPBOARD, NULL); UNBLOCK_WRAP(); @@ -11176,7 +11136,7 @@ static void compose_paste_cb(GtkAction *action, gpointer data) #ifndef GENERIC_UMPC gtk_widget_has_focus(compose->text) && #endif - compose->gtkaspell && + compose->gtkaspell && compose->gtkaspell->check_while_typing) gtkaspell_highlight_all(compose->gtkaspell); #endif @@ -11186,13 +11146,13 @@ static void compose_paste_as_quote_cb(GtkAction *action, gpointer data) { Compose *compose = (Compose *)data; gint wrap_quote = prefs_common.linewrap_quote; - if (compose->focused_editable + if (compose->focused_editable #ifndef GENERIC_UMPC && gtk_widget_has_focus(compose->focused_editable) #endif ) { /* let text_insert() (called directly or at a later time - * after the gtk_editable_paste_clipboard) know that + * after the gtk_editable_paste_clipboard) know that * text is to be inserted as a quotation. implemented * by using a simple refcount... */ gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data( @@ -11202,7 +11162,7 @@ static void compose_paste_as_quote_cb(GtkAction *action, gpointer data) "paste_as_quotation", GINT_TO_POINTER(paste_as_quotation + 1)); prefs_common.linewrap_quote = prefs_common.linewrap_pastes; - entry_paste_clipboard(compose, compose->focused_editable, + entry_paste_clipboard(compose, compose->focused_editable, prefs_common.linewrap_pastes, GDK_SELECTION_CLIPBOARD, NULL); prefs_common.linewrap_quote = wrap_quote; @@ -11215,7 +11175,7 @@ static void compose_paste_no_wrap_cb(GtkAction *action, gpointer data) gint prev_autowrap; GtkTextBuffer *buffer; BLOCK_WRAP(); - if (compose->focused_editable + if (compose->focused_editable #ifndef GENERIC_UMPC && gtk_widget_has_focus(compose->focused_editable) #endif @@ -11229,7 +11189,7 @@ static void compose_paste_no_wrap_cb(GtkAction *action, gpointer data) #ifndef GENERIC_UMPC gtk_widget_has_focus(compose->text) && #endif - compose->gtkaspell && + compose->gtkaspell && compose->gtkaspell->check_while_typing) gtkaspell_highlight_all(compose->gtkaspell); #endif @@ -11241,7 +11201,7 @@ static void compose_paste_wrap_cb(GtkAction *action, gpointer data) gint prev_autowrap; GtkTextBuffer *buffer; BLOCK_WRAP(); - if (compose->focused_editable + if (compose->focused_editable #ifndef GENERIC_UMPC && gtk_widget_has_focus(compose->focused_editable) #endif @@ -11264,7 +11224,7 @@ static void compose_paste_wrap_cb(GtkAction *action, gpointer data) static void compose_allsel_cb(GtkAction *action, gpointer data) { Compose *compose = (Compose *)data; - if (compose->focused_editable + if (compose->focused_editable #ifndef GENERIC_UMPC && gtk_widget_has_focus(compose->focused_editable) #endif @@ -11492,7 +11452,7 @@ static void textview_delete_line (GtkTextView *text) if (!gtk_text_iter_forward_char(&end_iter)) gtk_text_iter_backward_char(&start_iter); } - else + else gtk_text_iter_forward_to_line_end(&end_iter); gtk_text_buffer_delete(buffer, &start_iter, &end_iter); } @@ -11546,7 +11506,7 @@ static void compose_advanced_action_cb(GtkAction *gaction, gpointer data) Compose *compose = (Compose *)data; GtkTextView *text = GTK_TEXT_VIEW(compose->text); ComposeCallAdvancedAction action = COMPOSE_CALL_ADVANCED_ACTION_UNDEFINED; - + action = compose_call_advanced_action_from_path(gaction); static struct { @@ -11584,10 +11544,10 @@ static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose) GtkAllocation allocation; GtkWidget *parent; gchar *str = NULL; - + if (GTK_IS_EDITABLE(widget)) { str = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1); - gtk_editable_set_position(GTK_EDITABLE(widget), + gtk_editable_set_position(GTK_EDITABLE(widget), strlen(str)); g_free(str); if ((parent = gtk_widget_get_parent(widget)) @@ -11608,10 +11568,10 @@ static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose) } if ((y + height) > ((int)value + (int)page_size)) { if ((y - height - 1) < ((int)upper - (int)page_size)) { - gtk_adjustment_set_value(shown, + gtk_adjustment_set_value(shown, y + height - (int)page_size - 1); } else { - gtk_adjustment_set_value(shown, + gtk_adjustment_set_value(shown, (int)upper - (int)page_size - 1); } } @@ -11621,9 +11581,9 @@ static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose) if (GTK_IS_EDITABLE(widget) || GTK_IS_TEXT_VIEW(widget)) compose->focused_editable = widget; - + #ifdef GENERIC_UMPC - if (GTK_IS_TEXT_VIEW(widget) + if (GTK_IS_TEXT_VIEW(widget) && gtk_paned_get_child1(GTK_PANED(compose->paned)) != compose->edit_vbox) { g_object_ref(compose->notebook); g_object_ref(compose->edit_vbox); @@ -11640,7 +11600,7 @@ static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose) g_signal_handlers_unblock_by_func(G_OBJECT(widget), G_CALLBACK(compose_grab_focus_cb), compose); - } else if (!GTK_IS_TEXT_VIEW(widget) + } else if (!GTK_IS_TEXT_VIEW(widget) && gtk_paned_get_child1(GTK_PANED(compose->paned)) != compose->notebook) { g_object_ref(compose->notebook); g_object_ref(compose->edit_vbox); @@ -11724,7 +11684,7 @@ static void compose_toggle_encrypt_cb(GtkToggleAction *action, gpointer data) gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(compose->toolbar->privacy_encrypt_btn), compose->use_encryption); } -static void compose_activate_privacy_system(Compose *compose, PrefsAccount *account, gboolean warn) +static void compose_activate_privacy_system(Compose *compose, PrefsAccount *account, gboolean warn) { g_free(compose->privacy_system); g_free(compose->encdata); @@ -11785,21 +11745,21 @@ static void compose_attach_drag_received_cb (GtkWidget *widget, /* comes from our summaryview */ SummaryView * summaryview = NULL; GSList * list = NULL, *cur = NULL; - + if (mainwindow_get_mainwindow()) summaryview = mainwindow_get_mainwindow()->summaryview; - + if (summaryview) list = summary_get_selected_msg_list(summaryview); - + for (cur = list; cur; cur = cur->next) { MsgInfo *msginfo = (MsgInfo *)cur->data; gchar *file = NULL; if (msginfo) - file = procmsg_get_message_file_full(msginfo, + file = procmsg_get_message_file_full(msginfo, TRUE, TRUE); if (file) { - compose_attach_append(compose, (const gchar *)file, + compose_attach_append(compose, (const gchar *)file, (const gchar *)file, "message/rfc822", NULL); g_free(file); } @@ -11815,7 +11775,7 @@ static gboolean compose_drag_drop(GtkWidget *widget, { /* not handling this signal makes compose_insert_drag_received_cb * called twice */ - return TRUE; + return TRUE; } static gboolean completion_set_focus_to_subject @@ -11862,7 +11822,7 @@ static void compose_insert_drag_received_cb (GtkWidget *widget, gchar *tmpdata = g_strstrip(g_strdup(ddata)); gchar *tmpfile = get_tmp_file(); str_write_to_file(tmpdata, tmpfile, TRUE); - g_free(tmpdata); + g_free(tmpdata); compose_insert_file(compose, tmpfile); claws_unlink(tmpfile); g_free(tmpfile); @@ -11913,7 +11873,7 @@ static void compose_insert_drag_received_cb (GtkWidget *widget, compose_attach_drag_received_cb(widget, drag_context, x, y, data, info, time, user_data); list_free_strings_full(list); return; - } + } for (tmp = list; tmp != NULL; tmp = tmp->next) { compose_insert_file(compose, (const gchar *)tmp->data); @@ -12006,7 +11966,7 @@ static gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry, /* Override default next focus, and give it to subject_entry * instead of notebook tabs */ - g_signal_stop_emission_by_name(G_OBJECT(entry), "key-press-event"); + g_signal_stop_emission_by_name(G_OBJECT(entry), "key-press-event"); gtk_widget_grab_focus(headerentry->compose->subject_entry); return TRUE; } @@ -12101,7 +12061,7 @@ static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter, g_free(new_text); g_object_set_data(G_OBJECT(compose->text), "paste_as_quotation", GINT_TO_POINTER(paste_as_quotation - 1)); - + gtk_text_buffer_get_iter_at_mark(buffer, iter, mark); gtk_text_buffer_place_cursor(buffer, iter); gtk_text_buffer_delete_mark(buffer, mark); @@ -12117,7 +12077,7 @@ static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter, GtkTextIter before_ins; gtk_text_buffer_insert(buffer, iter, text, len); if (!strstr(text, "\n") && gtk_text_iter_has_tag(iter, compose->no_join_tag)) { - before_ins = *iter; + before_ins = *iter; gtk_text_iter_backward_chars(&before_ins, len); gtk_text_buffer_remove_tag_by_name(buffer, "no_join", &before_ins, iter); } @@ -12127,7 +12087,7 @@ static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *tmp = NULL, *quote = NULL; gint quote_len = 0, is_normal = 0; start_line = *iter; - gtk_text_iter_set_line_offset(&start_line, 0); + gtk_text_iter_set_line_offset(&start_line, 0); tmp = gtk_text_buffer_get_text(buffer, &start_line, iter, FALSE); g_strstrip(tmp); @@ -12140,16 +12100,16 @@ static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter, g_free(quote); } g_free(tmp); - + if (is_normal) { gtk_text_buffer_insert(buffer, iter, text, len); } else { - gtk_text_buffer_insert_with_tags_by_name(buffer, + gtk_text_buffer_insert_with_tags_by_name(buffer, iter, text, len, "no_join", NULL); } } } - + if (!paste_as_quotation) { mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE); compose_beautify_paragraph(compose, iter, FALSE); @@ -12162,7 +12122,7 @@ static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter, compose); g_signal_stop_emission_by_name(G_OBJECT(buffer), "insert-text"); - if (compose_can_autosave(compose) && + if (compose_can_autosave(compose) && gtk_text_buffer_get_char_count(buffer) % prefs_common.autosave_length == 0 && compose->draft_timeout_tag != COMPOSE_DRAFT_TIMEOUT_FORBIDDEN /* disabled while loading */) compose->draft_timeout_tag = g_timeout_add @@ -12175,10 +12135,10 @@ static void compose_check_all(GtkAction *action, gpointer data) Compose *compose = (Compose *)data; if (!compose->gtkaspell) return; - + if (gtk_widget_has_focus(compose->subject_entry)) claws_spell_entry_check_all( - CLAWS_SPELL_ENTRY(compose->subject_entry)); + CLAWS_SPELL_ENTRY(compose->subject_entry)); else gtkaspell_check_all(compose->gtkaspell); } @@ -12225,20 +12185,20 @@ static void compose_check_forwards_go(GtkAction *action, gpointer data) #endif /*! - *\brief Guess originating forward account from MsgInfo and several - * "common preference" settings. Return NULL if no guess. + *\brief Guess originating forward account from MsgInfo and several + * "common preference" settings. Return NULL if no guess. */ static PrefsAccount *compose_find_account(MsgInfo *msginfo) { PrefsAccount *account = NULL; - + cm_return_val_if_fail(msginfo, NULL); cm_return_val_if_fail(msginfo->folder, NULL); cm_return_val_if_fail(msginfo->folder->prefs, NULL); if (msginfo->folder->prefs->enable_default_account) account = account_find_from_id(msginfo->folder->prefs->default_account); - + if (!account && msginfo->to && prefs_common.forward_account_autosel) { gchar *to; Xstrdup_a(to, msginfo->to, return NULL); @@ -12249,18 +12209,18 @@ static PrefsAccount *compose_find_account(MsgInfo *msginfo) if (!account && prefs_common.forward_account_autosel) { gchar *cc = NULL; if (!procheader_get_header_from_msginfo - (msginfo, &cc, "Cc:")) { + (msginfo, &cc, "Cc:")) { gchar *buf = cc + strlen("Cc:"); extract_address(buf); account = account_find_from_address(buf, FALSE); g_free(cc); } } - + if (!account && prefs_common.forward_account_autosel) { gchar *deliveredto = NULL; if (!procheader_get_header_from_msginfo - (msginfo, &deliveredto, "Delivered-To:")) { + (msginfo, &deliveredto, "Delivered-To:")) { gchar *buf = deliveredto + strlen("Delivered-To:"); extract_address(buf); account = account_find_from_address(buf, FALSE); @@ -12270,7 +12230,7 @@ static PrefsAccount *compose_find_account(MsgInfo *msginfo) if (!account) account = msginfo->folder->folder->account; - + return account; } @@ -12287,7 +12247,7 @@ gboolean compose_close(Compose *compose) debug_print("waiting for drafting to finish...\n"); compose_allow_user_actions(compose, FALSE); if (compose->close_timeout_tag == 0) { - compose->close_timeout_tag = + compose->close_timeout_tag = g_timeout_add (500, (GSourceFunc) compose_close, compose); } @@ -12325,7 +12285,7 @@ static void compose_add_field_list( Compose *compose, GList *listAddress ) { } } -static void compose_reply_from_messageview_real(MessageView *msgview, GSList *msginfo_list, +static void compose_reply_from_messageview_real(MessageView *msgview, GSList *msginfo_list, guint action, gboolean opening_multiple) { gchar *body = NULL; @@ -12342,7 +12302,7 @@ static void compose_reply_from_messageview_real(MessageView *msgview, GSList *ms MimeInfo *mimeinfo = messageview_get_selected_mime_part(msgview); MsgInfo *orig_msginfo = (MsgInfo *)msginfo_list->data; - if (mimeinfo != NULL && mimeinfo->type == MIMETYPE_MESSAGE && + if (mimeinfo != NULL && mimeinfo->type == MIMETYPE_MESSAGE && !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) { tmp_msginfo = procmsg_msginfo_new_from_mimeinfo( orig_msginfo, mimeinfo); @@ -12354,7 +12314,7 @@ static void compose_reply_from_messageview_real(MessageView *msgview, GSList *ms originally_sig = MSG_IS_SIGNED(orig_msginfo->flags); tmp_msginfo->folder = orig_msginfo->folder; - tmp_msginfo->msgnum = orig_msginfo->msgnum; + tmp_msginfo->msgnum = orig_msginfo->msgnum; if (orig_msginfo->tags) { tmp_msginfo->tags = g_slist_copy(orig_msginfo->tags); tmp_msginfo->folder->tags_dirty = TRUE; @@ -12385,17 +12345,17 @@ static void compose_reply_from_messageview_real(MessageView *msgview, GSList *ms hooks_invoke(COMPOSE_CREATED_HOOKLIST, compose); } -void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list, +void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list, guint action) { - if ((!prefs_common.forward_as_attachment || action != COMPOSE_FORWARD) + if ((!prefs_common.forward_as_attachment || action != COMPOSE_FORWARD) && msginfo_list != NULL && action != COMPOSE_FORWARD_AS_ATTACH && g_slist_length(msginfo_list) > 1) { GSList *cur = msginfo_list; gchar *msg = g_strdup_printf(_("You are about to reply to %d " "messages. Opening the windows " "could take some time. Do you " - "want to continue?"), + "want to continue?"), g_slist_length(msginfo_list)); if (g_slist_length(msginfo_list) > 9 && alertpanel(_("Warning"), msg, NULL, _("_Cancel"), NULL, _("_Yes"), @@ -12434,7 +12394,7 @@ void compose_check_for_email_account(Compose *compose) { PrefsAccount *ac = NULL, *curr = NULL; GList *list; - + if (!compose) return; @@ -12442,7 +12402,7 @@ void compose_check_for_email_account(Compose *compose) ac = account_get_cur_account(); if (ac->protocol == A_NNTP) { list = account_get_list(); - + for( ; list != NULL ; list = g_list_next(list)) { curr = (PrefsAccount *) list->data; if (curr->protocol != A_NNTP) { @@ -12452,19 +12412,19 @@ void compose_check_for_email_account(Compose *compose) } } combobox_select_by_data(GTK_COMBO_BOX(compose->account_combo), - ac->account_id); + ac->account_id); } } -void compose_reply_to_address(MessageView *msgview, MsgInfo *msginfo, +void compose_reply_to_address(MessageView *msgview, MsgInfo *msginfo, const gchar *address) { GSList *msginfo_list = NULL; gchar *body = messageview_get_selection(msgview); Compose *compose; - + msginfo_list = g_slist_prepend(msginfo_list, msginfo); - + compose = compose_reply_mode(COMPOSE_REPLY_TO_ADDRESS, msginfo_list, body); compose_check_for_email_account(compose); compose_set_folder_prefs(compose, msginfo->folder, FALSE); @@ -12561,7 +12521,7 @@ static MsgInfo *compose_msginfo_new_from_compose(Compose *compose) } g_free(header); - g_free(entry); + g_free(entry); } /* other data is unset */ diff --git a/src/compose.h b/src/compose.h @@ -14,7 +14,7 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * */ #ifndef __COMPOSE_H__ @@ -119,7 +119,7 @@ struct _Compose /* Toolbar handlebox */ GtkWidget *handlebox; Toolbar *toolbar; - + GtkWidget *vbox2; /* Header */ @@ -204,11 +204,11 @@ struct _Compose gboolean modified; gboolean sending; - + gboolean return_receipt; gboolean batch; - + GSList *to_list; GSList *newsgroup_list; @@ -230,11 +230,11 @@ struct _Compose gint priority; gchar *redirect_filename; - + gboolean remove_references; gint64 draft_timeout_tag; - + GtkTextTag *no_wrap_tag; GtkTextTag *no_join_tag; GtkTextTag *signature_tag; @@ -263,12 +263,6 @@ struct _Compose GtkAspell *gtkaspell; GtkWidget *aspell_options_menu; #endif - -#ifdef USE_LDAP - /* List of addressbook ifaces which we disabled, and will - * enable in compose_destroy. */ - GSList *passworded_ldap_servers; -#endif }; struct _AttachInfo @@ -332,13 +326,13 @@ void compose_reflect_prefs_pixmap_theme (void); void compose_destroy_all (void); gboolean compose_draft (gpointer data, guint action); -void compose_toolbar_cb (gint action, +void compose_toolbar_cb (gint action, gpointer data); void compose_reply_to_address (MessageView *msgview, MsgInfo *msginfo, const gchar *address); -void compose_reply_from_messageview (MessageView *msgview, - GSList *msginfo_list, +void compose_reply_from_messageview (MessageView *msgview, + GSList *msginfo_list, guint action); void compose_action_cb (void *data); @@ -351,8 +345,8 @@ gboolean compose_search_string_backward (Compose *compose, const gchar *str, gboolean case_sens); ComposeQueueResult compose_queue (Compose *compose, - gint *msgnum, - FolderItem **item, + gint *msgnum, + FolderItem **item, gchar **msgpath, gboolean remove_reedit_target); gboolean compose_close (Compose *compose); diff --git a/src/crash.c b/src/crash.c @@ -55,20 +55,20 @@ #include "manage_window.h" /* - * NOTE: the crash dialog is called when claws is not + * NOTE: the crash dialog is called when claws is not * initialized, so do not assume settings are available. - * for example, loading / creating pixmaps seems not + * for example, loading / creating pixmaps seems not * to be possible. */ /***/ -static GtkWidget *crash_dialog_show (const gchar *text, +static GtkWidget *crash_dialog_show (const gchar *text, const gchar *debug_output); static void crash_create_debugger_file (void); static void crash_save_crash_log (GtkButton *, const gchar *); static void crash_create_bug_report (GtkButton *, const gchar *); -static void crash_debug (unsigned long crash_pid, +static void crash_debug (unsigned long crash_pid, gchar *exe_image, GString *debug_output); static gchar *get_compiled_in_features (void); @@ -89,7 +89,7 @@ static const gchar *DEBUG_SCRIPT = "thread all apply\nbt full\nkill\nq"; */ void crash_install_handlers(void) { -#if CRASH_DIALOG +#if CRASH_DIALOG sigset_t mask; if (!is_crash_dialog_allowed()) return; @@ -100,7 +100,7 @@ void crash_install_handlers(void) signal(SIGSEGV, crash_handler); sigaddset(&mask, SIGSEGV); #endif - + #ifdef SIGFPE signal(SIGFPE, crash_handler); sigaddset(&mask, SIGFPE); @@ -117,17 +117,17 @@ void crash_install_handlers(void) #endif sigprocmask(SIG_UNBLOCK, &mask, 0); -#endif /* CRASH_DIALOG */ +#endif /* CRASH_DIALOG */ } /***/ /*! - *\brief crash dialog entry point + *\brief crash dialog entry point */ -void crash_main(const char *arg) +void crash_main(const char *arg) { -#if CRASH_DIALOG +#if CRASH_DIALOG gchar *text; gchar **tokens; unsigned long pid; @@ -140,7 +140,7 @@ void crash_main(const char *arg) text = g_strdup_printf(_("Claws Mail process (%ld) received signal %ld"), pid, atol(tokens[1])); - output = g_string_new(""); + output = g_string_new(""); crash_debug(pid, tokens[2], output); /* @@ -152,7 +152,7 @@ void crash_main(const char *arg) g_string_free(output, TRUE); g_free(text); g_strfreev(tokens); -#endif /* CRASH_DIALOG */ +#endif /* CRASH_DIALOG */ } /*! @@ -182,7 +182,7 @@ static GtkWidget *crash_dialog_show(const gchar *text, const gchar *debug_output GtkTextIter iter; gchar *features = get_compiled_in_features(); gchar *os = get_operating_system(); - gchar *lversion = get_lib_version(); + gchar *lversion = get_lib_version(); window1 = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "crash"); gtk_container_set_border_width(GTK_CONTAINER(window1), 5); @@ -266,7 +266,7 @@ static GtkWidget *crash_dialog_show(const gchar *text, const gchar *debug_output gtk_widget_show(button5); gtk_container_add(GTK_CONTAINER(hbuttonbox4), button5); gtk_widget_set_can_default(button5, TRUE); - + g_signal_connect(G_OBJECT(window1), "delete_event", G_CALLBACK(gtk_main_quit), NULL); g_signal_connect(G_OBJECT(button3), "clicked", @@ -287,13 +287,13 @@ static GtkWidget *crash_dialog_show(const gchar *text, const gchar *debug_output /*! *\brief create debugger script file in claws directory. - * all the other options (creating temp files) looked too + * all the other options (creating temp files) looked too * convoluted. */ static void crash_create_debugger_file(void) { gchar *filespec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, DEBUGGERRC, NULL); - + str_write_to_file(DEBUG_SCRIPT, filespec, TRUE); g_free(filespec); } @@ -315,11 +315,11 @@ static void crash_save_crash_log(GtkButton *button, const gchar *text) if (NULL != (filename = filesel_select_file_save(_("Save crash information"), buf)) && *filename) str_write_to_file(text, filename, TRUE); - g_free(filename); + g_free(filename); } /*! - *\brief create bug report (goes to Claws Mail bug tracker) + *\brief create bug report (goes to Claws Mail bug tracker) */ static void crash_create_bug_report(GtkButton *button, const gchar *data) { @@ -329,7 +329,7 @@ static void crash_create_bug_report(GtkButton *button, const gchar *data) /*! *\brief launches debugger and attaches it to crashed claws */ -static void crash_debug(unsigned long crash_pid, +static void crash_debug(unsigned long crash_pid, gchar *exe_image, GString *debug_output) { @@ -354,7 +354,7 @@ static void crash_debug(unsigned long crash_pid, /* * setup debugger to attach to crashed claws */ - *argptr++ = "gdb"; + *argptr++ = "gdb"; *argptr++ = "--nw"; *argptr++ = "--nx"; *argptr++ = "--quiet"; @@ -372,12 +372,12 @@ static void crash_debug(unsigned long crash_pid, if (dup(choutput[1]) < 0) perror("dup"); close(choutput[0]); - if (-1 == execvp("gdb", argp)) + if (-1 == execvp("gdb", argp)) perror("execvp"); } else { char buf[100]; int r; - + waitpid(pid, NULL, 0); /* @@ -396,14 +396,14 @@ static void crash_debug(unsigned long crash_pid, g_string_append(debug_output, buf); } } while (r > 0); - + close(choutput[0]); close(choutput[1]); - + /* * kill the process we attached to */ - kill(crash_pid, SIGCONT); + kill(crash_pid, SIGCONT); } } @@ -427,12 +427,6 @@ static gchar *get_compiled_in_features(void) #if USE_GNUTLS " GnuTLS" #endif -#if USE_LDAP - " LDAP" -#endif -#if USE_JPILOT - " JPilot" -#endif #if USE_ENCHANT " GNU/aspell" #endif @@ -477,7 +471,7 @@ static gchar *get_operating_system(void) utsbuf.machine); #else return g_strdup(_("Unknown")); - + #endif } @@ -493,7 +487,7 @@ static gboolean is_crash_dialog_allowed(void) } /*! - *\brief this handler will probably evolve into + *\brief this handler will probably evolve into * something better. */ static void crash_handler(int sig) @@ -509,7 +503,7 @@ static void crash_handler(int sig) /* - * besides guarding entrancy it's probably also better + * besides guarding entrancy it's probably also better * to mask off signals */ if (crashed_) return; @@ -517,7 +511,7 @@ static void crash_handler(int sig) crashed_++; #ifdef SIGTERM - if (sig == SIGTERM) + if (sig == SIGTERM) clean_quit(NULL); #endif @@ -531,13 +525,13 @@ static void crash_handler(int sig) if (0 == (pid = fork())) { char buf[50]; char *args[5]; - + /* * probably also some other parameters (like GTK ones). * also we pass the full startup dir and the real command * line typed in (argv0) */ - args[0] = argv0; + args[0] = argv0; args[1] = "--debug"; args[2] = "--crash"; sprintf(buf, "%d,%d,%s", getppid(), sig, argv0); diff --git a/src/editaddress.c b/src/editaddress.c @@ -795,7 +795,7 @@ static GtkWidget* addressbook_edit_person_widgets_create( GtkWidget* container, GtkWidget *cancel_btn; vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4); - gtk_container_set_border_width(GTK_CONTAINER(vbox), BORDER_WIDTH); + gtk_container_set_border_width(GTK_CONTAINER(vbox), BORDER_WIDTH); gtk_widget_show(vbox); gtk_container_add(GTK_CONTAINER(container), vbox); @@ -941,7 +941,7 @@ static void addressbook_edit_person_set_picture(void) scalewidth = (width * 128) / height; scaleheight = 128; } - pixbuf = gdk_pixbuf_new_from_file_at_scale(filename, + pixbuf = gdk_pixbuf_new_from_file_at_scale(filename, scalewidth, scaleheight, TRUE, &error); } else { pixbuf = gdk_pixbuf_new_from_file(filename, &error); @@ -963,7 +963,7 @@ static void addressbook_edit_person_set_picture(void) gtk_image_set_from_pixbuf(GTK_IMAGE(personeditdlg.image), pixbuf); g_object_unref(pixbuf); } -} +} static void addressbook_edit_person_clear_picture(void) { @@ -993,9 +993,9 @@ static GtkActionEntry editaddr_popup_entries[] = {"EditAddressPopup/UnsetPicture", NULL, N_("_Unset picture"), NULL, NULL, G_CALLBACK(addressbook_edit_person_unset_picture_menu_cb) }, }; -static void addressbook_edit_person_set_picture_cb(GtkWidget *widget, +static void addressbook_edit_person_set_picture_cb(GtkWidget *widget, GdkEventButton *event, gpointer data) -{ +{ if (event->button == 1) { addressbook_edit_person_set_picture(); } else { @@ -1006,10 +1006,10 @@ static void addressbook_edit_person_set_picture_cb(GtkWidget *widget, static gboolean addressbook_edit_person_picture_popup_menu(GtkWidget *widget, gpointer data) { GdkEventButton event; - + event.button = 3; event.time = gtk_get_current_event_time(); - + addressbook_edit_person_set_picture_cb(NULL, &event, data); return TRUE; @@ -1032,7 +1032,7 @@ static void addressbook_edit_person_page_basic( gint pageNum, gchar *pageLbl ) { vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 20 ); hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8 ); - gtk_widget_show( vbox ); + gtk_widget_show( vbox ); if (!editaddr_popup_menu) { cm_menu_create_action_group("EditAddressPopup", editaddr_popup_entries, @@ -1047,29 +1047,29 @@ static void addressbook_edit_person_page_basic( gint pageNum, gchar *pageLbl ) { /* User's picture */ ebox_picture = gtk_event_box_new(); frame_picture = gtk_frame_new(_("Photo")); - + /* Room for a photo */ personeditdlg.image = gtk_image_new(); addressbook_edit_person_clear_picture(); gtk_container_add(GTK_CONTAINER(ebox_picture), personeditdlg.image); - gtk_container_add(GTK_CONTAINER(frame_picture), ebox_picture); + gtk_container_add(GTK_CONTAINER(frame_picture), ebox_picture); gtk_container_add(GTK_CONTAINER( personeditdlg.notebook ), hbox ); gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH ); gtk_container_set_border_width( GTK_CONTAINER (hbox), BORDER_WIDTH ); label = gtk_label_new_with_mnemonic( pageLbl ); gtk_widget_show( label ); - + gtk_box_pack_start(GTK_BOX(hbox), frame_picture, TRUE, TRUE, 0); - + gtk_notebook_set_tab_label( GTK_NOTEBOOK( personeditdlg.notebook ), gtk_notebook_get_nth_page( GTK_NOTEBOOK( personeditdlg.notebook ), pageNum ), label ); - + g_signal_connect(G_OBJECT(ebox_picture), "popup-menu", G_CALLBACK(addressbook_edit_person_picture_popup_menu), NULL); - g_signal_connect(G_OBJECT(ebox_picture), "button_press_event", + g_signal_connect(G_OBJECT(ebox_picture), "button_press_event", G_CALLBACK(addressbook_edit_person_set_picture_cb), NULL); table = gtk_grid_new(); @@ -1166,7 +1166,7 @@ static gboolean edit_person_entry_email_pressed(GtkWidget *widget, GdkEventKey * if (event && (event->keyval == GDK_KEY_KP_Enter || event->keyval == GDK_KEY_Return)) { if (email_saving) - edit_person_email_modify(NULL); + edit_person_email_modify(NULL); else if (email_adding) edit_person_email_add(NULL); } @@ -1325,7 +1325,7 @@ static void addressbook_edit_person_page_email( gint pageNum, gchar *pageLbl ) { buttonDel = gtkut_stock_button("edit-delete", _("D_elete")); buttonMod = gtkut_stock_button("document-save", _("_Save")); buttonAdd = gtkut_stock_button("list-add", _("_Add")); - + #ifndef GENERIC_UMPC gtk_container_add( GTK_CONTAINER(vbuttonbox), buttonUp ); @@ -1538,7 +1538,7 @@ static void addressbook_edit_person_page_attrib( gint pageNum, gchar *pageLbl ) gtk_combo_box_set_active(GTK_COMBO_BOX(entry_name), -1); if (prefs_common.addressbook_custom_attributes) combobox_set_popdown_strings(GTK_COMBO_BOX_TEXT(entry_name), - prefs_common.addressbook_custom_attributes); + prefs_common.addressbook_custom_attributes); /* Button box */ vboxb = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4 ); gtk_box_pack_start(GTK_BOX(hbox), vboxb, FALSE, FALSE, 2); @@ -1558,7 +1558,7 @@ static void addressbook_edit_person_page_attrib( gint pageNum, gchar *pageLbl ) buttonAdd = gtkut_stock_button("list-add", _("_Add")); gtk_container_add( GTK_CONTAINER(vbuttonbox), buttonAdd ); - + gtk_widget_set_sensitive(buttonDel,FALSE); gtk_widget_set_sensitive(buttonMod,FALSE); gtk_widget_set_sensitive(buttonAdd,FALSE); @@ -1596,12 +1596,7 @@ static void addressbook_edit_person_create( GtkWidget *parent, gboolean *cancell addressbook_edit_person_widgetset_create( parent, cancelled ); addressbook_edit_person_page_basic( PAGE_BASIC, _( "_User Data" ) ); addressbook_edit_person_page_email( PAGE_EMAIL, _( "_Email Addresses" ) ); -#ifdef USE_LDAP - if (personeditdlg.ldap) - addressbook_edit_person_page_attrib_ldap(&personeditdlg, PAGE_ATTRIBUTES, _("O_ther Attributes")); - else -#endif - addressbook_edit_person_page_attrib( PAGE_ATTRIBUTES, _( "O_ther Attributes" ) ); + addressbook_edit_person_page_attrib( PAGE_ATTRIBUTES, _( "O_ther Attributes" ) ); gtk_widget_show_all( personeditdlg.container ); } @@ -1749,7 +1744,7 @@ static gboolean addressbook_edit_person_close( gboolean cancelled ) listAttrib = NULL; if(!cancelled && current_person != NULL) { - /* Set current_person stuff */ + /* Set current_person stuff */ gchar *name; gchar *cn = edit_person_get_common_name_from_widgets(); @@ -1757,14 +1752,14 @@ static gboolean addressbook_edit_person_close( gboolean cancelled ) addritem_person_set_common_name( current_person, cn ); g_free( cn ); - if (personeditdlg.picture_set) { + if (personeditdlg.picture_set) { GdkPixbuf * pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(personeditdlg.image)); if (!current_person->picture) - name = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, ADDRBOOK_DIR, G_DIR_SEPARATOR_S, + name = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, ADDRBOOK_DIR, G_DIR_SEPARATOR_S, ADDRITEM_ID(current_person), ".png", NULL ); - else - name = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, ADDRBOOK_DIR, G_DIR_SEPARATOR_S, + else + name = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, ADDRBOOK_DIR, G_DIR_SEPARATOR_S, current_person->picture, ".png", NULL ); gdk_pixbuf_save(pixbuf, name, "png", &error, NULL); @@ -1780,10 +1775,10 @@ static gboolean addressbook_edit_person_close( gboolean cancelled ) g_free( name ); } else { if (!current_person->picture) - name = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, ADDRBOOK_DIR, G_DIR_SEPARATOR_S, + name = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, ADDRBOOK_DIR, G_DIR_SEPARATOR_S, ADDRITEM_ID(current_person), ".png", NULL ); - else - name = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, ADDRBOOK_DIR, G_DIR_SEPARATOR_S, + else + name = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, ADDRBOOK_DIR, G_DIR_SEPARATOR_S, current_person->picture, ".png", NULL ); claws_unlink(name); g_free(name); @@ -1811,7 +1806,7 @@ static gboolean addressbook_edit_person_close( gboolean cancelled ) return TRUE; } - + /* * Edit person. * Enter: abf Address book. @@ -1836,7 +1831,7 @@ ItemPerson *addressbook_edit_person( AddressBookFile *abf, ItemFolder *parent_fo current_person = person; current_parent_folder = parent_folder; edit_person_close_post_update_cb = post_update_cb; - personeditdlg.ldap = (abf && abf->type == ADBOOKTYPE_LDAP)? TRUE : FALSE; + personeditdlg.ldap = FALSE; if( personeditdlg.container ) { gtk_widget_destroy(personeditdlg.container); @@ -1849,7 +1844,7 @@ ItemPerson *addressbook_edit_person( AddressBookFile *abf, ItemFolder *parent_fo gtk_widget_grab_focus(personeditdlg.ok_btn); gtk_widget_grab_focus(personeditdlg.entry_name); } - + personeditdlg.read_only = (current_abf == NULL); update_sensitivity(); @@ -1882,8 +1877,8 @@ ItemPerson *addressbook_edit_person( AddressBookFile *abf, ItemFolder *parent_fo cm_menu_set_sensitive("EditAddressPopup/SetPicture", !personeditdlg.ldap); cm_menu_set_sensitive("EditAddressPopup/UnsetPicture", !personeditdlg.ldap); - if( current_person->picture ) { - filename = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, ADDRBOOK_DIR, G_DIR_SEPARATOR_S, + if( current_person->picture ) { + filename = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, ADDRBOOK_DIR, G_DIR_SEPARATOR_S, current_person->picture, ".png", NULL ); if (is_file_exist(filename)) { pixbuf = gdk_pixbuf_new_from_file(filename, &error); @@ -1903,7 +1898,7 @@ ItemPerson *addressbook_edit_person( AddressBookFile *abf, ItemFolder *parent_fo no_img: addressbook_edit_person_clear_picture(); } - + g_free(filename); if (pixbuf) { g_object_unref(pixbuf); @@ -1958,7 +1953,7 @@ no_img: return NULL; } } - + return person; } diff --git a/src/editaddress_other_attributes_ldap.c b/src/editaddress_other_attributes_ldap.c @@ -20,453 +20,3 @@ # include "config.h" #include "claws-features.h" #endif - -#ifdef USE_LDAP - -#include "defs.h" - -#include "mgutils.h" -#include "addressbook.h" -#include "addressitem.h" -#include "addritem.h" -#include "addrbook.h" -#include "manage_window.h" -#include "gtkutils.h" -#include "codeconv.h" -#include "editaddress.h" -#include "editaddress_other_attributes_ldap.h" -#include "prefs_common.h" - -#define ATTRIB_COL_WIDTH_NAME 120 -#define ATTRIB_COL_WIDTH_VALUE 180 - -PersonEditDlg *personEditDlg; -gboolean attrib_adding = FALSE, attrib_saving = FALSE; - -int get_attribute_index(const gchar *string_literal) { - int i = 0; - /*int count = sizeof(ATTRIBUTE) / sizeof(*ATTRIBUTE);*/ - const gchar **attribute = ATTRIBUTE; - - cm_return_val_if_fail(string_literal != NULL, -1); - while (*attribute) { - debug_print("Comparing %s to %s\n", *attribute, string_literal); - if (strcmp(*attribute++, string_literal) == 0) - return i; - i++; - } - return -1; -} - -static void edit_person_status_show(gchar *msg) { - if (personEditDlg->statusbar != NULL) { - gtk_statusbar_pop(GTK_STATUSBAR(personEditDlg->statusbar), personEditDlg->status_cid); - if(msg) { - gtk_statusbar_push(GTK_STATUSBAR(personEditDlg->statusbar), personEditDlg->status_cid, msg); - } - } -} - -static void edit_person_attrib_clear(gpointer data) { - gtk_combo_box_set_active(GTK_COMBO_BOX(personEditDlg->entry_atname), 0); - gtk_entry_set_text(GTK_ENTRY(personEditDlg->entry_atvalue), ""); -} - -static gboolean list_find_attribute(const gchar *attr) -{ - GtkWidget *view = personEditDlg->view_attrib; - GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(view)); - GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); - GtkTreeIter iter; - UserAttribute *attrib; - - if (!gtk_tree_model_get_iter_first(model, &iter)) - return FALSE; - - do { - gtk_tree_model_get(model, &iter, ATTRIB_COL_PTR, &attrib, -1); - if (!g_ascii_strcasecmp(attrib->name, attr)) { - gtk_tree_selection_select_iter(sel, &iter); - return TRUE; - } - } while (gtk_tree_model_iter_next(model, &iter)); - - return FALSE; -} - -static void edit_person_combo_box_changed(GtkComboBox *opt_menu, gpointer data) -{ - GtkWidget *view = GTK_WIDGET(data); - UserAttribute *attrib = gtkut_tree_view_get_selected_pointer( - GTK_TREE_VIEW(view), ATTRIB_COL_PTR, NULL, NULL, NULL); - gint option = gtk_combo_box_get_active(opt_menu); - const gchar *str = attrib ? attrib->name:""; - - cm_return_if_fail (option < ATTRIBUTE_SIZE); - /* A corresponding attribute in contact does not match selected option */ - if (strcmp(ATTRIBUTE[option], str) != 0) { - gtk_widget_set_sensitive(personEditDlg->attrib_add, TRUE); - gtk_widget_set_sensitive(personEditDlg->attrib_mod, TRUE); - gtk_widget_set_sensitive(personEditDlg->attrib_del, FALSE); - gtk_entry_set_text(GTK_ENTRY(personEditDlg->entry_atvalue), ""); - gtk_widget_grab_focus(personEditDlg->entry_atvalue); - edit_person_status_show(NULL); - } -} - -static void edit_person_attrib_cursor_changed(GtkTreeView *view, - gpointer user_data) -{ - UserAttribute *attrib = gtkut_tree_view_get_selected_pointer( - view, ATTRIB_COL_PTR, NULL, NULL, NULL); - - if( attrib && !personEditDlg->read_only ) { - gint index = get_attribute_index(attrib->name); - - if (index == -1) - index = 0; - - gtk_combo_box_set_active(GTK_COMBO_BOX(personEditDlg->entry_atname), index); - gtk_entry_set_text(GTK_ENTRY(personEditDlg->entry_atvalue), attrib->value); - - gtk_widget_set_sensitive(personEditDlg->attrib_del, TRUE); - } else { - gtk_widget_set_sensitive(personEditDlg->attrib_del, FALSE); - } - edit_person_status_show( NULL ); -} - -static void edit_person_attrib_delete(gpointer data) { - UserAttribute *attrib; - GtkTreeModel *model; - GtkTreeSelection *sel; - GtkTreeIter iter; - gboolean has_row = FALSE; - gint n; - - edit_person_attrib_clear(NULL); - edit_person_status_show(NULL); - - attrib = gtkut_tree_view_get_selected_pointer( - GTK_TREE_VIEW(personEditDlg->view_attrib), ATTRIB_COL_PTR, - &model, &sel, &iter); - - if (attrib) { - /* Remove list entry, and set iter to next row, if any */ - has_row = gtk_list_store_remove(GTK_LIST_STORE(model), &iter); - addritem_free_attribute(attrib); - attrib = NULL; - } - - /* Position hilite bar */ - if (!has_row) { - /* The removed row was the last in the list, so iter is not - * valid. Find out if there is at least one row remaining - * in the list, and select the last one if so. */ - n = gtk_tree_model_iter_n_children(model, NULL); - if (n > 0 && gtk_tree_model_iter_nth_child(model, &iter, NULL, n-1)) { - /* It exists. */ - has_row = TRUE; - } - } - - if (!has_row) - gtk_tree_selection_select_iter(sel, &iter); - - edit_person_attrib_cursor_changed( - GTK_TREE_VIEW(personEditDlg->view_attrib), NULL); -} - -static UserAttribute *edit_person_attrib_edit(gboolean *error, UserAttribute *attrib) { - UserAttribute *retVal = NULL; - gchar *sName, *sValue, *sName_, *sValue_; - gint index; - - *error = TRUE; - index = gtk_combo_box_get_active(GTK_COMBO_BOX(personEditDlg->entry_atname)); - sName_ = (gchar *) ATTRIBUTE[index]; - sValue_ = gtk_editable_get_chars(GTK_EDITABLE(personEditDlg->entry_atvalue), 0, -1); - sName = mgu_email_check_empty(sName_); - sValue = mgu_email_check_empty(sValue_); - g_free(sValue_); - - if (sName && sValue) { - debug_print("sname && svalue\n"); - if (attrib == NULL) { - attrib = addritem_create_attribute(); - } - addritem_attrib_set_name(attrib, sName); - addritem_attrib_set_value(attrib, sValue); - retVal = attrib; - *error = FALSE; - } - else { - edit_person_status_show(N_( "A Name and Value must be supplied." )); - gtk_widget_grab_focus(personEditDlg->entry_atvalue); - } - - g_free(sName); - g_free(sValue); - - return retVal; -} - -static void edit_person_attrib_modify(gpointer data) { - gboolean errFlg = FALSE; - GtkTreeModel *model; - GtkTreeIter iter; - UserAttribute *attrib; - - attrib = gtkut_tree_view_get_selected_pointer( - GTK_TREE_VIEW(personEditDlg->view_attrib), ATTRIB_COL_PTR, - &model, NULL, &iter); - if (attrib) { - edit_person_attrib_edit(&errFlg, attrib); - if (!errFlg) { - gtk_list_store_set(GTK_LIST_STORE(model), &iter, - ATTRIB_COL_NAME, attrib->name, - ATTRIB_COL_VALUE, attrib->value, - -1); - edit_person_attrib_clear(NULL); - } - } -} - -static void edit_person_attrib_add(gpointer data) { - gboolean errFlg = FALSE; - GtkTreeModel *model = gtk_tree_view_get_model( - GTK_TREE_VIEW(personEditDlg->view_attrib)); - GtkTreeSelection *sel = gtk_tree_view_get_selection( - GTK_TREE_VIEW(personEditDlg->view_attrib)); - GtkTreeIter iter, iter2; - UserAttribute *attrib, *prev_attrib; - - attrib = edit_person_attrib_edit(&errFlg, NULL); - if (attrib == NULL) /* input for new attribute is not valid */ - return; - - prev_attrib = gtkut_tree_view_get_selected_pointer( - GTK_TREE_VIEW(personEditDlg->view_attrib), ATTRIB_COL_PTR, - &model, &sel, &iter); - - if (prev_attrib == NULL) { - /* No row selected, or list empty, add it as first row. */ - gtk_list_store_insert(GTK_LIST_STORE(model), &iter, 0); - } else { - /* Add it after the currently selected row. */ - gtk_list_store_insert_after(GTK_LIST_STORE(model), &iter2, - &iter); - iter = iter2; - } - - /* Fill out the new row. */ - gtk_list_store_set(GTK_LIST_STORE(model), &iter, - ATTRIB_COL_NAME, attrib->name, - ATTRIB_COL_VALUE, attrib->value, - ATTRIB_COL_PTR, attrib, - -1); - gtk_tree_selection_select_iter(sel, &iter); - edit_person_attrib_clear(NULL); -} - -static void edit_person_entry_att_changed (GtkWidget *entry, gpointer data) -{ - GtkTreeModel *model = gtk_tree_view_get_model( - GTK_TREE_VIEW(personEditDlg->view_attrib)); - gboolean non_empty = (gtk_tree_model_iter_n_children(model, NULL) > 0); - const gchar *sName; - int index; - - if (personEditDlg->read_only) - return; - - index = gtk_combo_box_get_active(GTK_COMBO_BOX(personEditDlg->entry_atname)); - sName = ATTRIBUTE[index]; - if (list_find_attribute(sName)) { - gtk_widget_set_sensitive(personEditDlg->attrib_add,FALSE); - gtk_widget_set_sensitive(personEditDlg->attrib_mod,non_empty); - attrib_adding = FALSE; - attrib_saving = non_empty; - } - else { - gtk_widget_set_sensitive(personEditDlg->attrib_add,TRUE); - gtk_widget_set_sensitive(personEditDlg->attrib_mod,non_empty); - attrib_adding = TRUE; - attrib_saving = non_empty; - } -} - -static gboolean edit_person_entry_att_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data) -{ - if (event && (event->keyval == GDK_KEY_Return || event->keyval == GDK_KEY_KP_Enter)) { - if (attrib_saving) - edit_person_attrib_modify(NULL); - else if (attrib_adding) - edit_person_attrib_add(NULL); - } - return FALSE; -} - -void addressbook_edit_person_page_attrib_ldap(PersonEditDlg *dialog, gint pageNum, gchar *pageLbl) { - GtkWidget *combo_box; - GtkWidget *vbox; - GtkWidget *hbox; - GtkWidget *vboxl; - GtkWidget *vboxb; - GtkWidget *vbuttonbox; - GtkWidget *buttonDel; - GtkWidget *buttonMod; - GtkWidget *buttonAdd; - - GtkWidget *table; - GtkWidget *label; - GtkWidget *scrollwin; - GtkWidget *view; - GtkWidget *entry_value; - GtkListStore *store; - GtkTreeViewColumn *col; - GtkCellRenderer *rdr; - GtkTreeSelection *sel; - - personEditDlg = dialog; - - vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8); - gtk_widget_show(vbox); - gtk_container_add(GTK_CONTAINER(personEditDlg->notebook), vbox); - gtk_container_set_border_width(GTK_CONTAINER(vbox), BORDER_WIDTH); - - label = gtk_label_new_with_mnemonic(pageLbl); - gtk_widget_show(label); - gtk_notebook_set_tab_label( - GTK_NOTEBOOK(personEditDlg->notebook), - gtk_notebook_get_nth_page(GTK_NOTEBOOK(personEditDlg->notebook), pageNum), label); - - /* Split into two areas */ - hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); - gtk_container_add(GTK_CONTAINER(vbox), hbox); - - /* Attribute list */ - vboxl = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4); - gtk_container_add(GTK_CONTAINER(hbox), vboxl); - gtk_container_set_border_width(GTK_CONTAINER(vboxl), 4); - - scrollwin = gtk_scrolled_window_new(NULL, NULL); - gtk_container_add(GTK_CONTAINER(vboxl), scrollwin); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - - store = gtk_list_store_new(ATTRIB_N_COLS, - G_TYPE_STRING, G_TYPE_STRING, - G_TYPE_POINTER, -1); - - view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); - g_object_unref(store); - gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), TRUE); - sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); - gtk_tree_selection_set_mode(sel, GTK_SELECTION_BROWSE); - - rdr = gtk_cell_renderer_text_new(); - col = gtk_tree_view_column_new_with_attributes(_("Name"), rdr, - "markup", ATTRIB_COL_NAME, NULL); - gtk_tree_view_column_set_min_width(col, ATTRIB_COL_WIDTH_NAME); - gtk_tree_view_append_column(GTK_TREE_VIEW(view), col); - - col = gtk_tree_view_column_new_with_attributes(_("Value"), rdr, - "markup", ATTRIB_COL_VALUE, NULL); - gtk_tree_view_column_set_min_width(col, ATTRIB_COL_WIDTH_VALUE); - gtk_tree_view_append_column(GTK_TREE_VIEW(view), col); - - gtk_container_add(GTK_CONTAINER(scrollwin), view); - - /* Data entry area */ - table = gtk_grid_new(); - gtk_box_pack_start(GTK_BOX(vboxl), table, FALSE, FALSE, 0); - gtk_container_set_border_width(GTK_CONTAINER(table), 4); - gtk_grid_set_row_spacing(GTK_GRID(table), 4); - gtk_grid_set_column_spacing(GTK_GRID(table), 4); - - /* First row */ - label = gtk_label_new(N_("Name")); - gtk_label_set_xalign(GTK_LABEL(label), 0.0); - gtk_grid_attach(GTK_GRID(table), label, 0, 0, 1, 1); - - gchar **attribute = (gchar **) ATTRIBUTE; - - combo_box = gtk_combo_box_text_new(); - - while (*attribute) { - if (!strcmp(*attribute, "jpegPhoto")) { - attribute++; - continue; - } - gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo_box), *attribute++); - } - gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box), 0); - - gtk_grid_attach(GTK_GRID(table), combo_box, 1, 0, 1, 1); - gtk_widget_set_hexpand(combo_box, TRUE); - gtk_widget_set_halign(combo_box, GTK_ALIGN_FILL); - - /* Next row */ - label = gtk_label_new(N_("Value")); - gtk_label_set_xalign(GTK_LABEL(label), 0.0); - gtk_grid_attach(GTK_GRID(table), label, 0, 1, 1, 1); - - entry_value = gtk_entry_new(); - gtk_grid_attach(GTK_GRID(table), entry_value, 1, 1, 1, 1); - gtk_widget_set_hexpand(entry_value, TRUE); - gtk_widget_set_halign(entry_value, GTK_ALIGN_FILL); - - /* Button box */ - vboxb = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4); - gtk_box_pack_start(GTK_BOX(hbox), vboxb, FALSE, FALSE, 2); - - vbuttonbox = gtk_button_box_new(GTK_ORIENTATION_VERTICAL); - gtk_button_box_set_layout(GTK_BUTTON_BOX(vbuttonbox), GTK_BUTTONBOX_START); - gtk_box_set_spacing(GTK_BOX(vbuttonbox), 8); - gtk_container_set_border_width(GTK_CONTAINER(vbuttonbox), 4); - gtk_container_add(GTK_CONTAINER(vboxb), vbuttonbox); - - /* Buttons */ - buttonDel = gtkut_stock_button("edit-delete", _("D_elete")); - gtk_container_add(GTK_CONTAINER(vbuttonbox), buttonDel); - - buttonMod = gtkut_stock_button("document-save", _("_Save")); - gtk_container_add(GTK_CONTAINER(vbuttonbox), buttonMod); - - buttonAdd = gtkut_stock_button("list-add", _("_Add")); - gtk_container_add(GTK_CONTAINER(vbuttonbox), buttonAdd); - - gtk_widget_set_sensitive(buttonDel,FALSE); - gtk_widget_set_sensitive(buttonMod,FALSE); - gtk_widget_set_sensitive(buttonAdd,FALSE); - - gtk_widget_show_all(vbox); - - /* Event handlers */ - g_signal_connect(G_OBJECT(view), "cursor-changed", - G_CALLBACK(edit_person_attrib_cursor_changed), NULL); - g_signal_connect(G_OBJECT(buttonDel), "clicked", - G_CALLBACK(edit_person_attrib_delete), NULL); - g_signal_connect(G_OBJECT(buttonMod), "clicked", - G_CALLBACK(edit_person_attrib_modify), NULL); - g_signal_connect(G_OBJECT(buttonAdd), "clicked", - G_CALLBACK(edit_person_attrib_add), NULL); - g_signal_connect(G_OBJECT(combo_box), "changed", - G_CALLBACK(edit_person_entry_att_changed), NULL); - g_signal_connect(G_OBJECT(entry_value), "key_press_event", - G_CALLBACK(edit_person_entry_att_pressed), NULL); - g_signal_connect(G_OBJECT(combo_box), "changed", - G_CALLBACK(edit_person_combo_box_changed), view); - - personEditDlg->view_attrib = view; - personEditDlg->entry_atname = combo_box; - personEditDlg->entry_atvalue = entry_value; - personEditDlg->attrib_add = buttonAdd; - personEditDlg->attrib_del = buttonDel; - personEditDlg->attrib_mod = buttonMod; -} - -#endif /* USE_LDAP */ - - diff --git a/src/editaddress_other_attributes_ldap.h b/src/editaddress_other_attributes_ldap.h @@ -14,7 +14,7 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * */ /* @@ -78,38 +78,4 @@ struct _PersonEdit_dlg { gboolean ldap; }; -#ifdef USE_LDAP - -static const char *ATTRIBUTE[] = { - "telephoneNumber", - /*"description (Remarks)",*/ - "title", - "telexNumber", - "facsimileTelephoneNumber", - "street", - "postOfficeBox", - "postalCode", - "postalAddress", - "st", /* state or province */ - "l", /* locality Name */ - "departmentNumber", - "homePhone", - "homePostalAddress", - "initials", - "labeledURI", - "mobile", - "pager", - "roomNumber", - "jpegPhoto", - NULL -}; - -static const int ATTRIBUTE_SIZE = (sizeof(ATTRIBUTE) / sizeof(*ATTRIBUTE)) - 1; - -/* Function proto types */ -void addressbook_edit_person_page_attrib_ldap(PersonEditDlg *personEditDlg, gint pageNum, gchar *pageLbl); -int get_attribute_index(const gchar *string_literal); - -#endif /* USE_LDAP */ - #endif /* __EDITADDRESS_OTHER_ATTRIBUTES_LDAP_H__ */ diff --git a/src/editjpilot.c b/src/editjpilot.c @@ -1,414 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2001-2022 the Claws Mail team and Match Grun - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * Edit JPilot address book data. - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#include "claws-features.h" -#endif - -#ifdef USE_JPILOT - -#include "defs.h" - -#include <glib.h> -#include <glib/gi18n.h> -#include <gdk/gdkkeysyms.h> -#include <gtk/gtk.h> - -#include "addressbook.h" -#include "prefs_common.h" -#include "addressitem.h" -#include "jpilot.h" -#include "mgutils.h" -#include "filesel.h" -#include "gtkutils.h" -#include "codeconv.h" -#include "manage_window.h" - -#define ADDRESSBOOK_GUESS_JPILOT "MyJPilot" -#define JPILOT_NUM_CUSTOM_LABEL 4 - -static struct _JPilotEdit { - GtkWidget *window; - GtkWidget *name_entry; - GtkWidget *file_entry; - GtkWidget *custom_check[JPILOT_NUM_CUSTOM_LABEL]; - GtkWidget *custom_label[JPILOT_NUM_CUSTOM_LABEL]; - GtkWidget *ok_btn; - GtkWidget *cancel_btn; - GtkWidget *statusbar; - gint status_cid; -} jpilotedit; - -/* -* Edit functions. -*/ -static void edit_jpilot_status_show( gchar *msg ) { - if( jpilotedit.statusbar != NULL ) { - gtk_statusbar_pop( GTK_STATUSBAR(jpilotedit.statusbar), jpilotedit.status_cid ); - if( msg ) { - gtk_statusbar_push( GTK_STATUSBAR(jpilotedit.statusbar), jpilotedit.status_cid, msg ); - } - } -} - -static gint edit_jpilot_delete_event( GtkWidget *widget, GdkEventAny *event, gboolean *cancelled ) { - *cancelled = TRUE; - gtk_main_quit(); - return TRUE; -} - -static gboolean edit_jpilot_key_pressed( GtkWidget *widget, GdkEventKey *event, gboolean *cancelled ) { - if (event && event->keyval == GDK_KEY_Escape) { - *cancelled = TRUE; - gtk_main_quit(); - } - return FALSE; -} - -static void edit_jpilot_ok( GtkWidget *widget, gboolean *cancelled ) { - *cancelled = FALSE; - gtk_main_quit(); -} - -static void edit_jpilot_cancel( GtkWidget *widget, gboolean *cancelled ) { - *cancelled = TRUE; - gtk_main_quit(); -} - -static void edit_jpilot_fill_check_box( JPilotFile *jpf ) { - gint i; - GList *node, *customLbl = NULL; - gchar *labelName; - gboolean done, checked; - for( i = 0; i < JPILOT_NUM_CUSTOM_LABEL; i++ ) { - gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( jpilotedit.custom_check[i] ), FALSE ); - gtk_label_set_text( GTK_LABEL( jpilotedit.custom_label[i] ), "" ); - } - - done = FALSE; - i = 0; - customLbl = jpilot_load_custom_label( jpf, customLbl ); - node = customLbl; - while( ! done ) { - if( node ) { - labelName = node->data; - gtk_label_set_text( GTK_LABEL( jpilotedit.custom_label[i] ), labelName ); - checked = jpilot_test_custom_label( jpf, labelName ); - gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( jpilotedit.custom_check[i] ), checked ); - i++; - if( i >= JPILOT_NUM_CUSTOM_LABEL ) done = TRUE; - node = g_list_next( node ); - } - else { - done = TRUE; - } - } - g_list_free_full( customLbl, g_free ); - customLbl = NULL; -} - -static void edit_jpilot_fill_check_box_new() { - gint i; - for( i = 0; i < JPILOT_NUM_CUSTOM_LABEL; i++ ) { - gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( jpilotedit.custom_check[i] ), FALSE ); - gtk_label_set_text( GTK_LABEL( jpilotedit.custom_label[i] ), "" ); - } -} - -static void edit_jpilot_read_check_box( JPilotFile *pilotFile ) { - gint i; - const gchar *labelName; - jpilot_clear_custom_labels( pilotFile ); - for( i = 0; i < JPILOT_NUM_CUSTOM_LABEL; i++ ) { - if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(jpilotedit.custom_check[i]) ) ) { - labelName = gtk_label_get_label (GTK_LABEL(jpilotedit.custom_label[i])); - jpilot_add_custom_label( pilotFile, labelName ); - } - } -} - -static void edit_jpilot_file_check( void ) { - gint t = -1; - gchar *sFile; - gchar *sFSFile; - gchar *sMsg; - gboolean flg; - - flg = FALSE; - sFile = gtk_editable_get_chars( GTK_EDITABLE(jpilotedit.file_entry), 0, -1 ); - if( sFile ) { - sFSFile = conv_filename_from_utf8( sFile ); - if( sFSFile && *sFSFile != '\0' ) { - /* Attempt to read file */ - JPilotFile *jpf; - jpf = jpilot_create_path( sFSFile ); - t = jpilot_read_data( jpf ); - if( t == MGU_SUCCESS ) { - /* Set check boxes */ - edit_jpilot_fill_check_box( jpf ); - flg = TRUE; - } - jpilot_free( jpf ); - jpf = NULL; - } - g_free( sFSFile ); - g_free( sFile ); - } - if( ! flg ) { - /* Clear all check boxes */ - edit_jpilot_fill_check_box_new(); - } - - /* Display appropriate message */ - if( t == MGU_SUCCESS ) { - sMsg = ""; - } - else if( t == MGU_BAD_FORMAT || t == MGU_OO_MEMORY ) { - sMsg = _("File does not appear to be JPilot format."); - } - else { - sMsg = _("Could not read file."); - } - edit_jpilot_status_show( sMsg ); -} - -static void edit_jpilot_file_select( void ) { - gchar *sFile; - gchar *sUTF8File; - - sFile = filesel_select_file_open( _("Select JPilot File"), NULL); - - if( sFile ) { - sUTF8File = conv_filename_to_utf8( sFile ); - gtk_entry_set_text( GTK_ENTRY(jpilotedit.file_entry), sUTF8File ); - g_free( sUTF8File ); - g_free( sFile ); - edit_jpilot_file_check(); - } -} - -static void addressbook_edit_jpilot_create( gboolean *cancelled ) { - GtkWidget *window; - GtkWidget *vbox; - GtkWidget *table; - GtkWidget *label; - GtkWidget *name_entry; - GtkWidget *file_entry; - GtkWidget *vbox_custom; - GtkWidget *frame_custom; - GtkWidget *custom_check[JPILOT_NUM_CUSTOM_LABEL]; - GtkWidget *custom_label[JPILOT_NUM_CUSTOM_LABEL]; - GtkWidget *hlbox; - GtkWidget *hbbox; - GtkWidget *hsep; - GtkWidget *ok_btn; - GtkWidget *cancel_btn; - GtkWidget *check_btn; - GtkWidget *file_btn; - GtkWidget *hsbox; - GtkWidget *statusbar; - gint i; - - window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "editjpilot"); - gtk_widget_set_size_request(window, 450, -1); - gtk_container_set_border_width(GTK_CONTAINER(window), 0); - gtk_window_set_title(GTK_WINDOW(window), _("Edit JPilot Entry")); - gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); - g_signal_connect(G_OBJECT(window), "delete_event", - G_CALLBACK(edit_jpilot_delete_event), - cancelled); - g_signal_connect(G_OBJECT(window), "key_press_event", - G_CALLBACK(edit_jpilot_key_pressed), - cancelled); - - vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8); - gtk_container_add(GTK_CONTAINER(window), vbox); - gtk_container_set_border_width( GTK_CONTAINER(vbox), 0 ); - - table = gtk_grid_new(); - gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); - gtk_container_set_border_width( GTK_CONTAINER(table), 8 ); - gtk_grid_set_row_spacing(GTK_GRID(table), 8); - gtk_grid_set_column_spacing(GTK_GRID(table), 8); - - /* First row */ - label = gtk_label_new(_("Name")); - gtk_label_set_xalign(GTK_LABEL(label), 0.0); - gtk_grid_attach(GTK_GRID(table), label, 0, 0, 1, 1); - - name_entry = gtk_entry_new(); - gtk_grid_attach(GTK_GRID(table), name_entry, 1, 0, 1, 1); - gtk_widget_set_hexpand(name_entry, TRUE); - gtk_widget_set_halign(name_entry, GTK_ALIGN_FILL); - - check_btn = gtk_button_new_with_label( _(" Check File ")); - gtk_grid_attach(GTK_GRID(table), check_btn, 2, 0, 1, 1); - - /* Second row */ - label = gtk_label_new(_("File")); - gtk_label_set_xalign(GTK_LABEL(label), 0.0); - gtk_grid_attach(GTK_GRID(table), label, 0, 1, 1, 1); - - file_entry = gtk_entry_new(); - gtk_grid_attach(GTK_GRID(table), file_entry, 1, 1, 1, 1); - gtk_widget_set_hexpand(file_entry, TRUE); - gtk_widget_set_halign(file_entry, GTK_ALIGN_FILL); - - file_btn = gtkut_get_browse_file_btn(_("_Browse")); - gtk_grid_attach(GTK_GRID(table), file_btn, 2, 1, 1, 1); - - /* Third row */ - frame_custom = gtk_frame_new(_("Additional e-Mail address item(s)")); - gtk_grid_attach(GTK_GRID(table), frame_custom, 1, 2, 1, 1); - - /* Now do custom labels. */ - vbox_custom = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8); - for( i = 0; i < JPILOT_NUM_CUSTOM_LABEL; i++ ) { - hlbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0 ); - custom_check[i] = gtk_check_button_new(); - custom_label[i] = gtk_label_new( "" ); - gtk_box_pack_start( GTK_BOX(hlbox), custom_check[i], FALSE, FALSE, 0 ); - gtk_box_pack_start( GTK_BOX(hlbox), custom_label[i], TRUE, TRUE, 0 ); - gtk_box_pack_start( GTK_BOX(vbox_custom), hlbox, TRUE, TRUE, 0 ); - gtk_label_set_xalign(GTK_LABEL(custom_label[1]), 0.0); - } - gtk_container_add (GTK_CONTAINER (frame_custom), vbox_custom); - gtk_container_set_border_width( GTK_CONTAINER(vbox_custom), 8 ); - - /* Status line */ - hsbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); - gtk_box_pack_end(GTK_BOX(vbox), hsbox, FALSE, FALSE, BORDER_WIDTH); - statusbar = gtk_statusbar_new(); - gtk_box_pack_start(GTK_BOX(hsbox), statusbar, TRUE, TRUE, BORDER_WIDTH); - - /* Button panel */ - gtkut_stock_button_set_create(&hbbox, &cancel_btn, NULL, _("_Cancel"), - &ok_btn, NULL, _("_OK"), - NULL, NULL, NULL); - gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0); - gtk_container_set_border_width( GTK_CONTAINER(hbbox), 0 ); - gtk_widget_grab_default(ok_btn); - - hsep = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL); - gtk_box_pack_end(GTK_BOX(vbox), hsep, FALSE, FALSE, 0); - - g_signal_connect(G_OBJECT(ok_btn), "clicked", - G_CALLBACK(edit_jpilot_ok), cancelled); - g_signal_connect(G_OBJECT(cancel_btn), "clicked", - G_CALLBACK(edit_jpilot_cancel), cancelled); - g_signal_connect(G_OBJECT(file_btn), "clicked", - G_CALLBACK(edit_jpilot_file_select), NULL); - g_signal_connect(G_OBJECT(check_btn), "clicked", - G_CALLBACK(edit_jpilot_file_check), NULL); - - gtk_widget_show_all(vbox); - - jpilotedit.window = window; - jpilotedit.name_entry = name_entry; - jpilotedit.file_entry = file_entry; - jpilotedit.ok_btn = ok_btn; - jpilotedit.cancel_btn = cancel_btn; - jpilotedit.statusbar = statusbar; - jpilotedit.status_cid = gtk_statusbar_get_context_id( GTK_STATUSBAR(statusbar), "Edit JPilot Dialog" ); - for( i = 0; i < JPILOT_NUM_CUSTOM_LABEL; i++ ) { - jpilotedit.custom_check[i] = custom_check[i]; - jpilotedit.custom_label[i] = custom_label[i]; - } -} - -AdapterDSource *addressbook_edit_jpilot( AddressIndex *addrIndex, AdapterDSource *ads ) { - static gboolean cancelled; - gchar *sName; - gchar *sFile; - gchar *sFSFile; - AddressDataSource *ds = NULL; - JPilotFile *jpf = NULL; - gboolean fin; - - if( ! jpilotedit.window ) - addressbook_edit_jpilot_create(&cancelled); - gtk_widget_grab_focus(jpilotedit.ok_btn); - gtk_widget_grab_focus(jpilotedit.name_entry); - gtk_widget_show(jpilotedit.window); - manage_window_set_transient(GTK_WINDOW(jpilotedit.window)); - gtk_window_set_modal(GTK_WINDOW(jpilotedit.window), TRUE); - edit_jpilot_status_show( "" ); - if( ads ) { - ds = ads->dataSource; - jpf = ds->rawDataSource; - if ( jpilot_get_name( jpf ) ) - gtk_entry_set_text(GTK_ENTRY(jpilotedit.name_entry), - jpilot_get_name( jpf ) ); - if (jpf->path) - gtk_entry_set_text(GTK_ENTRY(jpilotedit.file_entry), jpf->path); - gtk_window_set_title( GTK_WINDOW(jpilotedit.window), _("Edit JPilot Entry")); - edit_jpilot_fill_check_box( jpf ); - } - else { - gchar *guessFile = jpilot_find_pilotdb(); - gtk_entry_set_text(GTK_ENTRY(jpilotedit.name_entry), ADDRESSBOOK_GUESS_JPILOT ); - gtk_entry_set_text(GTK_ENTRY(jpilotedit.file_entry), guessFile ); - gtk_window_set_title( GTK_WINDOW(jpilotedit.window), _("Add New JPilot Entry")); - edit_jpilot_fill_check_box_new(); - if( *guessFile != '\0' ) { - edit_jpilot_file_check(); - } - } - - gtk_main(); - gtk_widget_hide(jpilotedit.window); - gtk_window_set_modal(GTK_WINDOW(jpilotedit.window), FALSE); - if (cancelled == TRUE) return NULL; - - fin = FALSE; - sName = gtk_editable_get_chars( GTK_EDITABLE(jpilotedit.name_entry), 0, -1 ); - sFile = gtk_editable_get_chars( GTK_EDITABLE(jpilotedit.file_entry), 0, -1 ); - sFSFile = conv_filename_from_utf8( sFile ); - if( *sName == '\0' ) fin = TRUE; - if( *sFile == '\0' ) fin = TRUE; - if( ! sFSFile || *sFSFile == '\0' ) fin = TRUE; - - if( ! fin ) { - if( ! ads ) { - jpf = jpilot_create(); - ds = addrindex_index_add_datasource( addrIndex, ADDR_IF_JPILOT, jpf ); - ads = addressbook_create_ds_adapter( ds, ADDR_JPILOT, NULL ); - } - addressbook_ads_set_name( ads, sName ); - jpilot_set_name( jpf, sName ); - jpilot_set_file( jpf, sFSFile ); - edit_jpilot_read_check_box( jpf ); - } - g_free( sFSFile ); - g_free( sFile ); - g_free( sName ); - - return ads; -} - -#endif /* USE_JPILOT */ - -/* -* End of Source. -*/ - diff --git a/src/editjpilot.h b/src/editjpilot.h @@ -1,33 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2001-2012 Match Grun and the Claws Mail team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -/* - * Edit JPilot address book data. - */ - -#ifndef __EDITJPILOT_H__ -#define __EDITJPILOT_H__ - -#ifdef USE_JPILOT - -AdapterDSource *addressbook_edit_jpilot( AddressIndex *addrIndex, AdapterDSource *ads ); - -#endif /* USE_JPILOT */ - -#endif /* __EDITJPILOT_H__ */ diff --git a/src/editldap.c b/src/editldap.c @@ -1,1093 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2001-2025 the Claws Mail team and Match Grun - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * Edit LDAP address book data. - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#include "claws-features.h" -#endif - -#ifdef USE_LDAP - -#include "defs.h" - -#include <glib.h> -#include <glib/gi18n.h> -#include <gdk/gdkkeysyms.h> -#include <gtk/gtk.h> - -#include "addressbook.h" -#include "prefs_common.h" -#include "addressitem.h" -#include "mgutils.h" -#include "ldapserver.h" -#include "ldapctrl.h" -#include "ldaputil.h" -#include "editldap_basedn.h" -#include "manage_window.h" -#include "gtkutils.h" -#include "prefs_gtk.h" -#include "passwordstore.h" - -#define PAGE_BASIC 0 -#define PAGE_SEARCH 1 -#define PAGE_EXTENDED 2 - -#define ADDRESSBOOK_GUESS_LDAP_NAME "MyServer" -#define ADDRESSBOOK_GUESS_LDAP_SERVER "localhost" - -#define LDAPEDIT_TABLE_ROWS 6 -#define LDAPEDIT_TABLE_COLS 3 - -static struct _LDAPEdit { - GtkWidget *window; - GtkWidget *notebook; - GtkWidget *ok_btn; - GtkWidget *cancel_btn; - GtkWidget *statusbar; - gint status_cid; - GtkWidget *entry_name; - GtkWidget *entry_server; - GtkWidget *spinbtn_port; - GtkWidget *entry_baseDN; - GtkWidget *spinbtn_timeout; - GtkWidget *entry_bindDN; - GtkWidget *entry_bindPW; - GtkWidget *spinbtn_maxentry; - GtkWidget *entry_criteria; - GtkWidget *spinbtn_queryage; - GtkWidget *check_dynsearch; - GtkWidget *check_matchoption; -#if (defined USE_LDAP_TLS || defined G_OS_WIN32) - GtkWidget *enable_ssl; - GtkWidget *enable_tls; -#endif -} ldapedit; - -/** - * Parse out individual attribute names from criteria string. - * \param criteria Criteria string. - * \ctl Control object. - */ -static gboolean editldap_validate_criteria( gchar *criteria ) { - gchar *ptr; - gchar **splitStr; - gint i; - gboolean errorFlag; - - cm_return_val_if_fail(criteria != NULL, TRUE); - - errorFlag = TRUE; - - /* Replace delimiters with spaces */ - ptr = criteria; - while( *ptr ) { - if( *ptr == ',' || *ptr == ';' || *ptr == '|' ) - *ptr = ' '; - ptr++; - } - debug_print("cleaned criteria list: %s\n", criteria); - - /* Parse string */ - splitStr = g_strsplit( criteria, " ", 0 ); - i = 0; - while( TRUE ) { - if( splitStr[i] ) { - if( *splitStr[i] ) { - errorFlag = FALSE; - break; - } - } - else { - break; - } - i++; - } - g_strfreev( splitStr ); - return errorFlag; -} - -/* -* Edit functions. -*/ -static void edit_ldap_status_show( gchar *msg ) { - if( ldapedit.statusbar != NULL ) { - gtk_statusbar_pop( GTK_STATUSBAR(ldapedit.statusbar), ldapedit.status_cid ); - if( msg ) { - gtk_statusbar_push( GTK_STATUSBAR(ldapedit.statusbar), - ldapedit.status_cid, msg ); - } - } -} - -static gboolean edit_ldap_validate( void ) { - gchar *str; - gboolean errorFlag; - gint page = 0; - - errorFlag = FALSE; - str = gtk_editable_get_chars( - GTK_EDITABLE(ldapedit.entry_name), 0, -1 ); - if( *str == '\0' ) { - page = PAGE_BASIC; - gtk_widget_grab_focus( ldapedit.entry_name ); - edit_ldap_status_show( _( "A Name must be supplied." ) ); - errorFlag = TRUE; - } - g_free( str ); - - if( ! errorFlag ) { - str = gtk_editable_get_chars( - GTK_EDITABLE(ldapedit.entry_server), 0, -1 ); - if( *str == '\0' ) { - page = PAGE_BASIC; - gtk_widget_grab_focus( ldapedit.entry_server ); - edit_ldap_status_show( - _( "A Hostname must be supplied for the server." ) ); - errorFlag = TRUE; - } - g_free( str ); - } - - if( ! errorFlag ) { - str = gtk_editable_get_chars( - GTK_EDITABLE(ldapedit.entry_criteria), 0, -1 ); - if( editldap_validate_criteria( str ) ) { - page = PAGE_SEARCH; - gtk_widget_grab_focus( ldapedit.entry_criteria ); - edit_ldap_status_show( - _( "At least one LDAP search attribute should be supplied." ) ); - errorFlag = TRUE; - } - g_free( str ); - } - - /* Switch to page with error */ - if( errorFlag ) { - gtk_notebook_set_current_page( GTK_NOTEBOOK(ldapedit.notebook), page ); - } - - return errorFlag; -} - -static void edit_ldap_ok( GtkWidget *widget, gboolean *cancelled ) { - if( ! edit_ldap_validate() ) { - *cancelled = FALSE; - gtk_main_quit(); - } -} - -static void edit_ldap_cancel( GtkWidget *widget, gboolean *cancelled ) { - *cancelled = TRUE; - gtk_main_quit(); -} - -static gint edit_ldap_delete_event( GtkWidget *widget, GdkEventAny *event, gboolean *cancelled ) { - *cancelled = TRUE; - gtk_main_quit(); - return TRUE; -} - -static gboolean edit_ldap_key_pressed( GtkWidget *widget, GdkEventKey *event, gboolean *cancelled ) { - if (event && event->keyval == GDK_KEY_Escape) { - *cancelled = TRUE; - gtk_main_quit(); - } - return FALSE; -} - -static void edit_ldap_server_check( void ) { - gchar *sHost, *sBind, *sPass; - gint iPort, iTime; - gchar *sMsg; - gchar *sBaseDN = NULL; - gint iBaseDN = 0; - gboolean flg; - gboolean tls = FALSE, ssl = FALSE; - GList *baseDN = NULL; - - edit_ldap_status_show( "" ); - flg = FALSE; - sHost = gtk_editable_get_chars( GTK_EDITABLE(ldapedit.entry_server), 0, -1 ); - sBind = gtk_editable_get_chars( GTK_EDITABLE(ldapedit.entry_bindDN), 0, -1 ); - sPass = gtk_editable_get_chars( GTK_EDITABLE(ldapedit.entry_bindPW), 0, -1 ); - iPort = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( ldapedit.spinbtn_port ) ); - iTime = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( ldapedit.spinbtn_timeout ) ); -#if (defined USE_LDAP_TLS || defined G_OS_WIN32) - tls = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ldapedit.enable_tls)); - ssl = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ldapedit.enable_ssl)); -#endif - - g_strstrip( sHost ); - g_strstrip( sBind ); - g_strstrip( sPass ); - if( *sHost != '\0' ) { - /* Test connection to server */ - debug_print("ldap server: %s\nport: %d\nssl: %d\ntls: %d\nbindDN: %s\n", sHost, iPort, ssl, tls, sBind); - if( ldaputil_test_connect( sHost, iPort, ssl, tls, iTime ) ) { - /* Attempt to read base DN */ - baseDN = ldaputil_read_basedn(sHost, iPort, sBind, sPass, iTime, ssl, tls); - if( baseDN ) { - GList *node = baseDN; - while( node ) { - ++iBaseDN; - if( ! sBaseDN ) { - sBaseDN = g_strdup( node->data ); - } - node = g_list_next( node ); - } - g_list_free_full( baseDN, g_free ); - baseDN = node = NULL; - flg = TRUE; - } else { - flg = FALSE; - } - } - } - g_free( sHost ); - g_free( sBind ); - g_free( sPass ); - - if( sBaseDN ) { - /* Load search DN */ - debug_print("baseDN: %s\n", sBaseDN); - gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_baseDN), sBaseDN); - g_free( sBaseDN ); - } - - /* Display appropriate message */ - if( flg ) { - sMsg = _( "Connected successfully to server" ); - } - else { - sMsg = _( "Could not connect to server" ); - } - edit_ldap_status_show( sMsg ); -} - -static void edit_ldap_basedn_select( void ) { - gchar *sHost, *sBind, *sPass, *sBase; - gint iPort, iTime, tls = 0, ssl = 0; - gchar *selectDN; - - sHost = gtk_editable_get_chars( GTK_EDITABLE(ldapedit.entry_server), 0, -1 ); - sBase = gtk_editable_get_chars( GTK_EDITABLE(ldapedit.entry_baseDN), 0, -1 ); - sBind = gtk_editable_get_chars( GTK_EDITABLE(ldapedit.entry_bindDN), 0, -1 ); - sPass = gtk_editable_get_chars( GTK_EDITABLE(ldapedit.entry_bindPW), 0, -1 ); - iPort = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( ldapedit.spinbtn_port ) ); - iTime = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( ldapedit.spinbtn_timeout ) ); -#if (defined USE_LDAP_TLS || defined G_OS_WIN32) - tls = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ldapedit.enable_tls)); - ssl = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ldapedit.enable_ssl)); -#endif - - g_strstrip( sHost ); - g_strstrip( sBind ); - g_strstrip( sPass ); - debug_print("ldap server: %s\nport: %d\nssl: %d\ntls: %d\nbindDN: %s\n", sHost, iPort, ssl, tls, sBind); - selectDN = edit_ldap_basedn_selection( sHost, iPort, sBase, iTime, sBind, sPass, ssl, tls ); - if( selectDN ) { - gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_baseDN), selectDN); - g_free( selectDN ); - selectDN = NULL; - } - g_free( sHost ); - g_free( sBase ); - g_free( sBind ); - g_free( sPass ); -} - -static void edit_ldap_search_reset(void) { - gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_criteria), LDAPCTL_DFL_ATTR_LIST); -} - -static void addressbook_edit_ldap_dialog_create( gboolean *cancelled ) { - GtkWidget *window; - GtkWidget *vbox; - GtkWidget *notebook; - GtkWidget *hbbox; - GtkWidget *ok_btn; - GtkWidget *cancel_btn; - GtkWidget *hsbox; - GtkWidget *statusbar; - - debug_print("creating edit_ldap_dialog\n"); - window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "editldap"); - gtk_container_set_border_width(GTK_CONTAINER(window), 0); - gtk_window_set_title(GTK_WINDOW(window), _("Edit LDAP Server")); - gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); - gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DIALOG); - g_signal_connect(G_OBJECT(window), "delete_event", - G_CALLBACK(edit_ldap_delete_event), - cancelled); - g_signal_connect(G_OBJECT(window), "key_press_event", - G_CALLBACK(edit_ldap_key_pressed), - cancelled); - - vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6 ); - gtk_widget_show( vbox ); - gtk_container_add( GTK_CONTAINER( window ), vbox ); - - /* Notebook */ - notebook = gtk_notebook_new(); - gtk_widget_show( notebook ); - gtk_box_pack_start( GTK_BOX( vbox ), notebook, TRUE, TRUE, 0 ); - gtk_container_set_border_width( GTK_CONTAINER( notebook ), 6 ); - - /* Status line */ - hsbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); - gtk_box_pack_end(GTK_BOX(vbox), hsbox, FALSE, FALSE, BORDER_WIDTH); - statusbar = gtk_statusbar_new(); - gtk_box_pack_start(GTK_BOX(hsbox), statusbar, TRUE, TRUE, BORDER_WIDTH); - - /* Button panel */ - gtkut_stock_button_set_create(&hbbox, &cancel_btn, NULL, _("_Cancel"), - &ok_btn, NULL, _("_OK"), - NULL, NULL, NULL); - gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0); - gtk_widget_grab_default(ok_btn); - - g_signal_connect(G_OBJECT(ok_btn), "clicked", - G_CALLBACK(edit_ldap_ok), cancelled); - g_signal_connect(G_OBJECT(cancel_btn), "clicked", - G_CALLBACK(edit_ldap_cancel), cancelled); - - gtk_widget_show_all(vbox); - - ldapedit.window = window; - ldapedit.notebook = notebook; - ldapedit.ok_btn = ok_btn; - ldapedit.cancel_btn = cancel_btn; - ldapedit.statusbar = statusbar; - ldapedit.status_cid = - gtk_statusbar_get_context_id( - GTK_STATUSBAR(statusbar), "Edit LDAP Server Dialog" ); -} - -static void editldap_update_port (GtkToggleButton *ssl_btn, gpointer data) { - gboolean val = gtk_toggle_button_get_active(ssl_btn); - gtk_spin_button_set_value( - GTK_SPIN_BUTTON( ldapedit.spinbtn_port ), - val ? LDAPCTL_DFL_SSL_PORT:LDAPCTL_DFL_PORT ); - debug_print("Setting port: %d\n", val ? LDAPCTL_DFL_SSL_PORT:LDAPCTL_DFL_PORT); -} - -static void addressbook_edit_ldap_page_basic( gint pageNum, gchar *pageLbl ) { - GtkWidget *vbox; - GtkWidget *table; - GtkWidget *label; - GtkWidget *entry_name; - GtkWidget *entry_server; - GtkWidget *hbox_spin; - GtkAdjustment *spinbtn_port_adj; - GtkWidget *spinbtn_port; -#if (defined USE_LDAP_TLS || defined G_OS_WIN32) - GtkWidget *enable_ssl_checkbtn, *enable_tls_checkbtn; -#endif - GtkWidget *entry_baseDN; - GtkWidget *check_btn; - GtkWidget *lookdn_btn; - - vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8 ); - gtk_widget_show( vbox ); - gtk_container_add( GTK_CONTAINER( ldapedit.notebook ), vbox ); - - label = gtk_label_new( pageLbl ); - gtk_widget_show( label ); - gtk_notebook_set_tab_label( - GTK_NOTEBOOK( ldapedit.notebook ), - gtk_notebook_get_nth_page( GTK_NOTEBOOK( ldapedit.notebook ), pageNum ), label ); - - table = gtk_grid_new(); - gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); - gtk_container_set_border_width( GTK_CONTAINER(table), 8 ); - gtk_grid_set_row_spacing(GTK_GRID(table), 8); - gtk_grid_set_column_spacing(GTK_GRID(table), 8); - - /* First row */ - label = gtk_label_new(_("Name")); - gtk_label_set_xalign(GTK_LABEL(label), 0.0); - gtk_grid_attach(GTK_GRID(table), label, 0, 0, 1, 1); - - entry_name = gtk_entry_new(); - gtk_grid_attach(GTK_GRID(table), entry_name, 1, 0, 1, 1); - gtk_widget_set_hexpand(entry_name, TRUE); - gtk_widget_set_halign(entry_name, GTK_ALIGN_FILL); - - CLAWS_SET_TIP(entry_name, _( - "A name that you wish to call the server." )); - - /* Next row */ - label = gtk_label_new(_("Hostname")); - gtk_label_set_xalign(GTK_LABEL(label), 0.0); - gtk_grid_attach(GTK_GRID(table), label, 0, 1, 1, 1); - - entry_server = gtk_entry_new(); - gtk_grid_attach(GTK_GRID(table), entry_server, 1, 1, 1, 1); - gtk_widget_set_hexpand(entry_server, TRUE); - gtk_widget_set_halign(entry_server, GTK_ALIGN_FILL); - - CLAWS_SET_TIP(entry_server, _( - "This is the hostname of the server. For example, " \ - "\"ldap.example.org\" may be appropriate for the " \ - "\"example.org\" organization. An IP address may also be " \ - "used. You may specify \"localhost\" if running an LDAP " \ - "server on the same computer as Claws Mail." )); - - /* Next row */ - label = gtk_label_new(_("Port")); - gtk_label_set_xalign(GTK_LABEL(label), 0.0); - gtk_grid_attach(GTK_GRID(table), entry_server, 0, 2, 1, 1); - - hbox_spin = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8); - spinbtn_port_adj = GTK_ADJUSTMENT(gtk_adjustment_new (389, 1, 65535, 1, 1000, 0)); - spinbtn_port = gtk_spin_button_new(GTK_ADJUSTMENT (spinbtn_port_adj), 1, 0); - gtk_box_pack_start (GTK_BOX (hbox_spin), spinbtn_port, TRUE, FALSE, 0); - gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_port), TRUE); - -#if (defined USE_LDAP_TLS || defined G_OS_WIN32) - enable_tls_checkbtn = gtk_check_button_new_with_label(_("STARTTLS")); - enable_ssl_checkbtn = gtk_check_button_new_with_label(_("TLS")); - SET_TOGGLE_SENSITIVITY_REVERSE(enable_tls_checkbtn, enable_ssl_checkbtn); - SET_TOGGLE_SENSITIVITY_REVERSE(enable_ssl_checkbtn, enable_tls_checkbtn); - CLAWS_SET_TIP(enable_tls_checkbtn, _( - "Enable secure connection to the LDAP server via STARTTLS. " - "Connection starts unencrypted and is secured by STARTTLS command. " - "If connection fails, be sure to check the correct " - "configuration in ldap.conf (TLS_CACERTDIR and TLS_REQCERT fields)." )); - CLAWS_SET_TIP(enable_ssl_checkbtn, _( - "Enable secure connection to the LDAP server via TLS. " - "If connection fails, be sure to check the correct " - "configuration in ldap.conf (TLS_CACERTDIR and TLS_REQCERT fields)." )); - - gtk_box_pack_start (GTK_BOX (hbox_spin), enable_tls_checkbtn, TRUE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (hbox_spin), enable_ssl_checkbtn, TRUE, FALSE, 0); -#endif - gtk_grid_attach(GTK_GRID(table), hbox_spin, 1, 2, 1, 1); - - CLAWS_SET_TIP(spinbtn_port, _( - "The port number that the server listens on. Port 389 is " \ - "the default." )); - - check_btn = gtk_button_new_with_label( _(" Check Server ")); - gtk_grid_attach(GTK_GRID(table), hbox_spin, 2, 2, 1, 1); - - CLAWS_SET_TIP(check_btn, _( - "Press this button to test the connection to the server." )); - - /* Next row */ - label = gtk_label_new(_("Search Base")); - gtk_label_set_xalign(GTK_LABEL(label), 0.0); - gtk_grid_attach(GTK_GRID(table), label, 0, 3, 1, 1); - - entry_baseDN = gtk_entry_new(); - gtk_grid_attach(GTK_GRID(table), entry_baseDN, 1, 3, 1, 1); - gtk_widget_set_hexpand(entry_baseDN, TRUE); - gtk_widget_set_halign(entry_baseDN, GTK_ALIGN_FILL); - - CLAWS_SET_TIP(entry_baseDN, _( - "This specifies the name of the directory to be searched " \ - "on the server. Examples include:\n" \ - " dc=claws-mail,dc=org\n" \ - " ou=people,dc=domainname,dc=com\n" \ - " o=Organization Name,c=Country\n" - )); - - lookdn_btn = gtkut_get_browse_file_btn(_("_Browse")); - gtk_grid_attach(GTK_GRID(table), lookdn_btn, 2, 3, 1, 1); - - CLAWS_SET_TIP(lookdn_btn, _( - "Press this button to lookup the name of available " \ - "directory names on the server." )); - - /* Signal handlers */ - g_signal_connect(G_OBJECT(check_btn), "clicked", - G_CALLBACK(edit_ldap_server_check), NULL); - g_signal_connect(G_OBJECT(lookdn_btn), "clicked", - G_CALLBACK(edit_ldap_basedn_select), NULL); - - /* Done */ - gtk_widget_show_all(vbox); - - ldapedit.entry_name = entry_name; - ldapedit.entry_server = entry_server; - ldapedit.spinbtn_port = spinbtn_port; - ldapedit.entry_baseDN = entry_baseDN; -#if (defined USE_LDAP_TLS || defined G_OS_WIN32) - ldapedit.enable_ssl = enable_ssl_checkbtn; - ldapedit.enable_tls = enable_tls_checkbtn; - - g_signal_connect(G_OBJECT(enable_ssl_checkbtn), "toggled", \ - G_CALLBACK(editldap_update_port), NULL); -#endif -} - -static void addressbook_edit_ldap_page_search( gint pageNum, gchar *pageLbl ) { - GtkWidget *vbox; - GtkWidget *table; - GtkWidget *label; - GtkWidget *entry_criteria; - GtkWidget *hbox_spin; - GtkAdjustment *spinbtn_queryage_adj; - GtkWidget *spinbtn_queryage; - GtkWidget *check_dynsearch; - GtkWidget *check_matchoption; - GtkWidget *reset_btn; - - vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8 ); - gtk_widget_show( vbox ); - gtk_container_add( GTK_CONTAINER( ldapedit.notebook ), vbox ); - - label = gtk_label_new( pageLbl ); - gtk_widget_show( label ); - gtk_notebook_set_tab_label( - GTK_NOTEBOOK( ldapedit.notebook ), - gtk_notebook_get_nth_page( GTK_NOTEBOOK( ldapedit.notebook ), pageNum ), label ); - - table = gtk_grid_new(); - gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); - gtk_container_set_border_width( GTK_CONTAINER(table), 8 ); - gtk_grid_set_row_spacing(GTK_GRID(table), 8); - gtk_grid_set_column_spacing(GTK_GRID(table), 8); - - /* First row */ - label = gtk_label_new(_("Search Attributes")); - gtk_label_set_xalign(GTK_LABEL(label), 0.0); - gtk_grid_attach(GTK_GRID(table), label, 0, 0, 1, 1); - - entry_criteria = gtk_entry_new(); - gtk_grid_attach(GTK_GRID(table), entry_criteria, 1, 0, 1, 1); - gtk_widget_set_hexpand(entry_criteria, TRUE); - gtk_widget_set_halign(entry_criteria, GTK_ALIGN_FILL); - - CLAWS_SET_TIP(entry_criteria, _( - "A list of LDAP attribute names that should be searched " \ - "when attempting to find a name or address." )); - - reset_btn = gtk_button_new_with_label( _(" Defaults ")); - gtk_grid_attach(GTK_GRID(table), reset_btn, 2, 0, 1, 1); - - CLAWS_SET_TIP(reset_btn, _( - "This resets the attribute names to a default value " \ - "that should find most names and addresses during a " \ - "name or address search process." )); - - /* Next row */ - label = gtk_label_new(_("Max Query Age (secs)")); - gtk_label_set_xalign(GTK_LABEL(label), 0.0); - gtk_grid_attach(GTK_GRID(table), label, 0, 1, 1, 1); - - hbox_spin = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8); - spinbtn_queryage_adj = GTK_ADJUSTMENT(gtk_adjustment_new( - LDAPCTL_DFL_QUERY_AGE, 1, LDAPCTL_MAX_QUERY_AGE, 10, 1000, 0 )); - spinbtn_queryage = gtk_spin_button_new(GTK_ADJUSTMENT (spinbtn_queryage_adj), 1, 0); - gtk_box_pack_start (GTK_BOX (hbox_spin), spinbtn_queryage, FALSE, FALSE, 0); - gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_queryage), TRUE); - gtk_grid_attach(GTK_GRID(table), hbox_spin, 1, 1, 1, 1); - - CLAWS_SET_TIP(spinbtn_queryage, _( - "This defines the maximum period of time (in seconds) that " \ - "an address search result is valid for address completion " \ - "purposes. Search results are stored in a cache until this " \ - "period of time has passed and then retired. This will " \ - "improve the response time when attempting to search for " \ - "the same name or address on subsequent address completion " \ - "requests. The cache will be searched in preference to " \ - "performing a new server search request. The default value " \ - "of 600 seconds (10 minutes), should be sufficient for most " \ - "servers. A larger value will reduce the search time for " \ - "subsequent searches. This is useful for servers that have " \ - "slow response times at the expense of more memory to cache " \ - "results." )); - - /* Next row */ - check_dynsearch = gtk_check_button_new_with_label( - _("Include server in dynamic search") ); - gtk_grid_attach(GTK_GRID(table), check_dynsearch, 1, 2, 1, 1); - - CLAWS_SET_TIP(check_dynsearch, _( - "Check this option to include this server for dynamic " \ - "searches when using address completion." )); - - /* Next row */ - check_matchoption = gtk_check_button_new_with_label( - _("Match names 'containing' search term") ); - gtk_grid_attach(GTK_GRID(table), check_matchoption, 1, 3, 1, 1); - - CLAWS_SET_TIP(check_matchoption, _( - "Searches for names and addresses can be performed either " \ - "using \"begins-with\" or \"contains\" search term. Check " \ - "this option to perform a \"contains\" search; this type of " \ - "search usually takes longer to complete. Note that for " \ - "performance reasons, address completion uses " \ - "\"begins-with\" for all searches against other address " \ - "interfaces." \ - )); - - /* Signal handlers */ - g_signal_connect(G_OBJECT(reset_btn), "clicked", - G_CALLBACK(edit_ldap_search_reset), NULL); - - /* Done */ - gtk_widget_show_all(vbox); - - ldapedit.entry_criteria = entry_criteria; - ldapedit.spinbtn_queryage = spinbtn_queryage; - ldapedit.check_dynsearch = check_dynsearch; - ldapedit.check_matchoption = check_matchoption; -} - -static void showpwd_toggled(GtkEntry *entry, gpointer user_data) -{ - gboolean visible = gtk_entry_get_visibility(GTK_ENTRY(entry)); - - if (visible) { - gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE); - gtk_entry_set_icon_from_icon_name(GTK_ENTRY(entry), - GTK_ENTRY_ICON_SECONDARY, - "view-reveal-symbolic"); - gtk_entry_set_icon_tooltip_text(GTK_ENTRY(entry), - GTK_ENTRY_ICON_SECONDARY, - _("Show password")); - } else { - gtk_entry_set_visibility(GTK_ENTRY(entry), TRUE); - gtk_entry_set_icon_from_icon_name(GTK_ENTRY(entry), - GTK_ENTRY_ICON_SECONDARY, - "view-conceal-symbolic"); - gtk_entry_set_icon_tooltip_text(GTK_ENTRY(entry), - GTK_ENTRY_ICON_SECONDARY, - _("Hide password")); - } -} - -static void addressbook_edit_ldap_page_extended( gint pageNum, gchar *pageLbl ) { - GtkWidget *vbox; - GtkWidget *table; - GtkWidget *label; - GtkWidget *entry_bindDN; - GtkWidget *entry_bindPW; - GtkWidget *hbox_spin; - GtkAdjustment *spinbtn_timeout_adj; - GtkWidget *spinbtn_timeout; - GtkAdjustment *spinbtn_maxentry_adj; - GtkWidget *spinbtn_maxentry; - - vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8 ); - gtk_widget_show( vbox ); - gtk_container_add( GTK_CONTAINER( ldapedit.notebook ), vbox ); - - label = gtk_label_new( pageLbl ); - gtk_widget_show( label ); - gtk_notebook_set_tab_label( - GTK_NOTEBOOK( ldapedit.notebook ), - gtk_notebook_get_nth_page( GTK_NOTEBOOK( ldapedit.notebook ), pageNum ), label ); - - table = gtk_grid_new(); - gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); - gtk_container_set_border_width( GTK_CONTAINER(table), 8 ); - gtk_grid_set_row_spacing(GTK_GRID(table), 8); - gtk_grid_set_column_spacing(GTK_GRID(table), 8); - - /* Next row */ - label = gtk_label_new(_("Bind DN")); - gtk_label_set_xalign(GTK_LABEL(label), 0.0); - gtk_grid_attach(GTK_GRID(table), label, 0, 0, 1, 1); - - entry_bindDN = gtk_entry_new(); - gtk_grid_attach(GTK_GRID(table), entry_bindDN, 1, 0, 1, 1); - gtk_widget_set_hexpand(entry_bindDN, TRUE); - gtk_widget_set_halign(entry_bindDN, GTK_ALIGN_FILL); - - CLAWS_SET_TIP(entry_bindDN, _( - "The LDAP user account name to be used to connect to the server. " \ - "This is usually only used for protected servers. This name " \ - "is typically formatted as: \"cn=user,dc=claws-mail,dc=org\". " \ - "This is usually left empty when performing a search." )); - - /* Next row */ - label = gtk_label_new(_("Bind Password")); - gtk_label_set_xalign(GTK_LABEL(label), 0.0); - gtk_grid_attach(GTK_GRID(table), entry_bindDN, 0, 1, 1, 1); - - entry_bindPW = gtk_entry_new(); - gtk_entry_set_visibility(GTK_ENTRY(entry_bindPW), FALSE); - gtk_entry_set_icon_from_icon_name(GTK_ENTRY(entry_bindPW), - GTK_ENTRY_ICON_SECONDARY, - "view-reveal-symbolic"); - gtk_entry_set_icon_activatable(GTK_ENTRY(entry_bindPW), - GTK_ENTRY_ICON_SECONDARY, TRUE); - gtk_entry_set_icon_tooltip_text(GTK_ENTRY(entry_bindPW), - GTK_ENTRY_ICON_SECONDARY, _("Show password")); - g_signal_connect(entry_bindPW, "icon-press", - G_CALLBACK(showpwd_toggled), NULL); - - gtk_grid_attach(GTK_GRID(table), entry_bindPW, 1, 1, 1, 1); - gtk_widget_set_hexpand(entry_bindPW, TRUE); - gtk_widget_set_halign(entry_bindPW, GTK_ALIGN_FILL); - - CLAWS_SET_TIP(entry_bindPW, _( - "The password to be used when connecting as the \"Bind DN\" " \ - "user." )); - - /* Next row */ - label = gtk_label_new(_("Timeout (secs)")); - gtk_label_set_xalign(GTK_LABEL(label), 0.0); - gtk_grid_attach(GTK_GRID(table), label, 0, 2, 1, 1); - - hbox_spin = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8); - spinbtn_timeout_adj = GTK_ADJUSTMENT(gtk_adjustment_new (0, 0, 300, 1, 10, 0)); - spinbtn_timeout = gtk_spin_button_new(GTK_ADJUSTMENT (spinbtn_timeout_adj), 1, 0); - gtk_box_pack_start (GTK_BOX (hbox_spin), spinbtn_timeout, FALSE, FALSE, 0); - gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_timeout), TRUE); - gtk_grid_attach(GTK_GRID(table), hbox_spin, 1, 2, 1, 1); - - CLAWS_SET_TIP(spinbtn_timeout, _( - "The timeout period in seconds." )); - - /* Next row */ - label = gtk_label_new(_("Maximum Entries")); - gtk_label_set_xalign(GTK_LABEL(label), 0.0); - gtk_grid_attach(GTK_GRID(table), label, 0, 3, 1, 1); - - hbox_spin = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8); - spinbtn_maxentry_adj = GTK_ADJUSTMENT(gtk_adjustment_new (0, 0, 500, 1, 10, 0)); - spinbtn_maxentry = gtk_spin_button_new(GTK_ADJUSTMENT (spinbtn_maxentry_adj), 1, 0); - gtk_box_pack_start (GTK_BOX (hbox_spin), spinbtn_maxentry, FALSE, FALSE, 0); - gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_maxentry), TRUE); - gtk_grid_attach(GTK_GRID(table), hbox_spin, 1, 3, 1, 1); - - CLAWS_SET_TIP(spinbtn_maxentry, _( - "The maximum number of entries that should be returned " \ - "in the search result." )); - - /* Done */ - gtk_widget_show_all(vbox); - - ldapedit.entry_bindDN = entry_bindDN; - ldapedit.entry_bindPW = entry_bindPW; - ldapedit.spinbtn_timeout = spinbtn_timeout; - ldapedit.spinbtn_maxentry = spinbtn_maxentry; -} - -static void addressbook_edit_ldap_create( gboolean *cancelled ) { - gint page = 0; - addressbook_edit_ldap_dialog_create( cancelled ); - addressbook_edit_ldap_page_basic( page++, _( "Basic" ) ); - addressbook_edit_ldap_page_search( page++, _( "Search" ) ); - addressbook_edit_ldap_page_extended( page++, _( "Extended" ) ); - gtk_widget_show_all( ldapedit.window ); -} - -/** - * Format criteria list for display. - * \param ctl Control object. - * \return Formatted string, or <i>NULL</i> if no attributes found. - */ -static gchar *editldap_build_criteria_list( const LdapControl *ctl ) { - gchar *str = NULL; - gchar *tmp = NULL; - GList *node; - - node = ldapctl_get_criteria_list( ctl ); - while( node ) { - gchar *attr = node->data; - if( str ) { - tmp = g_strdup_printf( "%s, %s", str, attr ); - g_free( str ); - str = tmp; - tmp = NULL; - } - else { - str = g_strdup( attr ); - } - node = g_list_next( node ); - } - - return str; -} - -/** - * Parse out individual attribute names from criteria string. - * \param criteria Criteria string. - * \ctl Control object. - */ -static void editldap_parse_criteria( gchar *criteria, LdapControl *ctl ) { - gchar *ptr; - gchar **splitStr; - gint i; - - /* Replace delimiters with spaces */ - ptr = criteria; - while( *ptr ) { - if( *ptr == ',' || *ptr == ';' || *ptr == '|' ) - *ptr = ' '; - ptr++; - } - - /* Parse string */ - ldapctl_criteria_list_clear( ctl ); - splitStr = g_strsplit( criteria, " ", 0 ); - i = 0; - while( TRUE ) { - if( splitStr[i] ) { - if( *splitStr[i] ) { - ldapctl_criteria_list_add( ctl, splitStr[i] ); - } - } - else { - break; - } - i++; - } - g_strfreev( splitStr ); -} - -/** - * Clear entry fields to reasonable defaults (for a new server entry). - */ -static void edit_ldap_clear_fields(void) { - gtk_entry_set_text( - GTK_ENTRY(ldapedit.entry_name), ADDRESSBOOK_GUESS_LDAP_NAME ); - gtk_entry_set_text( - GTK_ENTRY(ldapedit.entry_server), ADDRESSBOOK_GUESS_LDAP_SERVER ); - gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_baseDN), ""); - gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_bindDN), ""); - gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_bindPW), ""); - gtk_spin_button_set_value( - GTK_SPIN_BUTTON( ldapedit.spinbtn_port ), LDAPCTL_DFL_PORT ); - gtk_spin_button_set_value( - GTK_SPIN_BUTTON( ldapedit.spinbtn_timeout ), LDAPCTL_DFL_TIMEOUT ); - gtk_spin_button_set_value( - GTK_SPIN_BUTTON( ldapedit.spinbtn_maxentry ), LDAPCTL_DFL_TIMEOUT ); - gtk_entry_set_text( - GTK_ENTRY(ldapedit.entry_criteria), LDAPCTL_DFL_ATTR_LIST); - gtk_spin_button_set_value( - GTK_SPIN_BUTTON(ldapedit.spinbtn_queryage), LDAPCTL_DFL_QUERY_AGE ); - gtk_toggle_button_set_active( - GTK_TOGGLE_BUTTON( ldapedit.check_dynsearch), TRUE ); - gtk_toggle_button_set_active( - GTK_TOGGLE_BUTTON( ldapedit.check_matchoption), FALSE ); -#if (defined USE_LDAP_TLS || defined G_OS_WIN32) - gtk_toggle_button_set_active( - GTK_TOGGLE_BUTTON( ldapedit.enable_ssl), FALSE ); - gtk_toggle_button_set_active( - GTK_TOGGLE_BUTTON( ldapedit.enable_tls), FALSE ); -#endif -} - -/** - * Load entry fields from server control data. - * \param server Server object. - */ -static void edit_ldap_set_fields( LdapServer *server ) { - LdapControl *ctl; - gchar *crit, *pwd; - - if( ldapsvr_get_name( server ) ) - gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_name), - ldapsvr_get_name( server ) ); - - ctl = server->control; - if( ctl->hostName ) - gtk_entry_set_text( - GTK_ENTRY(ldapedit.entry_server), ctl->hostName); - if( ctl->baseDN ) - gtk_entry_set_text( - GTK_ENTRY(ldapedit.entry_baseDN), ctl->baseDN ); - if( ctl->bindDN ) - gtk_entry_set_text( - GTK_ENTRY(ldapedit.entry_bindDN), ctl->bindDN ); - - pwd = passwd_store_get(PWS_CORE, "LDAP", ctl->hostName); - gtk_entry_set_text( GTK_ENTRY(ldapedit.entry_bindPW), - (pwd ? pwd : "")); - if (pwd != NULL) { - memset(pwd, 0, strlen(pwd)); - g_free(pwd); - } - - gtk_spin_button_set_value( - GTK_SPIN_BUTTON(ldapedit.spinbtn_timeout), ctl->timeOut ); - gtk_spin_button_set_value( - GTK_SPIN_BUTTON(ldapedit.spinbtn_maxentry), ctl->maxEntries ); -#if (defined USE_LDAP_TLS || defined G_OS_WIN32) - gtk_toggle_button_set_active( - GTK_TOGGLE_BUTTON(ldapedit.enable_tls), ctl->enableTLS ); - gtk_toggle_button_set_active( - GTK_TOGGLE_BUTTON(ldapedit.enable_ssl), ctl->enableSSL ); -#endif - gtk_spin_button_set_value( - GTK_SPIN_BUTTON(ldapedit.spinbtn_port), ctl->port ); - /* Format criteria */ - crit = editldap_build_criteria_list( ctl ); - if( crit ) { - gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_criteria), crit ); - g_free( crit ); - } - else { - gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_criteria), "" ); - } - gtk_spin_button_set_value( - GTK_SPIN_BUTTON(ldapedit.spinbtn_queryage), ctl->maxQueryAge ); - gtk_toggle_button_set_active( - GTK_TOGGLE_BUTTON( ldapedit.check_dynsearch), server->searchFlag ); - gtk_toggle_button_set_active( - GTK_TOGGLE_BUTTON( ldapedit.check_matchoption), - ( ctl->matchingOption == LDAPCTL_MATCH_CONTAINS ) ); -} - -/** - * Edit LDAP server datasource that appears addressbook. - * \param addrIndex Address index object. - * \param ads Data source adapter. - * \return Update data source adapter, or <code>NULL</code> if user cancelled - * edit with dialog. - */ -AdapterDSource *addressbook_edit_ldap( - AddressIndex *addrIndex, AdapterDSource *ads ) -{ - static gboolean cancelled; - gchar *sName, *sHost, *sBase, *sBind, *sPass, *sCrit; - gint iPort, iMaxE, iTime, iAge; - gboolean bSrch, bMatch; - AddressDataSource *ds = NULL; - LdapServer *server = NULL; - LdapControl *ctl = NULL; - gboolean fin, ssl = FALSE, tls = FALSE; - - if (!ldapedit.window) - addressbook_edit_ldap_create(&cancelled); - gtk_notebook_set_current_page( GTK_NOTEBOOK(ldapedit.notebook), PAGE_BASIC ); - gtk_widget_grab_focus(ldapedit.ok_btn); - gtk_widget_grab_focus(ldapedit.entry_name); - gtk_widget_show(ldapedit.window); - manage_window_set_transient(GTK_WINDOW(ldapedit.window)); - gtk_window_set_modal(GTK_WINDOW(ldapedit.window), TRUE); - - edit_ldap_status_show( "" ); - if( ads ) { - ds = ads->dataSource; - server = ds->rawDataSource; - edit_ldap_set_fields( server ); - gtk_window_set_title( - GTK_WINDOW(ldapedit.window), _("Edit LDAP Server")); - } - else { - edit_ldap_clear_fields(); - gtk_window_set_title( - GTK_WINDOW(ldapedit.window), _("Add New LDAP Server")); - } - - gtk_main(); - gtk_widget_hide(ldapedit.window); - gtk_window_set_modal(GTK_WINDOW(ldapedit.window), FALSE); - if (cancelled == TRUE) return NULL; - - sName = gtk_editable_get_chars( - GTK_EDITABLE(ldapedit.entry_name), 0, -1 ); - sHost = gtk_editable_get_chars( - GTK_EDITABLE(ldapedit.entry_server), 0, -1 ); - sBase = gtk_editable_get_chars( - GTK_EDITABLE(ldapedit.entry_baseDN), 0, -1 ); - sCrit = gtk_editable_get_chars( - GTK_EDITABLE(ldapedit.entry_criteria), 0, -1 ); - sBind = gtk_editable_get_chars( - GTK_EDITABLE(ldapedit.entry_bindDN), 0, -1 ); - sPass = gtk_editable_get_chars( - GTK_EDITABLE(ldapedit.entry_bindPW), 0, -1 ); - iPort = gtk_spin_button_get_value_as_int( - GTK_SPIN_BUTTON( ldapedit.spinbtn_port ) ); - iTime = gtk_spin_button_get_value_as_int( - GTK_SPIN_BUTTON( ldapedit.spinbtn_timeout ) ); - iMaxE = gtk_spin_button_get_value_as_int( - GTK_SPIN_BUTTON( ldapedit.spinbtn_maxentry ) ); - iAge = gtk_spin_button_get_value_as_int( - GTK_SPIN_BUTTON( ldapedit.spinbtn_queryage ) ); - bSrch = gtk_toggle_button_get_active( - GTK_TOGGLE_BUTTON( ldapedit.check_dynsearch ) ); - bMatch = gtk_toggle_button_get_active( - GTK_TOGGLE_BUTTON( ldapedit.check_matchoption ) ); -#if (defined USE_LDAP_TLS || defined G_OS_WIN32) - ssl = gtk_toggle_button_get_active( - GTK_TOGGLE_BUTTON( ldapedit.enable_ssl ) ); - tls = gtk_toggle_button_get_active( - GTK_TOGGLE_BUTTON( ldapedit.enable_tls ) ); -#endif - debug_print("saving server config:\nname: %s\nhost: %s\nbase: %s\ncriteria: %s\nbind: %s\nport: %d\ntime: %d\nmax_entries: %d\ntimeout: %d\ndynamic: %d\ncheck_match: %d\n", - sName, sHost, sBase, sCrit, sBind, iPort, iTime, iMaxE, iAge, bSrch, bMatch); - fin = FALSE; - if( *sName == '\0' ) fin = TRUE; - if( *sHost == '\0' ) fin = TRUE; - - if( ! fin ) { - /* Save changes */ - if( ! ads ) { - /* New server */ - server = ldapsvr_create(); - ds = addrindex_index_add_datasource( - addrIndex, ADDR_IF_LDAP, server ); - ads = addressbook_create_ds_adapter( - ds, ADDR_LDAP, NULL ); - } - ctl = server->control; - addressbook_ads_set_name( ads, sName ); - ldapsvr_set_name( server, sName ); - ldapsvr_set_search_flag( server, bSrch ); - ldapctl_set_host( ctl, sHost ); - ldapctl_set_base_dn( ctl, sBase ); - ldapctl_set_bind_dn( ctl, sBind ); - ldapctl_set_port( ctl, iPort ); - ldapctl_set_max_entries( ctl, iMaxE ); - ldapctl_set_timeout( ctl, iTime ); - ldapctl_set_max_query_age( ctl, iAge ); - ldapctl_set_tls( ctl, tls ); - ldapctl_set_ssl( ctl, ssl ); - ldapctl_set_matching_option( - ctl, bMatch ? - LDAPCTL_MATCH_CONTAINS : LDAPCTL_MATCH_BEGINWITH ); - - addrindex_save_data(addrIndex); - - passwd_store_set(PWS_CORE, "LDAP", sHost, sPass, FALSE); - passwd_store_write_config(); - - /* Save attributes */ - editldap_parse_criteria( sCrit, ctl ); - - } - g_free( sName ); - g_free( sHost ); - g_free( sBase ); - g_free( sBind ); - g_free( sCrit ); - - if (sPass != NULL && strlen(sPass) > 0) - memset(sPass, 0, strlen(sPass)); - g_free( sPass ); - - return ads; -} - -#endif /* USE_LDAP */ - -/* -* End of Source. -*/ diff --git a/src/editldap.h b/src/editldap.h @@ -1,29 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2001-2012 Match Grun and the Claws Mail team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -#ifndef __EDITLDAP_H__ -#define __EDITLDAP_H__ - -#ifdef USE_LDAP - -AdapterDSource *addressbook_edit_ldap( AddressIndex *addrIndex, AdapterDSource *ads ); - -#endif /* USE_LDAP */ - -#endif /* __EDITLDAP_H__ */ diff --git a/src/editldap_basedn.c b/src/editldap_basedn.c @@ -1,370 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2001-2022 the Claws Mail team and Match Grun - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * LDAP Base DN selection dialog. - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#include "claws-features.h" -#endif - -#ifdef USE_LDAP - -#include "defs.h" - -#include <glib.h> -#include <glib/gi18n.h> -#include <gdk/gdkkeysyms.h> -#include <gtk/gtk.h> - -#include "prefs_common.h" -#include "ldaputil.h" -#include "mgutils.h" -#include "gtkutils.h" -#include "manage_window.h" - -static struct _LDAPEdit_basedn { - GtkWidget *window; - GtkWidget *host_label; - GtkWidget *port_label; - GtkWidget *basedn_entry; - GtkWidget *basedn_list; - GtkWidget *ok_btn; - GtkWidget *cancel_btn; - GtkWidget *statusbar; - gint status_cid; -} ldapedit_basedn; - -static gboolean ldapedit_basedn_cancelled; -static gboolean ldapedit_basedn_bad_server; - -/* -* Edit functions. -*/ -static void edit_ldap_bdn_status_show( gchar *msg ) { - if( ldapedit_basedn.statusbar != NULL ) { - gtk_statusbar_pop( GTK_STATUSBAR(ldapedit_basedn.statusbar), ldapedit_basedn.status_cid ); - if( msg ) { - gtk_statusbar_push( GTK_STATUSBAR(ldapedit_basedn.statusbar), ldapedit_basedn.status_cid, msg ); - } - } -} - -static gint edit_ldap_bdn_delete_event( GtkWidget *widget, GdkEventAny *event, gboolean *cancelled ) { - ldapedit_basedn_cancelled = TRUE; - gtk_main_quit(); - return TRUE; -} - -static gboolean edit_ldap_bdn_key_pressed( GtkWidget *widget, GdkEventKey *event, gboolean *cancelled ) { - if (event && event->keyval == GDK_KEY_Escape) { - ldapedit_basedn_cancelled = TRUE; - gtk_main_quit(); - } - return FALSE; -} - -static void edit_ldap_bdn_ok( GtkWidget *widget, gboolean *cancelled ) { - ldapedit_basedn_cancelled = FALSE; - gtk_main_quit(); -} - -static void edit_ldap_bdn_cancel( GtkWidget *widget, gboolean *cancelled ) { - ldapedit_basedn_cancelled = TRUE; - gtk_main_quit(); -} - -static void set_selected() -{ - GtkWidget *entry = ldapedit_basedn.basedn_entry; - GtkWidget *view = ldapedit_basedn.basedn_list; - gchar *text; - - if (entry == NULL || view == NULL) - return; - - text = gtkut_tree_view_get_selected_pointer( - GTK_TREE_VIEW(view), 0, NULL, NULL, NULL); - - if (text == NULL) - return; - - gtk_entry_set_text(GTK_ENTRY(entry), text); - g_free(text); -} - -static void basedn_list_cursor_changed(GtkTreeView *view, - gpointer user_data) -{ - set_selected(); -} - -static void basedn_list_row_activated(GtkTreeView *view, - GtkTreePath *path, - GtkTreeViewColumn *column, - gpointer user_data) -{ - set_selected(); - edit_ldap_bdn_ok(NULL, NULL); -} - -static void edit_ldap_bdn_create(void) { - GtkWidget *window; - GtkWidget *vbox; - GtkWidget *table; - GtkWidget *label; - GtkWidget *host_label; - GtkWidget *port_label; - GtkWidget *basedn_list; - GtkWidget *vlbox; - GtkWidget *lwindow; - GtkWidget *basedn_entry; - GtkWidget *hbbox; - GtkWidget *hsep; - GtkWidget *ok_btn; - GtkWidget *cancel_btn; - GtkWidget *hsbox; - GtkWidget *statusbar; - GtkListStore *store; - GtkTreeSelection *sel; - GtkTreeViewColumn *col; - GtkCellRenderer *rdr; - - window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "editldap_basedn"); - gtk_container_set_border_width(GTK_CONTAINER(window), 0); - gtk_window_set_title(GTK_WINDOW(window), _("Edit LDAP - Select Search Base")); - gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); - gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DIALOG); - g_signal_connect(G_OBJECT(window), "delete_event", - G_CALLBACK(edit_ldap_bdn_delete_event), NULL ); - g_signal_connect(G_OBJECT(window), "key_press_event", - G_CALLBACK(edit_ldap_bdn_key_pressed), NULL ); - - vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8); - gtk_container_add(GTK_CONTAINER(window), vbox); - gtk_container_set_border_width( GTK_CONTAINER(vbox), 0 ); - - table = gtk_grid_new(); - gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); - gtk_container_set_border_width( GTK_CONTAINER(table), 8 ); - gtk_grid_set_row_spacing(GTK_GRID(table), 8); - gtk_grid_set_column_spacing(GTK_GRID(table), 8); - - /* First row */ - label = gtk_label_new(_("Hostname")); - gtk_label_set_xalign(GTK_LABEL(label), 0.0); - gtk_grid_attach(GTK_GRID(table), label, 0, 0, 1, 1); - - host_label = gtk_label_new(""); - gtk_label_set_xalign(GTK_LABEL(host_label), 0.0); - gtk_grid_attach(GTK_GRID(table), host_label, 1, 0, 1, 1); - - /* Second row */ - label = gtk_label_new(_("Port")); - gtk_label_set_xalign(GTK_LABEL(label), 0.0); - gtk_grid_attach(GTK_GRID(table), label, 0, 1, 1, 1); - - port_label = gtk_label_new(""); - gtk_label_set_xalign(GTK_LABEL(port_label), 0.0); - gtk_grid_attach(GTK_GRID(table), label, 1, 1, 1, 1); - - /* Third row */ - label = gtk_label_new(_("Search Base")); - gtk_label_set_xalign(GTK_LABEL(label), 0.0); - gtk_grid_attach(GTK_GRID(table), label, 0, 2, 1, 1); - - basedn_entry = gtk_entry_new(); - gtk_grid_attach(GTK_GRID(table), basedn_entry, 1, 2, 1, 1); - gtk_widget_set_hexpand(basedn_entry, TRUE); - gtk_widget_set_halign(basedn_entry, GTK_ALIGN_FILL); - - /* Basedn list */ - vlbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8); - gtk_box_pack_start(GTK_BOX(vbox), vlbox, TRUE, TRUE, 0); - gtk_container_set_border_width( GTK_CONTAINER(vlbox), 8 ); - - lwindow = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(lwindow), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - gtk_box_pack_start(GTK_BOX(vlbox), lwindow, TRUE, TRUE, 0); - - store = gtk_list_store_new(1, G_TYPE_STRING, -1); - - basedn_list = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); - g_object_unref(store); - gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(basedn_list), TRUE); - sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(basedn_list)); - gtk_tree_selection_set_mode(sel, GTK_SELECTION_BROWSE); - - rdr = gtk_cell_renderer_text_new(); - col = gtk_tree_view_column_new_with_attributes( - _("Available Search Base(s)"), rdr, - "markup", 0, NULL); - gtk_tree_view_append_column(GTK_TREE_VIEW(basedn_list), col); - - gtk_container_add(GTK_CONTAINER(lwindow), basedn_list); - - g_signal_connect(G_OBJECT(basedn_list), "cursor-changed", - G_CALLBACK(basedn_list_cursor_changed), NULL); - g_signal_connect(G_OBJECT(basedn_list), "row-activated", - G_CALLBACK(basedn_list_row_activated), NULL); - - - /* Status line */ - hsbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); - gtk_box_pack_end(GTK_BOX(vbox), hsbox, FALSE, FALSE, BORDER_WIDTH); - statusbar = gtk_statusbar_new(); - gtk_box_pack_start(GTK_BOX(hsbox), statusbar, TRUE, TRUE, BORDER_WIDTH); - - /* Button panel */ - gtkut_stock_button_set_create(&hbbox, &cancel_btn, NULL, _("_Cancel"), - &ok_btn, NULL, _("_OK"), - NULL, NULL, NULL); - gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0); - gtk_container_set_border_width( GTK_CONTAINER(hbbox), 0 ); - gtk_widget_grab_default(ok_btn); - - hsep = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL); - gtk_box_pack_end(GTK_BOX(vbox), hsep, FALSE, FALSE, 0); - - g_signal_connect(G_OBJECT(ok_btn), "clicked", - G_CALLBACK(edit_ldap_bdn_ok), NULL); - g_signal_connect(G_OBJECT(cancel_btn), "clicked", - G_CALLBACK(edit_ldap_bdn_cancel), NULL); - - gtk_widget_show_all(vbox); - - ldapedit_basedn.window = window; - ldapedit_basedn.host_label = host_label; - ldapedit_basedn.port_label = port_label; - ldapedit_basedn.basedn_entry = basedn_entry; - ldapedit_basedn.basedn_list = basedn_list; - ldapedit_basedn.ok_btn = ok_btn; - ldapedit_basedn.cancel_btn = cancel_btn; - ldapedit_basedn.statusbar = statusbar; - ldapedit_basedn.status_cid = - gtk_statusbar_get_context_id( - GTK_STATUSBAR(statusbar), "Edit LDAP Select Base DN" ); -} - -static void edit_ldap_bdn_load_data( - const gchar *hostName, const gint iPort, const gint tov, - const gchar* bindDN, const gchar *bindPW, int ssl, int tls ) -{ - gchar *sHost; - gchar *sMsg = NULL; - gchar sPort[20]; - gboolean flgConn; - gboolean flgDN; - GList *baseDN = NULL; - GtkWidget *view = ldapedit_basedn.basedn_list; - GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(view)); - GtkTreeIter iter; - GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); - - edit_ldap_bdn_status_show( "" ); - - gtk_list_store_clear(GTK_LIST_STORE(model)); - - ldapedit_basedn_bad_server = TRUE; - flgConn = flgDN = FALSE; - sHost = g_strdup( hostName ); - sprintf( sPort, "%d", iPort ); - gtk_label_set_text(GTK_LABEL(ldapedit_basedn.host_label), hostName); - gtk_label_set_text(GTK_LABEL(ldapedit_basedn.port_label), sPort); - if( *sHost != '\0' ) { - /* Test connection to server */ - if( ldaputil_test_connect( sHost, iPort, ssl, tls, tov ) ) { - /* Attempt to read base DN */ - baseDN = ldaputil_read_basedn( sHost, iPort, bindDN, bindPW, tov, ssl, tls ); - if( baseDN ) { - GList *node = baseDN; - - while( node ) { - gtk_list_store_append(GTK_LIST_STORE(model), &iter); - gtk_list_store_set(GTK_LIST_STORE(model), &iter, - 0, (gchar *)node->data, -1); - node = g_list_next( node ); - flgDN = TRUE; - } - - /* Select the first line */ - if (gtk_tree_model_get_iter_first(model, &iter)) - gtk_tree_selection_select_iter(sel, &iter); - - g_list_free_full( baseDN, g_free ); - baseDN = node = NULL; - } - ldapedit_basedn_bad_server = FALSE; - flgConn = TRUE; - } - } - g_free( sHost ); - - /* Display appropriate message */ - if( flgConn ) { - if( ! flgDN ) { - sMsg = _( "Could not read Search Base(s) from server - please set manually" ); - } - } - else { - sMsg = _( "Could not connect to server" ); - } - edit_ldap_bdn_status_show( sMsg ); -} - -gchar *edit_ldap_basedn_selection( const gchar *hostName, const gint port, gchar *baseDN, const gint tov, - const gchar* bindDN, const gchar *bindPW, int ssl, int tls ) { - gchar *retVal = NULL; - - ldapedit_basedn_cancelled = FALSE; - if( ! ldapedit_basedn.window ) edit_ldap_bdn_create(); - gtk_widget_grab_focus(ldapedit_basedn.ok_btn); - gtk_widget_show(ldapedit_basedn.window); - manage_window_set_transient(GTK_WINDOW(ldapedit_basedn.window)); - gtk_window_set_modal(GTK_WINDOW(ldapedit_basedn.window), TRUE); - edit_ldap_bdn_status_show( "" ); - edit_ldap_bdn_load_data( hostName, port, tov, bindDN, bindPW, ssl, tls ); - gtk_widget_show(ldapedit_basedn.window); - - gtk_entry_set_text(GTK_ENTRY(ldapedit_basedn.basedn_entry), baseDN); - - gtk_main(); - gtk_widget_hide(ldapedit_basedn.window); - gtk_window_set_modal(GTK_WINDOW(ldapedit_basedn.window), FALSE); - if( ldapedit_basedn_cancelled ) return NULL; - if( ldapedit_basedn_bad_server ) return NULL; - - retVal = gtk_editable_get_chars( GTK_EDITABLE(ldapedit_basedn.basedn_entry), 0, -1 ); - g_strstrip( retVal ); - if( *retVal == '\0' ) { - g_free( retVal ); - retVal = NULL; - } - return retVal; -} - -#endif /* USE_LDAP */ - -/* -* End of Source. -*/ - diff --git a/src/editldap_basedn.h b/src/editldap_basedn.h @@ -1,30 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2001-2012 Match Grun and the Claws Mail team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -#ifndef __EDITLDAP_BASEDN_H__ -#define __EDITLDAP_BASEDN_H__ - -#ifdef USE_LDAP - -gchar *edit_ldap_basedn_selection( const gchar *hostName, const gint port, gchar *baseDN, const gint tov, - const gchar* bindDN, const gchar *bindPW, int ssl, int tls ); - -#endif /* USE_LDAP */ - -#endif /* __EDITLDAP_BASEDN_H__ */ diff --git a/src/etpan/etpan-errors.h b/src/etpan/etpan-errors.h @@ -14,7 +14,7 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * */ #ifndef ETPAN_ERRORS_H @@ -56,7 +56,6 @@ enum { ERROR_IMAP_CREATE, ERROR_PRIVACY, ERROR_DIRECTORY_NOT_FOUND, - ERROR_LDAP_SEARCH, ERROR_NOT_SUPPORTED, ERROR_COULD_NOT_POSTPONE, ERROR_NO_FROM, diff --git a/src/expldifdlg.c b/src/expldifdlg.c @@ -1,780 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2003-2025 the Claws Mail team and Match Grun - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * Export address book to LDIF file. - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#include "claws-features.h" -#endif - -#include "defs.h" - -#include <glib.h> -#include <glib/gi18n.h> -#include <gdk/gdkkeysyms.h> -#include <gtk/gtk.h> - -#include "gtkutils.h" -#include "prefs_common.h" -#include "alertpanel.h" -#include "mgutils.h" -#include "addrcache.h" -#include "addressitem.h" -#include "exportldif.h" -#include "utils.h" -#include "manage_window.h" -#include "filesel.h" -#include "combobox.h" - -#define PAGE_FILE_INFO 0 -#define PAGE_DN 1 -#define PAGE_FINISH 2 - -#define EXPORTLDIF_WIDTH 480 -#define EXPORTLDIF_HEIGHT -1 - -/** - * Dialog object. - */ -static struct _ExpLdif_Dlg { - GtkWidget *window; - GtkWidget *notebook; - GtkWidget *labelBook; - GtkWidget *entryLdif; - GtkWidget *entrySuffix; - GtkWidget *optmenuRDN; - GtkWidget *checkUseDN; - GtkWidget *checkEMail; - GtkWidget *labelOutBook; - GtkWidget *labelOutFile; - GtkWidget *btnPrev; - GtkWidget *btnNext; - GtkWidget *btnCancel; - GtkWidget *statusbar; - gint status_cid; - gboolean cancelled; -} expldif_dlg; - -static struct _AddressFileSelection _exp_ldif_file_selector_; - -static ExportLdifCtl *_exportCtl_ = NULL; -static AddressCache *_addressCache_ = NULL; - -/** - * Display message in status field. - * \param msg Message to display. - */ -static void export_ldif_status_show( gchar *msg ) { - if( expldif_dlg.statusbar != NULL ) { - gtk_statusbar_pop( - GTK_STATUSBAR(expldif_dlg.statusbar), - expldif_dlg.status_cid ); - if( msg ) { - gtk_statusbar_push( - GTK_STATUSBAR(expldif_dlg.statusbar), - expldif_dlg.status_cid, msg ); - } - } -} - -/** - * Select and display status message appropriate for the page being displayed. - */ -static void export_ldif_message( void ) { - gchar *sMsg = NULL; - gint pageNum; - - pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(expldif_dlg.notebook) ); - if( pageNum == PAGE_FILE_INFO ) { - sMsg = _( "Please specify output directory and LDIF filename to create." ); - } - else if( pageNum == PAGE_DN ) { - sMsg = _( "Specify parameters to format distinguished name." ); - } - else if( pageNum == PAGE_FINISH ) { - sMsg = _( "File exported successfully." ); - } - export_ldif_status_show( sMsg ); -} - -/** - * Callback function to cancel LDIF file selection dialog. - * \param widget Widget (button). - * \param data User data. - */ -static void export_ldif_cancel( GtkWidget *widget, gpointer data ) { - gint pageNum; - - pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(expldif_dlg.notebook) ); - if( pageNum != PAGE_FINISH ) { - expldif_dlg.cancelled = TRUE; - } - gtk_main_quit(); -} - -/** - * Callback function to handle dialog close event. - * \param widget Widget (dialog). - * \param event Event object. - * \param data User data. - */ -static gint export_ldif_delete_event( GtkWidget *widget, GdkEventAny *event, gpointer data ) { - export_ldif_cancel( widget, data ); - return TRUE; -} - -/** - * Callback function to respond to dialog key press events. - * \param widget Widget. - * \param event Event object. - * \param data User data. - */ -static gboolean export_ldif_key_pressed( GtkWidget *widget, GdkEventKey *event, gpointer data ) { - if (event && event->keyval == GDK_KEY_Escape) { - export_ldif_cancel( widget, data ); - } - return FALSE; -} - -/** - * Test whether we can move off file page. - * \return <i>TRUE</i> if OK to move off page. - */ -static gboolean exp_ldif_move_file( void ) { - gchar *sFile, *msg, *reason; - gboolean errFlag = FALSE; - AlertValue aval; - - sFile = gtk_editable_get_chars( GTK_EDITABLE(expldif_dlg.entryLdif), 0, -1 ); - g_strstrip( sFile ); - gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entryLdif), sFile ); - exportldif_parse_filespec( _exportCtl_, sFile ); - - /* Test that something was supplied */ - if( *sFile == '\0'|| strlen( sFile ) < 1 ) { - gtk_widget_grab_focus( expldif_dlg.entryLdif ); - errFlag = TRUE; - } - g_free( sFile ); - if( errFlag ) return FALSE; - - /* Test for directory */ - if( g_file_test(_exportCtl_->dirOutput, - G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) ) { - return TRUE; - } - - /* Prompt to create */ - msg = g_strdup_printf( _( - "LDIF Output Directory '%s'\n" \ - "does not exist. OK to create new directory?" ), - _exportCtl_->dirOutput ); - aval = alertpanel( _("Create Directory" ), - msg, NULL, _("_No"), NULL, _("_Yes"), NULL, NULL, ALERTFOCUS_FIRST ); - g_free( msg ); - if( aval != G_ALERTALTERNATE ) return FALSE; - - /* Create directory */ - if( ! exportldif_create_dir( _exportCtl_ ) ) { - reason = exportldif_get_create_msg( _exportCtl_ ); - msg = g_strdup_printf( _( - "Could not create output directory for LDIF file:\n%s" ), - reason ); - aval = alertpanel_full(_("Failed to Create Directory"), msg, - NULL, _("Close"), NULL, NULL, NULL, NULL, - ALERTFOCUS_FIRST, FALSE, NULL, ALERT_ERROR); - g_free( msg ); - return FALSE; - } - - return TRUE; -} - -/** - * Test whether we can move off distinguished name page. - * \return <i>TRUE</i> if OK to move off page. - */ -static gboolean exp_ldif_move_dn( void ) { - gboolean retVal = FALSE; - gboolean errFlag = FALSE; - gchar *suffix; - gint id; - - /* Set suffix */ - suffix = gtk_editable_get_chars( GTK_EDITABLE(expldif_dlg.entrySuffix), 0, -1 ); - g_strstrip( suffix ); - - /* Set RDN format */ - id = combobox_get_active_data(GTK_COMBO_BOX(expldif_dlg.optmenuRDN)); - exportldif_set_rdn( _exportCtl_, id ); - - exportldif_set_suffix( _exportCtl_, suffix ); - exportldif_set_use_dn( _exportCtl_, - gtk_toggle_button_get_active( - GTK_TOGGLE_BUTTON( expldif_dlg.checkUseDN ) ) ); - exportldif_set_exclude_email( _exportCtl_, - gtk_toggle_button_get_active( - GTK_TOGGLE_BUTTON( expldif_dlg.checkEMail ) ) ); - - if( *suffix == '\0' || strlen( suffix ) < 1 ) { - AlertValue aval; - - aval = alertpanel( - _( "Suffix was not supplied" ), - _( - "A suffix is required if data is to be used " \ - "for an LDAP server. Are you sure you wish " \ - "to proceed without a suffix?" - ), - NULL, _("_No"), NULL, _("_Yes"), NULL, NULL, ALERTFOCUS_FIRST ); - if( aval != G_ALERTALTERNATE ) { - gtk_widget_grab_focus( expldif_dlg.entrySuffix ); - errFlag = TRUE; - } - } - - if( ! errFlag ) { - /* Process export */ - exportldif_process( _exportCtl_, _addressCache_ ); - if( _exportCtl_->retVal == MGU_SUCCESS ) { - retVal = TRUE; - } - else { - export_ldif_status_show( _( "Error creating LDIF file" ) ); - } - } - - return retVal; -} - -/** - * Display finish page. - */ -static void exp_ldif_finish_show( void ) { - gtk_label_set_text( GTK_LABEL(expldif_dlg.labelOutFile), _exportCtl_->path ); - gtk_widget_set_sensitive( expldif_dlg.btnNext, FALSE ); - gtk_widget_grab_focus( expldif_dlg.btnCancel ); -} - -/** - * Callback function to select previous page. - * \param widget Widget (button). - */ -static void export_ldif_prev( GtkWidget *widget ) { - gint pageNum; - - pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(expldif_dlg.notebook) ); - if( pageNum == PAGE_DN ) { - /* Goto file page stuff */ - gtk_notebook_set_current_page( - GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_FILE_INFO ); - gtk_widget_set_sensitive( expldif_dlg.btnPrev, FALSE ); - } - else if( pageNum == PAGE_FINISH ) { - /* Goto format page */ - gtk_notebook_set_current_page( - GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_DN ); - gtk_widget_set_sensitive( expldif_dlg.btnNext, TRUE ); - } - export_ldif_message(); -} - -/** - * Callback function to select next page. - * \param widget Widget (button). - */ -static void export_ldif_next( GtkWidget *widget ) { - gint pageNum; - - pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(expldif_dlg.notebook) ); - if( pageNum == PAGE_FILE_INFO ) { - /* Goto distinguished name page */ - if( exp_ldif_move_file() ) { - gtk_notebook_set_current_page( - GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_DN ); - gtk_widget_set_sensitive( expldif_dlg.btnPrev, TRUE ); - } - export_ldif_message(); - } - else if( pageNum == PAGE_DN ) { - /* Goto finish page */ - if( exp_ldif_move_dn() ) { - gtk_notebook_set_current_page( - GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_FINISH ); - gtk_button_set_label(GTK_BUTTON(expldif_dlg.btnCancel), - _("_Close")); - gtk_button_set_image(GTK_BUTTON(expldif_dlg.btnCancel), - gtk_image_new_from_icon_name("window-close-symbolic", GTK_ICON_SIZE_BUTTON)); - exp_ldif_finish_show(); - exportldif_save_settings( _exportCtl_ ); - export_ldif_message(); - } - } -} - -/** - * Create LDIF file selection dialog. - * \param afs Address file selection data. - */ -static void exp_ldif_file_select_create( AddressFileSelection *afs ) { - gchar *file = filesel_select_file_save(_("Select LDIF output file"), NULL); - - if (file == NULL) - afs->cancelled = TRUE; - else { - afs->cancelled = FALSE; - gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entryLdif), file ); - g_free(file); - } -} - -/** - * Callback function to display LDIF file selection dialog. - */ -static void exp_ldif_file_select( void ) { - exp_ldif_file_select_create( & _exp_ldif_file_selector_ ); -} - -/** - * Format notebook file specification page. - * \param pageNum Page (tab) number. - * \param pageLbl Page (tab) label. - */ -static void export_ldif_page_file( gint pageNum, gchar *pageLbl ) { - GtkWidget *vbox; - GtkWidget *table; - GtkWidget *label; - GtkWidget *labelBook; - GtkWidget *entryLdif; - GtkWidget *btnFile; - - vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8); - gtk_container_add( GTK_CONTAINER( expldif_dlg.notebook ), vbox ); - gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH ); - - label = gtk_label_new( pageLbl ); - gtk_widget_show( label ); - gtk_notebook_set_tab_label( - GTK_NOTEBOOK( expldif_dlg.notebook ), - gtk_notebook_get_nth_page( - GTK_NOTEBOOK( expldif_dlg.notebook ), pageNum ), - label ); - - table = gtk_grid_new(); - gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); - gtk_container_set_border_width( GTK_CONTAINER(table), 8 ); - gtk_grid_set_row_spacing(GTK_GRID(table), 8); - gtk_grid_set_column_spacing(GTK_GRID(table), 8); - - /* First row */ - label = gtk_label_new( _( "Address Book" ) ); - gtk_label_set_xalign(GTK_LABEL(label), 0.0); - gtk_grid_attach(GTK_GRID(table), label, 0, 0, 1, 1); - - labelBook = gtk_label_new( "Address book name goes here" ); - gtk_label_set_xalign(GTK_LABEL(labelBook), 0.0); - gtk_grid_attach(GTK_GRID(table), labelBook, 1, 0, 1, 1); - - /* Second row */ - label = gtk_label_new( _( "LDIF Output File" ) ); - gtk_label_set_xalign(GTK_LABEL(label), 0.0); - gtk_grid_attach(GTK_GRID(table), label, 0, 1, 1, 1); - - entryLdif = gtk_entry_new(); - gtk_grid_attach(GTK_GRID(table), entryLdif, 1, 1, 1, 1); - gtk_widget_set_hexpand(entryLdif, TRUE); - gtk_widget_set_halign(entryLdif, GTK_ALIGN_FILL); - - btnFile = gtkut_get_browse_file_btn(_("B_rowse")); - gtk_grid_attach(GTK_GRID(table), btnFile, 2, 1, 1, 1); - - gtk_widget_show_all(vbox); - - /* Button handler */ - g_signal_connect(G_OBJECT(btnFile), "clicked", - G_CALLBACK(exp_ldif_file_select), NULL); - - expldif_dlg.labelBook = labelBook; - expldif_dlg.entryLdif = entryLdif; -} - -static void export_ldif_relative_dn_changed(GtkWidget *widget, gpointer data) -{ - gint relativeDN = combobox_get_active_data(GTK_COMBO_BOX(widget)); - GtkLabel *label = GTK_LABEL(data); - - switch(relativeDN) { - case EXPORT_LDIF_ID_UID: - gtk_label_set_text(label, - _("The address book Unique ID is used to create a DN that is " \ - "formatted similar to:\n" \ - " uid=102376,ou=people,dc=claws-mail,dc=org")); - break; - case EXPORT_LDIF_ID_DNAME: - gtk_label_set_text(label, - _("The address book Display Name is used to create a DN that " \ - "is formatted similar to:\n" \ - " cn=John Doe,ou=people,dc=claws-mail,dc=org")); - break; - case EXPORT_LDIF_ID_EMAIL: - gtk_label_set_text(label, - _("The first Email Address belonging to a person is used to " \ - "create a DN that is formatted similar to:\n" \ - " mail=john.doe@domain.com,ou=people,dc=claws-mail,dc=org")); - break; - } - -} - -/** - * Format notebook distinguished name page. - * \param pageNum Page (tab) number. - * \param pageLbl Page (tab) label. - */ -static void export_ldif_page_dn( gint pageNum, gchar *pageLbl ) { - GtkWidget *vbox; - GtkWidget *table; - GtkWidget *label; - GtkWidget *entrySuffix; - GtkWidget *optmenuRDN; - GtkWidget *labelRDN; - GtkWidget *checkUseDN; - GtkWidget *checkEMail; - GtkListStore *store; - GtkTreeIter iter; - - vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8); - gtk_container_add( GTK_CONTAINER( expldif_dlg.notebook ), vbox ); - gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH ); - - label = gtk_label_new( pageLbl ); - gtk_widget_show( label ); - gtk_notebook_set_tab_label( - GTK_NOTEBOOK( expldif_dlg.notebook ), - gtk_notebook_get_nth_page( - GTK_NOTEBOOK( expldif_dlg.notebook ), pageNum ), - label ); - - table = gtk_grid_new(); - gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); - gtk_container_set_border_width( GTK_CONTAINER(table), 8 ); - gtk_grid_set_row_spacing(GTK_GRID(table), 8); - gtk_grid_set_column_spacing(GTK_GRID(table), 8); - - /* First row */ - label = gtk_label_new( _( "Suffix" ) ); - gtk_label_set_xalign(GTK_LABEL(label), 0.0); - gtk_grid_attach(GTK_GRID(table), label, 0, 0, 1, 1); - - entrySuffix = gtk_entry_new(); - gtk_grid_attach(GTK_GRID(table), entrySuffix, 1, 0, 1, 1); - gtk_widget_set_hexpand(entrySuffix, TRUE); - gtk_widget_set_halign(entrySuffix, GTK_ALIGN_FILL); - - CLAWS_SET_TIP(entrySuffix, _( - "The suffix is used to create a \"Distinguished Name\" " \ - "(or DN) for an LDAP entry. Examples include:\n" \ - " dc=claws-mail,dc=org\n" \ - " ou=people,dc=domainname,dc=com\n" \ - " o=Organization Name,c=Country\n")); - - /* Second row */ - label = gtk_label_new( _( "Relative DN" ) ); - gtk_label_set_xalign(GTK_LABEL(label), 0.0); - gtk_grid_attach(GTK_GRID(table), label, 0, 1, 1, 1); - - optmenuRDN = gtkut_sc_combobox_create(NULL, TRUE); - store = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenuRDN))); - - COMBOBOX_ADD(store, _("Unique ID"), EXPORT_LDIF_ID_UID); - COMBOBOX_ADD(store, _("Display Name"), EXPORT_LDIF_ID_DNAME); - COMBOBOX_ADD(store, _("Email Address"), EXPORT_LDIF_ID_EMAIL); - - gtk_grid_attach(GTK_GRID(table), optmenuRDN, 1, 1, 1, 1); - - CLAWS_SET_TIP(optmenuRDN, _( - "The LDIF file contains several data records that " \ - "are usually loaded into an LDAP server. Each data " \ - "record in the LDIF file is uniquely identified by " \ - "a \"Distinguished Name\" (or DN). The suffix is " \ - "appended to the \"Relative Distinguished Name\" "\ - "(or RDN) to create the DN. Please select one of " \ - "the available RDN options that will be used to " \ - "create the DN.")); - - /* Third row*/ - labelRDN = gtk_label_new(""); - gtk_label_set_line_wrap(GTK_LABEL(labelRDN), TRUE); - gtk_label_set_justify(GTK_LABEL(labelRDN), GTK_JUSTIFY_CENTER); - gtk_grid_attach(GTK_GRID(table), labelRDN, 0, 2, 1, 1); - - /* Fourth row */ - checkUseDN = gtk_check_button_new_with_label( - _( "Use DN attribute if present in data" ) ); - gtk_grid_attach(GTK_GRID(table), checkUseDN, 1, 3, 1, 1); - - CLAWS_SET_TIP(checkUseDN, _( - "The addressbook may contain entries that were " \ - "previously imported from an LDIF file. The " \ - "\"Distinguished Name\" (DN) user attribute, if " \ - "present in the address book data, may be used in " \ - "the exported LDIF file. The RDN selected above " \ - "will be used if the DN user attribute is not found.")); - - /* Fifth row */ - checkEMail = gtk_check_button_new_with_label( - _( "Exclude record if no Email Address" ) ); - gtk_grid_attach(GTK_GRID(table), checkEMail, 1, 4, 1, 1); - - CLAWS_SET_TIP(checkEMail, _( - "An addressbook may contain entries without " \ - "Email Addresses. Check this option to ignore " \ - "these records.")); - - - gtk_widget_show_all(vbox); - - g_signal_connect(G_OBJECT(optmenuRDN), "changed", - G_CALLBACK(export_ldif_relative_dn_changed), labelRDN); - gtk_combo_box_set_active(GTK_COMBO_BOX(optmenuRDN), 0); - - - expldif_dlg.entrySuffix = entrySuffix; - expldif_dlg.optmenuRDN = optmenuRDN; - expldif_dlg.checkUseDN = checkUseDN; - expldif_dlg.checkEMail = checkEMail; -} - -/** - * Format notebook finish page. - * \param pageNum Page (tab) number. - * \param pageLbl Page (tab) label. - */ -static void export_ldif_page_finish( gint pageNum, gchar *pageLbl ) { - GtkWidget *vbox; - GtkWidget *table; - GtkWidget *label; - GtkWidget *labelBook; - GtkWidget *labelFile; - - vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8); - gtk_container_add( GTK_CONTAINER( expldif_dlg.notebook ), vbox ); - gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH ); - - label = gtk_label_new( pageLbl ); - gtk_widget_show( label ); - gtk_notebook_set_tab_label( - GTK_NOTEBOOK( expldif_dlg.notebook ), - gtk_notebook_get_nth_page( GTK_NOTEBOOK( expldif_dlg.notebook ), pageNum ), label ); - - table = gtk_grid_new(); - gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); - gtk_container_set_border_width( GTK_CONTAINER(table), 8 ); - gtk_grid_set_row_spacing(GTK_GRID(table), 8); - gtk_grid_set_column_spacing(GTK_GRID(table), 8); - - /* First row */ - label = gtk_label_new( _( "Address Book:" ) ); - gtk_label_set_xalign(GTK_LABEL(label), 1.0); - gtk_grid_attach(GTK_GRID(table), label, 0, 0, 1, 1); - - labelBook = gtk_label_new("Full name of address book goes here"); - gtk_label_set_xalign(GTK_LABEL(labelBook), 0.0); - gtk_grid_attach(GTK_GRID(table), labelBook, 1, 0, 1, 1); - - /* Second row */ - label = gtk_label_new( _( "File Name:" ) ); - gtk_label_set_xalign(GTK_LABEL(label), 1.0); - gtk_grid_attach(GTK_GRID(table), label, 0, 1, 1, 1); - - labelFile = gtk_label_new("File name goes here"); - gtk_label_set_xalign(GTK_LABEL(labelFile), 0.0); - gtk_grid_attach(GTK_GRID(table), labelFile, 1, 1, 1, 1); - - gtk_widget_show_all(vbox); - - expldif_dlg.labelOutBook = labelBook; - expldif_dlg.labelOutFile = labelFile; -} - -/** - * Create main dialog decorations (excluding notebook pages). - */ -static void export_ldif_dialog_create( void ) { - GtkWidget *window; - GtkWidget *vbox; - GtkWidget *vnbox; - GtkWidget *notebook; - GtkWidget *hbbox; - GtkWidget *btnPrev; - GtkWidget *btnNext; - GtkWidget *btnCancel; - GtkWidget *hsbox; - GtkWidget *statusbar; - - window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "expldifdlg"); - gtk_widget_set_size_request(window, EXPORTLDIF_WIDTH, EXPORTLDIF_HEIGHT ); - gtk_container_set_border_width( GTK_CONTAINER(window), 0 ); - gtk_window_set_title( GTK_WINDOW(window), - _("Export Address Book to LDIF File") ); - gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); - gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DIALOG); - g_signal_connect(G_OBJECT(window), "delete_event", - G_CALLBACK(export_ldif_delete_event), - NULL ); - g_signal_connect(G_OBJECT(window), "key_press_event", - G_CALLBACK(export_ldif_key_pressed), - NULL ); - - vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4); - gtk_widget_show(vbox); - gtk_container_add(GTK_CONTAINER(window), vbox); - - vnbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4); - gtk_container_set_border_width(GTK_CONTAINER(vnbox), 4); - gtk_widget_show(vnbox); - gtk_box_pack_start(GTK_BOX(vbox), vnbox, TRUE, TRUE, 0); - - /* Notebook */ - notebook = gtk_notebook_new(); - gtk_notebook_set_show_tabs( GTK_NOTEBOOK(notebook), FALSE ); /* Hide */ - /* gtk_notebook_set_show_tabs( GTK_NOTEBOOK(notebook), TRUE ); */ - gtk_widget_show(notebook); - gtk_box_pack_start(GTK_BOX(vnbox), notebook, TRUE, TRUE, 0); - gtk_container_set_border_width(GTK_CONTAINER(notebook), 6); - - /* Status line */ - hsbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); - gtk_box_pack_end(GTK_BOX(vbox), hsbox, FALSE, FALSE, BORDER_WIDTH); - statusbar = gtk_statusbar_new(); - gtk_box_pack_start(GTK_BOX(hsbox), statusbar, TRUE, TRUE, BORDER_WIDTH); - - /* Button panel */ - gtkut_stock_button_set_create(&hbbox, &btnPrev, "go-previous", _("_Previous"), - &btnNext, "go-next", _("_Next"), - &btnCancel, NULL, _("_Cancel")); - gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0); - gtk_container_set_border_width(GTK_CONTAINER(hbbox), 2); - gtk_widget_grab_default(btnNext); - - /* Button handlers */ - g_signal_connect(G_OBJECT(btnPrev), "clicked", - G_CALLBACK(export_ldif_prev), NULL); - g_signal_connect(G_OBJECT(btnNext), "clicked", - G_CALLBACK(export_ldif_next), NULL); - g_signal_connect(G_OBJECT(btnCancel), "clicked", - G_CALLBACK(export_ldif_cancel), NULL); - - gtk_widget_show_all(vbox); - - expldif_dlg.window = window; - expldif_dlg.notebook = notebook; - expldif_dlg.btnPrev = btnPrev; - expldif_dlg.btnNext = btnNext; - expldif_dlg.btnCancel = btnCancel; - expldif_dlg.statusbar = statusbar; - expldif_dlg.status_cid = gtk_statusbar_get_context_id( - GTK_STATUSBAR(statusbar), "Export LDIF Dialog" ); -} - -/** - * Create export LDIF dialog. - */ -static void export_ldif_create( void ) { - export_ldif_dialog_create(); - export_ldif_page_file( PAGE_FILE_INFO, _( "File Info" ) ); - export_ldif_page_dn( PAGE_DN, _( "Distinguished Name" ) ); - export_ldif_page_finish( PAGE_FINISH, _( "Finish" ) ); - gtk_widget_show_all( expldif_dlg.window ); -} - -/** - * Populate fields from control data. - * \param ctl Export control data. - */ -static void export_ldif_fill_fields( ExportLdifCtl *ctl ) { - gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entryLdif), "" ); - if( ctl->path ) { - gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entryLdif), - ctl->path ); - } - gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entrySuffix), "" ); - if( ctl->suffix ) { - gtk_entry_set_text( GTK_ENTRY(expldif_dlg.entrySuffix), - ctl->suffix ); - } - - gtk_combo_box_set_active( - GTK_COMBO_BOX( expldif_dlg.optmenuRDN ), ctl->rdnIndex ); - gtk_toggle_button_set_active( - GTK_TOGGLE_BUTTON( expldif_dlg.checkUseDN ), ctl->useDN ); - gtk_toggle_button_set_active( - GTK_TOGGLE_BUTTON( expldif_dlg.checkEMail ), ctl->excludeEMail ); -} - -/** - * Process export address dialog. - * \param cache Address book/data source cache. - */ -void addressbook_exp_ldif( AddressCache *cache ) { - /* Set references to control data */ - _addressCache_ = cache; - - _exportCtl_ = exportldif_create(); - exportldif_load_settings( _exportCtl_ ); - - /* Setup GUI */ - if( ! expldif_dlg.window ) - export_ldif_create(); - - gtk_button_set_label(GTK_BUTTON(expldif_dlg.btnCancel), - _("_Cancel")); - expldif_dlg.cancelled = FALSE; - gtk_widget_show(expldif_dlg.window); - manage_window_set_transient(GTK_WINDOW(expldif_dlg.window)); - gtk_window_set_modal(GTK_WINDOW(expldif_dlg.window), TRUE); - gtk_label_set_text( GTK_LABEL(expldif_dlg.labelBook), cache->name ); - gtk_label_set_text( GTK_LABEL(expldif_dlg.labelOutBook), cache->name ); - export_ldif_fill_fields( _exportCtl_ ); - - gtk_widget_grab_default(expldif_dlg.btnNext); - gtk_notebook_set_current_page( GTK_NOTEBOOK(expldif_dlg.notebook), PAGE_FILE_INFO ); - gtk_widget_set_sensitive( expldif_dlg.btnPrev, FALSE ); - gtk_widget_set_sensitive( expldif_dlg.btnNext, TRUE ); - - export_ldif_message(); - gtk_widget_grab_focus(expldif_dlg.entryLdif); - - gtk_main(); - gtk_widget_hide(expldif_dlg.window); - gtk_window_set_modal(GTK_WINDOW(expldif_dlg.window), FALSE); - exportldif_free( _exportCtl_ ); - _exportCtl_ = NULL; - - _addressCache_ = NULL; -} - -/* - * ============================================================================ - * End of Source. - * ============================================================================ - */ - diff --git a/src/expldifdlg.h b/src/expldifdlg.h @@ -1,35 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2003-2012 Match Grun and the Claws Mail team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -/* - * Export addressbook to HTML file. - */ - -#ifndef __EXPORT_LDIF_H__ -#define __EXPORT_LDIF_H__ - -/* Function prototypes */ -void addressbook_exp_ldif( AddressCache *cache ); - -#endif /* __EXPORT_LDIF_H__ */ - -/* -* End of Source. -*/ - diff --git a/src/exportldif.c b/src/exportldif.c @@ -1,705 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2003-2024 the Claws Mail team and Match Grun - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * Export address book to LDIF file. - */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#include "claws-features.h" -#endif - -#include <sys/stat.h> -#include <errno.h> -#include <time.h> -#include <string.h> -#include <glib.h> -#include <glib/gi18n.h> - -#include "mgutils.h" -#include "utils.h" -#include "exportldif.h" -#include "xmlprops.h" -#include "ldif.h" -#include "file-utils.h" - - -#define DFL_DIR_CLAWS_OUT "claws-mail-out" -#define DFL_FILE_CLAWS_OUT "addressbook.ldif" - -#define FMT_BUFSIZE 2048 -#define XML_BUFSIZE 2048 - -/* Settings - properties */ -#define EXML_PROPFILE_NAME "exportldif.xml" -#define EXMLPROP_DIRECTORY "directory" -#define EXMLPROP_FILE "file" -#define EXMLPROP_SUFFIX "suffix" -#define EXMLPROP_RDN_INDEX "rdn" -#define EXMLPROP_USE_DN "use-dn" -#define EXMLPROP_EXCL_EMAIL "exclude-mail" - -static gchar *_attrName_UID_ = "uid"; -static gchar *_attrName_DName_ = "cn"; -static gchar *_attrName_EMail_ = "mail"; - -/** - * Create initialized LDIF export control object. - * \return Initialized export control data. - */ -ExportLdifCtl *exportldif_create( void ) { - ExportLdifCtl *ctl = g_new0( ExportLdifCtl, 1 ); - - ctl->path = NULL; - ctl->dirOutput = NULL; - ctl->fileLdif = NULL; - ctl->suffix = NULL; - ctl->rdnIndex = EXPORT_LDIF_ID_UID; - ctl->useDN = FALSE; - ctl->excludeEMail = TRUE; - ctl->retVal = MGU_SUCCESS; - ctl->rcCreate = 0; - ctl->settingsFile = g_strconcat( - get_rc_dir(), G_DIR_SEPARATOR_S, EXML_PROPFILE_NAME, NULL ); - - return ctl; -} - -/** - * Free up object by releasing internal memory. - * \return ctl Export control data. - */ -void exportldif_free( ExportLdifCtl *ctl ) { - cm_return_if_fail( ctl != NULL ); - - g_free( ctl->path ); - g_free( ctl->fileLdif ); - g_free( ctl->dirOutput ); - g_free( ctl->suffix ); - g_free( ctl->settingsFile ); - - /* Clear pointers */ - ctl->path = NULL; - ctl->dirOutput = NULL; - ctl->fileLdif = NULL; - ctl->suffix = NULL; - ctl->rdnIndex = EXPORT_LDIF_ID_UID; - ctl->useDN = FALSE; - ctl->excludeEMail = FALSE; - ctl->retVal = MGU_SUCCESS; - ctl->rcCreate = 0; - - /* Now release object */ - g_free( ctl ); -} - -/** - * Specify suffix to be used for creating DN entries. - * \param ctl Export control data. - * \param value Suffix. - */ -void exportldif_set_suffix( ExportLdifCtl *ctl, const char *value ) { - cm_return_if_fail( ctl != NULL ); - ctl->suffix = mgu_replace_string( ctl->suffix, value ); - g_strstrip( ctl->suffix ); -} - -/** - * Specify index of variable to be used for creating RDN entries. - * \param ctl Export control data. - * \param value Index to variable, as follows: - * <ul> - * <li><code>EXPORT_LDIF_ID_UID</code> - Use Claws Mail UID.</li> - * <li><code>EXPORT_LDIF_ID_DNAME</code> - Use Claws Mail display name.</li> - * <li><code>EXPORT_LDIF_ID_EMAIL</code> - Use first Email address.</li> - * </ul> - */ -void exportldif_set_rdn( ExportLdifCtl *ctl, const gint value ) { - cm_return_if_fail( ctl != NULL ); - ctl->rdnIndex = value; -} - -/** - * Specify that <code>DN</code> attribute, if present, should be used as the - * DN for the entry. - * \param ctl Export control data. - * \param value <i>TRUE</i> if DN should be used. - */ -void exportldif_set_use_dn( ExportLdifCtl *ctl, const gboolean value ) { - cm_return_if_fail( ctl != NULL ); - ctl->useDN = value; -} - -/** - * Specify that records without E-Mail addresses should be excluded. - * \param ctl Export control data. - * \param value <i>TRUE</i> if records without E-Mail should be excluded. - */ -void exportldif_set_exclude_email( ExportLdifCtl *ctl, const gboolean value ) { - cm_return_if_fail( ctl != NULL ); - ctl->excludeEMail = value; -} - -/** - * Format LDAP value name with no embedded commas. - * \param value Data value to format. - * \return Formatted string, should be freed after use. - */ -static gchar *exportldif_fmt_value( gchar *value ) { - gchar *dupval; - gchar *src; - gchar *dest; - gchar ch; - - /* Duplicate incoming value */ - dest = dupval = g_strdup( value ); - - /* Copy characters, ignoring commas */ - src = value; - while( *src ) { - ch = *src; - if( ch != ',' ) { - *dest = ch; - dest++; - } - src++; - } - *dest = '\0'; - return dupval; -} - -/** - * Build DN for entry. - * \param ctl Export control data. - * \param person Person to format. - * \return Formatted DN entry. - */ -static gchar *exportldif_fmt_dn( - ExportLdifCtl *ctl, const ItemPerson *person ) -{ - gchar buf[ FMT_BUFSIZE + 1 ]; - gchar *retVal = NULL; - gchar *attr = NULL; - gchar *value = NULL; - gchar *dupval = NULL; - - /* Process RDN */ - *buf = '\0'; - if( ctl->rdnIndex == EXPORT_LDIF_ID_UID ) { - attr = _attrName_UID_; - value = ADDRITEM_ID( person ); - } - else if( ctl->rdnIndex == EXPORT_LDIF_ID_DNAME ) { - attr = _attrName_DName_; - value = ADDRITEM_NAME( person ); - dupval = exportldif_fmt_value( value ); - } - else if( ctl->rdnIndex == EXPORT_LDIF_ID_EMAIL ) { - GList *node; - - node = person->listEMail; - if( node ) { - ItemEMail *email = node->data; - - attr = _attrName_EMail_; - value = email->address; - dupval = exportldif_fmt_value( value ); - } - } - - /* Format DN */ - if( attr ) { - if( value ) { - if( strlen( value ) > 0 ) { - strncat( buf, attr, FMT_BUFSIZE - strlen(buf) ); - strncat( buf, "=", FMT_BUFSIZE - strlen(buf) ); - if( dupval ) { - /* Format and free duplicated value */ - strncat( buf, dupval, FMT_BUFSIZE - strlen(buf) ); - g_free( dupval ); - } - else { - /* Use original value */ - strncat( buf, value, FMT_BUFSIZE - strlen(buf) ); - } - - /* Append suffix */ - if( ctl->suffix ) { - if( strlen( ctl->suffix ) > 0 ) { - strncat( buf, ",", FMT_BUFSIZE - strlen(buf) ); - strncat( buf, ctl->suffix, FMT_BUFSIZE - strlen(buf) ); - } - } - - retVal = g_strdup( buf ); - } - } - } - return retVal; -} - -/** - * Find DN by searching attribute list. - * \param ctl Export control data. - * \param person Person to format. - * \return Formatted DN entry, should be freed after use. - */ -static gchar *exportldif_find_dn( - ExportLdifCtl *ctl, const ItemPerson *person ) -{ - gchar *retVal = NULL; - const GList *node; - - node = person->listAttrib; - while( node ) { - UserAttribute *attrib = node->data; - - node = g_list_next( node ); - if( g_utf8_collate( attrib->name, LDIF_TAG_DN ) == 0 ) { - retVal = g_strdup( attrib->value ); - break; - } - } - return retVal; -} - -/** - * Format E-Mail entries for person. - * \param person Person to format. - * \param stream Output stream. - * \return <i>TRUE</i> if entry formatted. - */ -static gboolean exportldif_fmt_email( const ItemPerson *person, FILE *stream ) { - gboolean retVal = FALSE; - const GList *node; - - node = person->listEMail; - while( node ) { - ItemEMail *email = node->data; - - node = g_list_next( node ); - ldif_write_value( stream, LDIF_TAG_EMAIL, email->address ); - retVal = TRUE; - } - return retVal; -} - -/** - * Test for E-Mail entries for person. - * \param person Person to test. - * \return <i>TRUE</i> if person has E-Mail address. - */ -static gboolean exportldif_test_email( const ItemPerson *person ) -{ - gboolean retVal = FALSE; - const GList *node; - - node = person->listEMail; - while( node ) { - ItemEMail *email = node->data; - - node = g_list_next( node ); - if( email->address ) { - if( strlen( email->address ) > 0 ) { - retVal = TRUE; - break; - } - } - retVal = TRUE; - } - return retVal; -} - -/** - * Format other attributes for person. - * \param person ItemPerson. - * \param stream Output stream. - */ -static void exportldif_fmt_other_attributes(ItemPerson* person, FILE* stream) { - UserAttribute* attr; - GList* attrList = NULL; - gchar* attrib; - - if (! person) - return; - debug_print("cn: %s\n-----------------------------\n", ADDRITEM_NAME(person)); - attrList = person->listAttrib; - while (attrList) { - attr = (UserAttribute *) attrList->data; - if (attr->uid) { - /* Native address book which does not conform to - * the LDAP schemas - */ - attrib = g_strdup_printf("# %s", attr->name); - } - else { - attrib = g_strdup(attr->name); - } - debug_print("name: %s\nvalue: %s\n", attrib, attr->value); - ldif_write_value(stream, attrib, attr->value); - g_free(attrib); - attrList = g_list_next(attrList); - } - debug_print("-------------------------------\n"); -} - -/** - * Find persons displayName. - * \param person ItemPerson. - * \return displayName. - */ -static gchar* exportldif_find_displayName(ItemPerson* person) { - gchar* displayName; - - if (! person) - return NULL; - - if (person->nickName && strlen(person->nickName) > 0) - displayName = g_strdup(person->nickName); - else - displayName = g_strdup(ADDRITEM_NAME(person)); - return displayName; -} - -/** - * Format persons in an address book folder. - * \param ctl Export control data. - * \param stream Output stream. - * \param folder Folder to format. - * \return <i>TRUE</i> if no persons were formatted. - */ -static gboolean exportldif_fmt_person( - ExportLdifCtl *ctl, FILE *stream, const ItemFolder *folder ) -{ - gboolean retVal = TRUE; - const GList *node; - gchar* sn = NULL; - gchar* displayName = NULL; - - if( folder->listPerson == NULL ) return retVal; - - node = folder->listPerson; - while( node ) { - AddrItemObject *aio = node->data; - node = g_list_next( node ); - - if( aio && aio->type == ITEMTYPE_PERSON ) { - ItemPerson *person = ( ItemPerson * ) aio; - gboolean classPerson = FALSE; - gboolean classInetP = FALSE; - gchar *dn = NULL; - - /* Check for E-Mail */ - if( exportldif_test_email( person ) ) { - classInetP = TRUE; - } - else { - /* Bail if no E-Mail address */ - if( ctl->excludeEMail ) continue; - } - - /* Format DN */ - if( ctl->useDN ) { - dn = exportldif_find_dn( ctl, person ); - } - if( dn == NULL ) { - dn = exportldif_fmt_dn( ctl, person ); - } - if( dn == NULL ) continue; - ldif_write_value( stream, LDIF_TAG_DN, dn ); - g_free( dn ); - - /* - * Test for schema requirements. This is a simple - * test and does not trap all LDAP schema errors. - * These can be detected when the LDIF file is - * loaded into an LDAP server. - */ - if( person->lastName ) { - if( strlen( person->lastName ) > 0 ) { - classPerson = TRUE; - classInetP = TRUE; - } - } - - if( classPerson ) { - ldif_write_value( stream, - LDIF_TAG_OBJECTCLASS, LDIF_CLASS_PERSON ); - } - if( classInetP ) { - ldif_write_value( stream, - LDIF_TAG_OBJECTCLASS, LDIF_CLASS_INET_PERSON ); - } - - /* Format person attributes */ - ldif_write_value( - stream, LDIF_TAG_COMMONNAME, ADDRITEM_NAME( person ) ); - sn = g_strdup(person->lastName); - if (classPerson || classInetP) { - if(! sn || strcmp("", sn) == 0 || strcmp(" ", sn) == 0) { - g_free(sn); - sn = g_strdup("Some SN"); - } - } - ldif_write_value( - stream, LDIF_TAG_LASTNAME, sn ); - g_free(sn); - ldif_write_value( - stream, LDIF_TAG_FIRSTNAME, person->firstName ); - - if (! person->externalID) - displayName = exportldif_find_displayName(person); - else - displayName = g_strdup(person->nickName); - ldif_write_value(stream, LDIF_TAG_NICKNAME, displayName); - g_free(displayName); - - /* Format E-Mail */ - exportldif_fmt_email( person, stream ); - - /* Handle other attributes */ - exportldif_fmt_other_attributes(person, stream); - - /* End record */ - ldif_write_eor( stream ); - - retVal = FALSE; - } - } - - return retVal; -} - -/** - * Format an address book folder. - * \param ctl Export control data. - * \param stream Output stream. - * \param folder Folder to format. - * \return <i>TRUE</i> if no persons were formatted. - */ -static void exportldif_fmt_folder( - ExportLdifCtl *ctl, FILE *stream, const ItemFolder *folder ) -{ - const GList *node; - - /* Export entries in this folder */ - exportldif_fmt_person( ctl, stream, folder ); - - /* Export entries in subfolders */ - node = folder->listFolder; - while( node ) { - AddrItemObject *aio = node->data; - - node = g_list_next( node ); - if( aio && aio->type == ITEMTYPE_FOLDER ) { - ItemFolder *subFolder = ( ItemFolder * ) aio; - exportldif_fmt_folder( ctl, stream, subFolder ); - } - } -} - -/** - * Export address book to LDIF file. - * \param ctl Export control data. - * \param cache Address book/data source cache. - * \return Status. - */ -void exportldif_process( ExportLdifCtl *ctl, AddressCache *cache ) -{ - ItemFolder *rootFolder; - FILE *ldifFile; - - ldifFile = claws_fopen( ctl->path, "wb" ); - if( ! ldifFile ) { - /* Cannot open file */ - ctl->retVal = MGU_OPEN_FILE; - return; - } - - rootFolder = cache->rootFolder; - exportldif_fmt_folder( ctl, ldifFile, rootFolder ); - claws_safe_fclose( ldifFile ); - ctl->retVal = MGU_SUCCESS; -} - -/** - * Build full export file specification. - * \param ctl Export control data. - */ -static void exportldif_build_filespec( ExportLdifCtl *ctl ) { - gchar *fileSpec; - - fileSpec = g_strconcat( - ctl->dirOutput, G_DIR_SEPARATOR_S, ctl->fileLdif, NULL ); - ctl->path = mgu_replace_string( ctl->path, fileSpec ); - g_free( fileSpec ); -} - -/** - * Parse directory and filename from full export file specification. - * \param ctl Export control data. - * \param fileSpec File spec. - */ -void exportldif_parse_filespec( ExportLdifCtl *ctl, gchar *fileSpec ) { - gchar *t; - gchar *base = g_path_get_basename(fileSpec); - - ctl->fileLdif = - mgu_replace_string( ctl->fileLdif, base ); - g_free(base); - t = g_path_get_dirname( fileSpec ); - ctl->dirOutput = mgu_replace_string( ctl->dirOutput, t ); - g_free( t ); - ctl->path = mgu_replace_string( ctl->path, fileSpec ); -} - -/** - * Create output directory. - * \param ctl Export control data. - * \return TRUE if directory created. - */ -gboolean exportldif_create_dir( ExportLdifCtl *ctl ) { - gboolean retVal = FALSE; - - ctl->rcCreate = 0; - if( g_mkdir( ctl->dirOutput, S_IRWXU ) == 0 ) { - retVal = TRUE; - } - else { - ctl->rcCreate = errno; - } - return retVal; -} - -/** - * Retrieve create directory error message. - * \param ctl Export control data. - * \return Message. - */ -gchar *exportldif_get_create_msg( ExportLdifCtl *ctl ) { - gchar *msg; - - if( ctl->rcCreate == EEXIST ) { - msg = _( "Name already exists but is not a directory." ); - } - else if( ctl->rcCreate == EACCES ) { - msg = _( "No permissions to create directory." ); - } - else if( ctl->rcCreate == ENAMETOOLONG ) { - msg = _( "Name is too long." ); - } - else { - msg = _( "Not specified." ); - } - return msg; -} - -/** - * Set default values. - * \param ctl Export control data. - */ -static void exportldif_default_values( ExportLdifCtl *ctl ) { - gchar *str; - - str = g_strconcat( - get_home_dir(), G_DIR_SEPARATOR_S, - DFL_DIR_CLAWS_OUT, NULL ); - - ctl->dirOutput = mgu_replace_string( ctl->dirOutput, str ); - g_free( str ); - - ctl->fileLdif = - mgu_replace_string( ctl->fileLdif, DFL_FILE_CLAWS_OUT ); - ctl->suffix = mgu_replace_string( ctl->suffix, "" ); - - ctl->rdnIndex = EXPORT_LDIF_ID_UID; - ctl->useDN = FALSE; - ctl->retVal = MGU_SUCCESS; -} - -/** - * Load settings from XML properties file. - * \param ctl Export control data. - */ -void exportldif_load_settings( ExportLdifCtl *ctl ) { - XmlProperty *props; - gint rc; - gchar buf[ XML_BUFSIZE ]; - - props = xmlprops_create(); - xmlprops_set_path( props, ctl->settingsFile ); - rc = xmlprops_load_file( props ); - if( rc == 0 ) { - /* Read settings */ - *buf = '\0'; - xmlprops_get_property_s( props, EXMLPROP_DIRECTORY, buf ); - ctl->dirOutput = mgu_replace_string( ctl->dirOutput, buf ); - - *buf = '\0'; - xmlprops_get_property_s( props, EXMLPROP_FILE, buf ); - ctl->fileLdif = mgu_replace_string( ctl->fileLdif, buf ); - - *buf = '\0'; - xmlprops_get_property_s( props, EXMLPROP_SUFFIX, buf ); - ctl->suffix = mgu_replace_string( ctl->suffix, buf ); - - ctl->rdnIndex = - xmlprops_get_property_i( props, EXMLPROP_RDN_INDEX ); - ctl->useDN = - xmlprops_get_property_b( props, EXMLPROP_USE_DN ); - ctl->excludeEMail = - xmlprops_get_property_b( props, EXMLPROP_EXCL_EMAIL ); - } - else { - /* Set default values */ - exportldif_default_values( ctl ); - } - exportldif_build_filespec( ctl ); - /* exportldif_print( ctl, stdout ); */ - - xmlprops_free( props ); -} - -/** - * Save settings to XML properties file. - * \param ctl Export control data. - */ -void exportldif_save_settings( ExportLdifCtl *ctl ) { - XmlProperty *props; - - props = xmlprops_create(); - xmlprops_set_path( props, ctl->settingsFile ); - - xmlprops_set_property( props, EXMLPROP_DIRECTORY, ctl->dirOutput ); - xmlprops_set_property( props, EXMLPROP_FILE, ctl->fileLdif ); - xmlprops_set_property( props, EXMLPROP_SUFFIX, ctl->suffix ); - xmlprops_set_property_i( props, EXMLPROP_RDN_INDEX, ctl->rdnIndex ); - xmlprops_set_property_b( props, EXMLPROP_USE_DN, ctl->useDN ); - xmlprops_set_property_b( props, EXMLPROP_EXCL_EMAIL, ctl->excludeEMail ); - if (xmlprops_save_file( props ) != MGU_SUCCESS) - g_warning("can't save settings"); - xmlprops_free( props ); -} - -/* - * ============================================================================ - * End of Source. - * ============================================================================ - */ - - diff --git a/src/exportldif.h b/src/exportldif.h @@ -1,78 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2003-2012 Match Grun and the Claws Mail team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -/* - * Definitions for export to LDIF file. - */ - -#ifndef __EXPORT_LDIF_H__ -#define __EXPORT_LDIF_H__ - -#include <glib.h> - -#include "addrcache.h" - -/* RDN ID's */ -#define EXPORT_LDIF_ID_UID 0 -#define EXPORT_LDIF_ID_DNAME 1 -#define EXPORT_LDIF_ID_EMAIL 2 - -#define EXPORT_LDIF_FIRST_LAST 0 -#define EXPORT_LDIF_LAST_FIRST 1 - -/* Export LDIF control data */ -typedef struct _ExportLdifCtl ExportLdifCtl; -struct _ExportLdifCtl { - gchar *path; - gchar *dirOutput; - gchar *fileLdif; - gchar *settingsFile; - gchar *suffix; - gint rdnIndex; - gboolean useDN; - gboolean excludeEMail; - gint retVal; - gint rcCreate; -}; - -/* Function prototypes */ -ExportLdifCtl *exportldif_create ( void ); -void exportldif_free ( ExportLdifCtl *ctl ); -void exportldif_set_file_html ( ExportLdifCtl *ctl, - const gchar *value ); -void exportldif_set_suffix ( ExportLdifCtl *ctl, - const gchar *value ); -void exportldif_set_rdn ( ExportLdifCtl *ctl, - const gint value ); -void exportldif_set_use_dn ( ExportLdifCtl *ctl, - const gboolean value ); -void exportldif_set_exclude_email ( ExportLdifCtl *ctl, - const gboolean value ); -void exportldif_process ( ExportLdifCtl *ctl, - AddressCache *cache ); -gboolean exportldif_create_dir ( ExportLdifCtl *ctl ); -gchar *exportldif_get_create_msg ( ExportLdifCtl *ctl ); - -void exportldif_parse_filespec ( ExportLdifCtl *ctl, - gchar *fileSpec ); -void exportldif_load_settings ( ExportLdifCtl *ctl ); -void exportldif_save_settings ( ExportLdifCtl *ctl ); - -#endif /* __EXPORT_LDIF_H__ */ - diff --git a/src/gtk/about.c b/src/gtk/about.c @@ -82,7 +82,7 @@ void about_show(void) about_update_stats(); gtk_window_present(GTK_WINDOW(window)); } - + } #define ADD_TEXT(text) gtk_text_buffer_insert(buffer, &iter, text, -1) @@ -429,7 +429,7 @@ static GtkWidget *about_create_child_page_features(void) #endif gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, (" compface "), -1, "bold", NULL); - gtk_text_buffer_insert(buffer, &iter, + gtk_text_buffer_insert(buffer, &iter, (gchar *)C_("compface", "adds support for the X-Face header\n"), -1); #if USE_ENCHANT @@ -439,7 +439,7 @@ static GtkWidget *about_create_child_page_features(void) #endif gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, (" Enchant "), -1, "bold", NULL); - gtk_text_buffer_insert(buffer, &iter, + gtk_text_buffer_insert(buffer, &iter, (gchar *)C_("Enchant", "adds support for spell checking\n"), -1); #if USE_GNUTLS @@ -449,7 +449,7 @@ static GtkWidget *about_create_child_page_features(void) #endif gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, (" GnuTLS "), -1, "bold", NULL); - gtk_text_buffer_insert(buffer, &iter, + gtk_text_buffer_insert(buffer, &iter, (gchar *)C_("GnuTLS", "adds support for encrypted connections to servers\n"), -1); #if HAVE_ICONV @@ -469,29 +469,9 @@ static GtkWidget *about_create_child_page_features(void) #endif gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, (" IPv6 "), -1, "bold", NULL); - gtk_text_buffer_insert(buffer, &iter, + gtk_text_buffer_insert(buffer, &iter, (gchar *)C_("IPv6", "adds support for IPv6 addresses\n"), -1); -#if USE_JPILOT - gtk_text_buffer_insert_pixbuf(buffer, &iter, active_pixbuf); -#else - gtk_text_buffer_insert_pixbuf(buffer, &iter, inactive_pixbuf); -#endif - gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, (" JPilot "), -1, - "bold", NULL); - gtk_text_buffer_insert(buffer, &iter, - (gchar *)C_("JPilot", "adds support for PalmOS addressbooks\n"), -1); - -#if USE_LDAP - gtk_text_buffer_insert_pixbuf(buffer, &iter, active_pixbuf); -#else - gtk_text_buffer_insert_pixbuf(buffer, &iter, inactive_pixbuf); -#endif - gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, (" LDAP "), -1, - "bold", NULL); - gtk_text_buffer_insert(buffer, &iter, - (gchar *)C_("LDAP", "adds support for LDAP shared addressbooks\n"), -1); - #if HAVE_LIBETPAN gtk_text_buffer_insert_pixbuf(buffer, &iter, active_pixbuf); #else @@ -499,7 +479,7 @@ static GtkWidget *about_create_child_page_features(void) #endif gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, (" libetpan "), -1, "bold", NULL); - gtk_text_buffer_insert(buffer, &iter, + gtk_text_buffer_insert(buffer, &iter, (gchar *)C_("libetpan", "adds support for IMAP and NNTP servers\n"), -1); #if HAVE_SVG @@ -519,7 +499,7 @@ static GtkWidget *about_create_child_page_features(void) #endif gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, (" libSM "), -1, "bold", NULL); - gtk_text_buffer_insert(buffer, &iter, + gtk_text_buffer_insert(buffer, &iter, (gchar *)C_("libSM", "adds support for session handling\n"), -1); #if HAVE_NETWORKMANAGER_SUPPORT @@ -600,7 +580,7 @@ static GtkWidget *about_create_child_page_license(void) gtk_text_buffer_insert(buffer, &iter, g_strconcat( _("You should have received a copy of the GNU General Public License " "along with this program. If not, see "), "<", NULL), -1); - gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, + gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "http://www.gnu.org/licenses/", -1, "link", NULL); gtk_text_buffer_insert(buffer, &iter, ">. \n\n", -1); @@ -791,7 +771,7 @@ static void about_update_stats(void) session_stats.forwarded)); gtk_text_buffer_insert_with_tags_by_name(stats_text_buffer, &iter, buf, -1, "indented-list-item", "bold", NULL); - } + } } static void notebook_append_page(GtkWidget *notebook, GtkWidget *scrolledwin, const gchar *label_text) @@ -838,7 +818,7 @@ static void about_create(void) G_CALLBACK(gtk_widget_hide_on_delete), NULL); g_signal_connect(G_OBJECT(window), "key_press_event", G_CALLBACK(key_pressed), NULL); - + if (!geometry.min_width) { geometry.min_width = 450; geometry.min_height = 500; @@ -847,8 +827,8 @@ static void about_create(void) gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry, GDK_HINT_MIN_SIZE); gtk_window_set_default_size(GTK_WINDOW(window), prefs_common.aboutwin_width, - prefs_common.aboutwin_height); - + prefs_common.aboutwin_height); + gtk_widget_realize(window); grid1 = gtk_grid_new(); @@ -1027,7 +1007,7 @@ static void about_textview_uri_update(GtkWidget *textview, gint x, gint y) GtkTextIter start_iter, end_iter; gchar *uri = NULL; gboolean same; - + buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)); if (x != -1 && y != -1) { @@ -1035,8 +1015,8 @@ static void about_textview_uri_update(GtkWidget *textview, gint x, gint y) GtkTextIter iter; GSList *tags; GSList *cur; - - gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(textview), + + gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(textview), GTK_TEXT_WINDOW_WIDGET, x, y, &bx, &by); gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(textview), @@ -1076,7 +1056,7 @@ static void about_textview_uri_update(GtkWidget *textview, gint x, gint y) &uri_hover_start_iter, &uri_hover_end_iter); } - + uri_hover = uri; if (uri) { uri_hover_start_iter = start_iter; @@ -1087,7 +1067,7 @@ static void about_textview_uri_update(GtkWidget *textview, gint x, gint y) &start_iter, &end_iter); } - + window = gtk_text_view_get_window(GTK_TEXT_VIEW(textview), GTK_TEXT_WINDOW_TEXT); if (!hand_cursor) diff --git a/src/importldif.c b/src/importldif.c @@ -1,1041 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2001-2025 the Claws Mail team and Match Grun - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * Import LDIF address book data. - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#include "claws-features.h" -#endif - -#include "defs.h" - -#include <glib.h> -#include <glib/gi18n.h> -#include <gdk/gdkkeysyms.h> -#include <gtk/gtk.h> - -#include "addrbook.h" -#include "addressbook.h" -#include "addressitem.h" -#include "gtkutils.h" -#include "stock_pixmap.h" -#include "prefs_common.h" -#include "manage_window.h" -#include "mgutils.h" -#include "ldif.h" -#include "utils.h" -#include "filesel.h" - -#define IMPORTLDIF_GUESS_NAME "LDIF Import" - -#define PAGE_FILE_INFO 0 -#define PAGE_ATTRIBUTES 1 -#define PAGE_FINISH 2 - -#define IMPORTLDIF_WIDTH 390 -#define IMPORTLDIF_HEIGHT 300 - -#define FIELDS_COL_WIDTH_RESERVED 10 -#define FIELDS_COL_WIDTH_SELECT 10 -#define FIELDS_COL_WIDTH_FIELD 140 -#define FIELDS_COL_WIDTH_ATTRIB 140 - -typedef enum { - FIELD_COL_RESERVED, - FIELD_COL_SELECT, - FIELD_COL_FIELD, - FIELD_COL_ATTRIB, - FIELD_COL_PTR, - FIELDS_N_COLS -} ImpLdif_FieldColPos; - -/** - * LDIF dialog definition. - */ -static struct _ImpLdif_Dlg { - GtkWidget *window; - GtkWidget *notebook; - GtkWidget *entryFile; - GtkWidget *entryName; - GtkWidget *view_fields; - GtkWidget *entryField; - GtkWidget *entryAttrib; - GtkWidget *checkSelect; - GtkWidget *btnModify; - GtkWidget *labelBook; - GtkWidget *labelFile; - GtkWidget *labelRecords; - GtkWidget *btnPrev; - GtkWidget *btnNext; - GtkWidget *btnProceed; - GtkWidget *btnCancel; - GtkWidget *statusbar; - gint status_cid; - gint rowCount; - gchar *nameBook; - gchar *fileName; - gboolean cancelled; -} impldif_dlg; - -static struct _AddressFileSelection _imp_ldif_file_selector_; -static AddressBookFile *_importedBook_; -static AddressIndex *_imp_addressIndex_; -static LdifFile *_ldifFile_ = NULL; - -static GdkPixbuf *markxpm; - -/** - * Structure of error message table. - */ -typedef struct _ErrMsgTableEntry ErrMsgTableEntry; -struct _ErrMsgTableEntry { - gint code; - gchar *description; -}; - -static gchar *_errMsgUnknown_ = N_( "Unknown" ); - -/** - * Lookup table of error messages for general errors. Note that a NULL - * description signifies the end of the table. - */ -static ErrMsgTableEntry _lutErrorsLDIF_[] = { - { MGU_SUCCESS, N_("Success") }, - { MGU_BAD_ARGS, N_("Bad arguments") }, - { MGU_NO_FILE, N_("File not specified") }, - { MGU_OPEN_FILE, N_("Error opening file") }, - { MGU_ERROR_READ, N_("Error reading file") }, - { MGU_EOF, N_("End of file encountered") }, - { MGU_OO_MEMORY, N_("Error allocating memory") }, - { MGU_BAD_FORMAT, N_("Bad file format") }, - { MGU_ERROR_WRITE, N_("Error writing to file") }, - { MGU_OPEN_DIRECTORY, N_("Error opening directory") }, - { MGU_NO_PATH, N_("No path specified") }, - { 0, NULL } -}; - -/** - * Lookup message for specified error code. - * \param lut Lookup table. - * \param code Code to lookup. - * \return Description associated to code. - */ -static gchar *imp_ldif_err2string( ErrMsgTableEntry lut[], gint code ) { - gchar *desc = NULL; - ErrMsgTableEntry entry; - gint i; - - for( i = 0; ; i++ ) { - entry = lut[ i ]; - if( entry.description == NULL ) break; - if( entry.code == code ) { - desc = entry.description; - break; - } - } - if( ! desc ) { - desc = _errMsgUnknown_; - } - return desc; -} - -/** - * Display message in status field. - * \param msg Message to display. - */ -static void imp_ldif_status_show( gchar *msg ) { - if( impldif_dlg.statusbar != NULL ) { - gtk_statusbar_pop( GTK_STATUSBAR(impldif_dlg.statusbar), - impldif_dlg.status_cid ); - if( msg ) { - gtk_statusbar_push( - GTK_STATUSBAR(impldif_dlg.statusbar), - impldif_dlg.status_cid, msg ); - } - } -} - -/** - * Select and display status message appropriate for the page being displayed. - */ -static void imp_ldif_message( void ) { - gchar *sMsg = NULL; - gint pageNum; - - pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(impldif_dlg.notebook) ); - if( pageNum == PAGE_FILE_INFO ) { - sMsg = _( "Please specify address book name and file to import." ); - } - else if( pageNum == PAGE_ATTRIBUTES ) { - sMsg = _( "Select and rename LDIF field names to import." ); - } - else if( pageNum == PAGE_FINISH ) { - sMsg = _( "File imported." ); - } - imp_ldif_status_show( sMsg ); -} - -/** - * Update the line (represented by the GtkTreeIter) with data - * from the Ldif_FieldRec. - */ -static void _populate_iter(GtkListStore *store, GtkTreeIter *iter, - Ldif_FieldRec *rec) -{ - gtk_list_store_set(store, iter, - FIELD_COL_FIELD, rec->tagName, - FIELD_COL_ATTRIB, rec->userName, - FIELD_COL_PTR, rec, - -1); - gtk_list_store_set(store, iter, - FIELD_COL_SELECT, rec->selected ? markxpm : NULL, -1); - gtk_list_store_set(store, iter, - FIELD_COL_RESERVED, rec->reserved ? markxpm : NULL, -1); -} - -/** - * Load list with LDIF fields read from file. - * \param ldf LDIF control data. - */ -static void imp_ldif_load_fields( LdifFile *ldf ) { - GtkWidget *view = impldif_dlg.view_fields; - GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(view)); - GtkTreeIter iter; - GList *node, *list; - - impldif_dlg.rowCount = 0; - - if( ! ldf->accessFlag ) return; - - gtk_list_store_clear(GTK_LIST_STORE(model)); - - list = ldif_get_fieldlist( ldf ); - node = list; - while( node ) { - Ldif_FieldRec *rec = node->data; - - gtk_list_store_append(GTK_LIST_STORE(model), &iter); - _populate_iter(GTK_LIST_STORE(model), &iter, rec); - impldif_dlg.rowCount++; - node = g_list_next( node ); - } - g_list_free( list ); - list = NULL; - ldif_set_accessed( ldf, FALSE ); -} - -/** - * Test whether we can move off fields page. - * \return <i>TRUE</i> if OK to move off page. - */ -static gboolean imp_ldif_field_move() { - gboolean retVal = FALSE; - gchar *newFile; - AddressBookFile *abf = NULL; - - if( _importedBook_ ) { - addrbook_free_book( _importedBook_ ); - } - - abf = addrbook_create_book(); - addrbook_set_path( abf, _imp_addressIndex_->filePath ); - addrbook_set_name( abf, impldif_dlg.nameBook ); - newFile = addrbook_guess_next_file( abf ); - addrbook_set_file( abf, newFile ); - g_free( newFile ); - - /* Import data into file */ - if( ldif_import_data( _ldifFile_, abf->addressCache ) == MGU_SUCCESS ) { - addrbook_save_data( abf ); - _importedBook_ = abf; - retVal = TRUE; - } - else { - addrbook_free_book( abf ); - } - - return retVal; -} - -static void _update_selected_row() -{ - GtkTreeModel *model; - GtkTreeIter iter; - Ldif_FieldRec *rec; - - rec = gtkut_tree_view_get_selected_pointer( - GTK_TREE_VIEW(impldif_dlg.view_fields), FIELD_COL_PTR, - &model, NULL, &iter); - if (rec == NULL) - return; - - ldif_field_set_name(rec, gtk_entry_get_text( - GTK_ENTRY(impldif_dlg.entryAttrib))); - ldif_field_set_selected(rec, gtk_toggle_button_get_active( - GTK_TOGGLE_BUTTON(impldif_dlg.checkSelect))); - - _populate_iter(GTK_LIST_STORE(model), &iter, rec); -} - -static void imp_ldif_modify_pressed(GtkButton *widget, gpointer user_data) -{ - _update_selected_row(); -} - -static void imp_ldif_entryattrib_activate(GtkEntry *entry, gpointer user_data) -{ - _update_selected_row(); -} - -/** - * Test whether we can move off file page. - * \return <i>TRUE</i> if OK to move off page. - */ -static gboolean imp_ldif_file_move() { - gboolean retVal = FALSE; - gchar *sName; - gchar *sFile; - gchar *sMsg = NULL; - gboolean errFlag = FALSE; - - sFile = gtk_editable_get_chars( GTK_EDITABLE(impldif_dlg.entryFile), 0, -1 ); - g_strstrip( sFile ); - - sName = gtk_editable_get_chars( GTK_EDITABLE(impldif_dlg.entryName), 0, -1 ); - g_strstrip( sName ); - - g_free( impldif_dlg.nameBook ); - g_free( impldif_dlg.fileName ); - impldif_dlg.nameBook = sName; - impldif_dlg.fileName = sFile; - - gtk_entry_set_text( GTK_ENTRY(impldif_dlg.entryFile), sFile ); - gtk_entry_set_text( GTK_ENTRY(impldif_dlg.entryName), sName ); - - if( *sFile == '\0' ) { - sMsg = _( "Please select a file." ); - gtk_widget_grab_focus(impldif_dlg.entryFile); - errFlag = TRUE; - } - - if( ! errFlag && *sName == '\0' ) { - sMsg = _( "Address book name must be supplied." ); - gtk_widget_grab_focus(impldif_dlg.entryName); - errFlag = TRUE; - } - - if( ! errFlag ) { - /* Read attribute list */ - ldif_set_file( _ldifFile_, sFile ); - if( ldif_read_tags( _ldifFile_ ) == MGU_SUCCESS ) { - /* Load fields */ - /* ldif_print_file( _ldifFile_, stdout ); */ - imp_ldif_load_fields( _ldifFile_ ); - retVal = TRUE; - } - else { - sMsg = imp_ldif_err2string( _lutErrorsLDIF_, _ldifFile_->retVal ); - } - } - imp_ldif_status_show( sMsg ); - - return retVal; -} - -/** - * Display finish page. - */ -static void imp_ldif_finish_show() { - gchar *sMsg; - gchar *name; - - name = gtk_editable_get_chars( GTK_EDITABLE(impldif_dlg.entryName), 0, -1 ); - gtk_label_set_text( GTK_LABEL(impldif_dlg.labelBook), name ); - g_free( name ); - gtk_label_set_text( GTK_LABEL(impldif_dlg.labelFile), _ldifFile_->path ); - gtk_label_set_text( GTK_LABEL(impldif_dlg.labelRecords), itos( _ldifFile_->importCount ) ); - gtk_widget_set_sensitive( impldif_dlg.btnPrev, FALSE ); - gtk_widget_hide( impldif_dlg.btnNext ); - gtk_widget_show( impldif_dlg.btnProceed ); - gtk_widget_set_sensitive( impldif_dlg.btnProceed, FALSE ); - if( _ldifFile_->retVal == MGU_SUCCESS ) { - sMsg = _( "LDIF file imported successfully." ); - } - else { - sMsg = imp_ldif_err2string( _lutErrorsLDIF_, _ldifFile_->retVal ); - } - imp_ldif_status_show( sMsg ); - gtk_widget_grab_focus(impldif_dlg.btnCancel); -} - -/** - * Callback function to select previous page. - * \param widget Widget (button). - */ -static void imp_ldif_prev( GtkWidget *widget ) { - gint pageNum; - - pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(impldif_dlg.notebook) ); - if( pageNum == PAGE_ATTRIBUTES ) { - /* Goto file page stuff */ - gtk_notebook_set_current_page( - GTK_NOTEBOOK(impldif_dlg.notebook), PAGE_FILE_INFO ); - gtk_widget_set_sensitive( impldif_dlg.btnPrev, FALSE ); - gtk_widget_hide( impldif_dlg.btnProceed ); - gtk_widget_show( impldif_dlg.btnNext ); - } - imp_ldif_message(); -} - -/** - * Callback function to select next page. - * \param widget Widget (button). - */ -static void imp_ldif_next( GtkWidget *widget ) { - gint pageNum; - - pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(impldif_dlg.notebook) ); - if( pageNum == PAGE_FILE_INFO ) { - /* Goto attributes stuff */ - if( imp_ldif_file_move() ) { - gtk_notebook_set_current_page( - GTK_NOTEBOOK(impldif_dlg.notebook), PAGE_ATTRIBUTES ); - imp_ldif_message(); - gtk_widget_set_sensitive( impldif_dlg.btnPrev, TRUE ); - gtk_widget_hide( impldif_dlg.btnNext ); - gtk_widget_show( impldif_dlg.btnProceed ); - gtk_widget_set_sensitive( impldif_dlg.btnProceed, TRUE ); - } - else { - gtk_widget_set_sensitive( impldif_dlg.btnPrev, FALSE ); - _ldifFile_->dirtyFlag = TRUE; - } - } - else if( pageNum == PAGE_ATTRIBUTES ) { - /* Goto finish stuff */ - if( imp_ldif_field_move() ) { - gtk_notebook_set_current_page( - GTK_NOTEBOOK(impldif_dlg.notebook), PAGE_FINISH ); - gtk_button_set_label(GTK_BUTTON(impldif_dlg.btnCancel), - _("_Close")); - gtk_button_set_image(GTK_BUTTON(impldif_dlg.btnCancel), - gtk_image_new_from_icon_name("window-close-symbolic", GTK_ICON_SIZE_BUTTON)); - imp_ldif_finish_show(); - } - } -} - -/** - * Callback function to cancel and close dialog. - * \param widget Widget (button). - * \param data User data. - */ -static void imp_ldif_cancel( GtkWidget *widget, gpointer data ) { - gint pageNum; - - pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(impldif_dlg.notebook) ); - if( pageNum != PAGE_FINISH ) { - impldif_dlg.cancelled = TRUE; - } - gtk_main_quit(); -} - - -/** - * Create LDIF file selection dialog. - * \param afs Address file selection data. - */ -static void imp_ldif_file_select_create( AddressFileSelection *afs ) { - gchar *file = filesel_select_file_open(_("Select LDIF File"), NULL); - - if (file == NULL) - afs->cancelled = TRUE; - else { - afs->cancelled = FALSE; - gtk_entry_set_text( GTK_ENTRY(impldif_dlg.entryFile), file ); - g_free(file); - } -} - -/** - * Callback function to display LDIF file selection dialog. - */ -static void imp_ldif_file_select( void ) { - imp_ldif_file_select_create( & _imp_ldif_file_selector_ ); -} - -/** - * Callback function to handle dialog close event. - * \param widget Widget (dialog). - * \param event Event object. - * \param data User data. - */ -static gint imp_ldif_delete_event( GtkWidget *widget, GdkEventAny *event, gpointer data ) { - imp_ldif_cancel( widget, data ); - return TRUE; -} - -/** - * Callback function to respond to dialog key press events. - * \param widget Widget. - * \param event Event object. - * \param data User data. - */ -static gboolean imp_ldif_key_pressed( GtkWidget *widget, GdkEventKey *event, gpointer data ) { - if (event && event->keyval == GDK_KEY_Escape) { - imp_ldif_cancel( widget, data ); - } - return FALSE; -} - -/** - * Format notebook "file" page. - * \param pageNum Page (tab) number. - * \param pageLbl Page (tab) label. - */ -static void imp_ldif_page_file( gint pageNum, gchar *pageLbl ) { - GtkWidget *vbox; - GtkWidget *table; - GtkWidget *label; - GtkWidget *entryFile; - GtkWidget *entryName; - GtkWidget *btnFile; - - vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8); - gtk_container_add( GTK_CONTAINER( impldif_dlg.notebook ), vbox ); - gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH ); - - label = gtk_label_new( pageLbl ); - gtk_widget_show( label ); - gtk_notebook_set_tab_label( - GTK_NOTEBOOK( impldif_dlg.notebook ), - gtk_notebook_get_nth_page( - GTK_NOTEBOOK( impldif_dlg.notebook ), pageNum ), - label ); - - table = gtk_grid_new(); - gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); - gtk_container_set_border_width( GTK_CONTAINER(table), 8 ); - gtk_grid_set_row_spacing(GTK_GRID(table), 8); - gtk_grid_set_column_spacing(GTK_GRID(table), 8); - - /* First row */ - label = gtk_label_new(_("Address Book")); - gtk_label_set_xalign(GTK_LABEL(label), 0.0); - gtk_grid_attach(GTK_GRID(table), label, 0, 0, 1, 1); - - entryName = gtk_entry_new(); - gtk_grid_attach(GTK_GRID(table), entryName, 1, 0, 1, 1); - gtk_widget_set_hexpand(entryName, TRUE); - gtk_widget_set_halign(entryName, GTK_ALIGN_FILL); - - CLAWS_SET_TIP(entryName, _( - "Specify the name for the address book that will " \ - "be created from the LDIF file data." )); - - /* Second row */ - label = gtk_label_new(_("File Name")); - gtk_label_set_xalign(GTK_LABEL(label), 0.0); - gtk_grid_attach(GTK_GRID(table), label, 0, 1, 1, 1); - - entryFile = gtk_entry_new(); - gtk_grid_attach(GTK_GRID(table), entryFile, 1, 1, 1, 1); - gtk_widget_set_hexpand(entryFile, TRUE); - gtk_widget_set_halign(entryFile, GTK_ALIGN_FILL); - - CLAWS_SET_TIP(entryFile, - _( "The full file specification of the LDIF file to import." )); - - btnFile = gtkut_get_browse_file_btn(_("B_rowse")); - gtk_grid_attach(GTK_GRID(table), btnFile, 2, 1, 1, 1); - - CLAWS_SET_TIP(btnFile, - _( "Select the LDIF file to import." )); - - gtk_widget_show_all(vbox); - - /* Button handler */ - g_signal_connect(G_OBJECT(btnFile), "clicked", - G_CALLBACK(imp_ldif_file_select), NULL); - - impldif_dlg.entryFile = entryFile; - impldif_dlg.entryName = entryName; - -} - -static void imp_ldif_field_list_cursor_changed(GtkTreeView *view, - gpointer user_data) -{ - Ldif_FieldRec *rec; - - gtk_entry_set_text( GTK_ENTRY(impldif_dlg.entryAttrib), "" ); - - rec = gtkut_tree_view_get_selected_pointer(view, FIELD_COL_PTR, - NULL, NULL, NULL); - - if( rec != NULL) { - /* Update widget contents */ - gtk_label_set_text( - GTK_LABEL(impldif_dlg.entryField), rec->tagName ); - if( rec->userName ) - gtk_entry_set_text( - GTK_ENTRY(impldif_dlg.entryAttrib), rec->userName ); - gtk_toggle_button_set_active( - GTK_TOGGLE_BUTTON(impldif_dlg.checkSelect), - rec->selected ); - - /* Disable widgets for reserved fields */ - gtk_widget_set_sensitive( - impldif_dlg.entryAttrib, ! rec->reserved ); - gtk_widget_set_sensitive( - impldif_dlg.checkSelect, ! rec->reserved ); - gtk_widget_set_sensitive( - impldif_dlg.btnModify, ! rec->reserved ); - } - gtk_widget_grab_focus(impldif_dlg.entryAttrib); -} - -static void imp_ldif_field_list_row_activated(GtkTreeView *view, - GtkTreePath *path, GtkTreeViewColumn *col, - gpointer user_data) -{ - GtkTreeModel *model = gtk_tree_view_get_model(view); - GtkTreeIter iter; - gboolean ok; - Ldif_FieldRec *rec; - - ok = gtk_tree_model_get_iter(model, &iter, path); - if (!ok) { - return; /* Huh? */ - } - - gtk_tree_model_get(model, &iter, FIELD_COL_PTR, &rec, -1); - cm_return_if_fail(rec != NULL); - - /* Flip the "selected" state for the record, and update the - * "selected" column in the list view, as well as the - * "selected" checkbox. */ - ldif_field_toggle(rec); - gtk_list_store_set(GTK_LIST_STORE(model), &iter, - FIELD_COL_SELECT, rec->selected ? markxpm : NULL, -1); - gtk_toggle_button_set_active( - GTK_TOGGLE_BUTTON(impldif_dlg.checkSelect), - rec->selected ); -} - -/** - * Format notebook fields page. - * \param pageNum Page (tab) number. - * \param pageLbl Page (tab) label. - */ -static void imp_ldif_page_fields( gint pageNum, gchar *pageLbl ) { - GtkWidget *vbox; - GtkWidget *vboxt; - GtkWidget *vboxb; - GtkWidget *table; - GtkWidget *label; - GtkWidget *scrollwin; - GtkWidget *view_fields; - GtkWidget *entryField; - GtkWidget *entryAttrib; - GtkWidget *checkSelect; - GtkWidget *btnModify; - GtkWidget *eventBox; - GtkListStore *store; - GtkCellRenderer *rdr; - GtkTreeViewColumn *col; - GtkTreeSelection *sel; - - vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8); - gtk_container_add( GTK_CONTAINER( impldif_dlg.notebook ), vbox ); - gtk_container_set_border_width( GTK_CONTAINER (vbox), 4 ); - - label = gtk_label_new( pageLbl ); - gtk_widget_show( label ); - gtk_notebook_set_tab_label( - GTK_NOTEBOOK( impldif_dlg.notebook ), - gtk_notebook_get_nth_page(GTK_NOTEBOOK( impldif_dlg.notebook ), pageNum ), - label ); - - /* Upper area - Field list */ - vboxt = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4 ); - gtk_container_add( GTK_CONTAINER( vbox ), vboxt ); - - scrollwin = gtk_scrolled_window_new( NULL, NULL ); - gtk_container_add( GTK_CONTAINER(vboxt), scrollwin ); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - - store = gtk_list_store_new(FIELDS_N_COLS, - GDK_TYPE_PIXBUF, GDK_TYPE_PIXBUF, - G_TYPE_STRING, G_TYPE_STRING, - G_TYPE_POINTER, - -1); - - view_fields = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); - g_object_unref(store); - gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view_fields), TRUE); - gtk_tree_view_set_reorderable(GTK_TREE_VIEW(view_fields), FALSE); - sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(view_fields)); - gtk_tree_selection_set_mode(sel, GTK_SELECTION_BROWSE); - - rdr = gtk_cell_renderer_pixbuf_new(); - col = gtk_tree_view_column_new_with_attributes(_("R"), rdr, - "pixbuf", FIELD_COL_RESERVED, NULL); - gtk_tree_view_column_set_min_width(col, FIELD_COL_RESERVED); - gtk_tree_view_append_column(GTK_TREE_VIEW(view_fields), col); - - col = gtk_tree_view_column_new_with_attributes(_("S"), rdr, - "pixbuf", FIELD_COL_SELECT, NULL); - gtk_tree_view_column_set_min_width(col, FIELD_COL_SELECT); - gtk_tree_view_append_column(GTK_TREE_VIEW(view_fields), col); - - rdr = gtk_cell_renderer_text_new(); - col = gtk_tree_view_column_new_with_attributes(_("LDIF Field Name"), rdr, - "markup", FIELD_COL_FIELD, NULL); - gtk_tree_view_column_set_min_width(col, FIELD_COL_FIELD); - gtk_tree_view_append_column(GTK_TREE_VIEW(view_fields), col); - - col = gtk_tree_view_column_new_with_attributes(_("Attribute Name"), rdr, - "markup", FIELD_COL_ATTRIB, NULL); - gtk_tree_view_column_set_min_width(col, FIELD_COL_ATTRIB); - gtk_tree_view_append_column(GTK_TREE_VIEW(view_fields), col); - - gtk_container_add( GTK_CONTAINER(scrollwin), view_fields ); - - /* Lower area - Edit area */ - vboxb = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4 ); - gtk_box_pack_end(GTK_BOX(vbox), vboxb, FALSE, FALSE, 2); - - /* Data entry area */ - table = gtk_grid_new(); - gtk_box_pack_start(GTK_BOX(vboxb), table, FALSE, FALSE, 0); - gtk_grid_set_row_spacing(GTK_GRID(table), 4); - gtk_grid_set_column_spacing(GTK_GRID(table), 4); - - /* First row */ - label = gtk_label_new(_("LDIF Field")); - gtk_label_set_xalign(GTK_LABEL(label), 0.0); - gtk_grid_attach(GTK_GRID(table), label, 0, 0, 1, 1); - - entryField = gtk_label_new( "" ); - gtk_label_set_xalign(GTK_LABEL(entryField), 0.0); - gtk_grid_attach(GTK_GRID(table), entryField, 1, 0, 1, 1); - gtk_widget_set_hexpand(entryField, TRUE); - gtk_widget_set_halign(entryField, GTK_ALIGN_FILL); - - /* Second row */ - label = gtk_label_new(_("Attribute")); - /* - * Use an event box to attach some help in the form of a tooltip. - * Tried this for the clist but it looked bad. - */ - eventBox = gtk_event_box_new(); - gtk_container_add( GTK_CONTAINER(eventBox), label ); - gtk_label_set_xalign(GTK_LABEL(label), 0.0); - gtk_grid_attach(GTK_GRID(table), eventBox, 0, 1, 1, 1); - - CLAWS_SET_TIP(eventBox, _( - "Choose the LDIF field that will be renamed or selected " \ - "for import in the list above. Reserved fields (marked " \ - "with a tick in the \"R\" column), are automatically " \ - "imported and cannot be renamed. A single click in the " \ - "Select (\"S\") column will select the field for import " \ - "with a tick. A single click anywhere in the row will " \ - "select that field for rename in the input area below " \ - "the list. A double click anywhere in the row will also " \ - "select the field for import.")); - - entryAttrib = gtk_entry_new(); - gtk_grid_attach(GTK_GRID(table), entryAttrib, 1, 1, 1, 1); - gtk_widget_set_hexpand(entryAttrib, TRUE); - gtk_widget_set_halign(entryAttrib, GTK_ALIGN_FILL); - - CLAWS_SET_TIP(entryAttrib, - _( "The LDIF field can be renamed to the User Attribute name." )); - - /* Next row */ - checkSelect = gtk_check_button_new_with_label( _( "Select for Import" ) ); - gtk_grid_attach(GTK_GRID(table), checkSelect, 1, 2, 1, 1); - - CLAWS_SET_TIP(checkSelect, - _( "Select the LDIF field for import into the address book." )); - - btnModify = gtk_button_new_with_label( _(" Modify ")); - gtk_grid_attach(GTK_GRID(table), btnModify, 2, 2, 1, 1); - - CLAWS_SET_TIP(btnModify, - _( "This button will update the list above with the data supplied." )); - - gtk_widget_show_all(vbox); - - /* Event handlers */ - g_signal_connect(G_OBJECT(view_fields), "cursor-changed", - G_CALLBACK(imp_ldif_field_list_cursor_changed), NULL); - g_signal_connect(G_OBJECT(view_fields), "row-activated", - G_CALLBACK(imp_ldif_field_list_row_activated), NULL); - g_signal_connect(G_OBJECT(btnModify), "clicked", - G_CALLBACK(imp_ldif_modify_pressed), NULL ); - g_signal_connect(G_OBJECT(entryAttrib), "activate", - G_CALLBACK(imp_ldif_entryattrib_activate), NULL); - - impldif_dlg.view_fields = view_fields; - impldif_dlg.entryField = entryField; - impldif_dlg.entryAttrib = entryAttrib; - impldif_dlg.checkSelect = checkSelect; - impldif_dlg.btnModify = btnModify; -} - -/** - * Format notebook finish page. - * \param pageNum Page (tab) number. - * \param pageLbl Page (tab) label. - */ -static void imp_ldif_page_finish( gint pageNum, gchar *pageLbl ) { - GtkWidget *vbox; - GtkWidget *table; - GtkWidget *label; - GtkWidget *labelBook; - GtkWidget *labelFile; - GtkWidget *labelRecs; - - vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8); - gtk_container_add( GTK_CONTAINER( impldif_dlg.notebook ), vbox ); - gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH ); - - label = gtk_label_new( pageLbl ); - gtk_widget_show( label ); - gtk_notebook_set_tab_label( - GTK_NOTEBOOK( impldif_dlg.notebook ), - gtk_notebook_get_nth_page( GTK_NOTEBOOK( impldif_dlg.notebook ), pageNum ), - label ); - - table = gtk_grid_new(); - gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); - gtk_container_set_border_width( GTK_CONTAINER(table), 8 ); - gtk_grid_set_row_spacing(GTK_GRID(table), 8); - gtk_grid_set_column_spacing(GTK_GRID(table), 8); - - /* First row */ - label = gtk_label_new( _( "Address Book:" ) ); - gtk_label_set_xalign(GTK_LABEL(label), 1.0); - gtk_grid_attach(GTK_GRID(table), label, 0, 0, 1, 1); - - labelBook = gtk_label_new(""); - gtk_label_set_xalign(GTK_LABEL(labelBook), 0.0); - gtk_grid_attach(GTK_GRID(table), labelBook, 1, 0, 1, 1); - - /* Second row */ - label = gtk_label_new( _( "File Name:" ) ); - gtk_label_set_xalign(GTK_LABEL(label), 1.0); - gtk_grid_attach(GTK_GRID(table), label, 0, 1, 1, 1); - - labelFile = gtk_label_new(""); - gtk_label_set_xalign(GTK_LABEL(labelFile), 0.0); - gtk_grid_attach(GTK_GRID(table), labelFile, 1, 1, 1, 1); - - /* Third row */ - label = gtk_label_new( _("Records Imported:") ); - gtk_label_set_xalign(GTK_LABEL(label), 1.0); - gtk_grid_attach(GTK_GRID(table), label, 0, 2, 1, 1); - - labelRecs = gtk_label_new(""); - gtk_label_set_xalign(GTK_LABEL(labelRecs), 0.0); - gtk_grid_attach(GTK_GRID(table), labelRecs, 1, 2, 1, 1); - - impldif_dlg.labelBook = labelBook; - impldif_dlg.labelFile = labelFile; - impldif_dlg.labelRecords = labelRecs; -} - -/** - * Create main dialog decorations (excluding notebook pages). - */ -static void imp_ldif_dialog_create() { - GtkWidget *window; - GtkWidget *vbox; - GtkWidget *vnbox; - GtkWidget *notebook; - GtkWidget *hbbox; - GtkWidget *btnPrev; - GtkWidget *btnNext; - GtkWidget *btnProceed; - GtkWidget *btnCancel; - GtkWidget *hsbox; - GtkWidget *statusbar; - - window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "importldif"); - gtk_widget_set_size_request(window, IMPORTLDIF_WIDTH, IMPORTLDIF_HEIGHT ); - gtk_container_set_border_width( GTK_CONTAINER(window), 0 ); - gtk_window_set_title( GTK_WINDOW(window), _("Import LDIF file into Address Book") ); - gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); - gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DIALOG); - g_signal_connect(G_OBJECT(window), "delete_event", - G_CALLBACK(imp_ldif_delete_event), - NULL ); - g_signal_connect(G_OBJECT(window), "key_press_event", - G_CALLBACK(imp_ldif_key_pressed), - NULL ); - - vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4); - gtk_widget_show(vbox); - gtk_container_add(GTK_CONTAINER(window), vbox); - - vnbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4); - gtk_container_set_border_width(GTK_CONTAINER(vnbox), 4); - gtk_widget_show(vnbox); - gtk_box_pack_start(GTK_BOX(vbox), vnbox, TRUE, TRUE, 0); - - /* Notebook */ - notebook = gtk_notebook_new(); - gtk_notebook_set_show_tabs( GTK_NOTEBOOK(notebook), FALSE ); - gtk_widget_show(notebook); - gtk_box_pack_start(GTK_BOX(vnbox), notebook, TRUE, TRUE, 0); - gtk_container_set_border_width(GTK_CONTAINER(notebook), 6); - - /* Status line */ - hsbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); - gtk_box_pack_end(GTK_BOX(vbox), hsbox, FALSE, FALSE, BORDER_WIDTH); - statusbar = gtk_statusbar_new(); - gtk_box_pack_start(GTK_BOX(hsbox), statusbar, TRUE, TRUE, BORDER_WIDTH); - - /* Button panel */ - gtkut_stock_button_set_create(&hbbox, - &btnPrev, "go-previous", _("_Previous"), - &btnNext, "go-next", _("_Next"), - &btnCancel, NULL, _("_Cancel")); - - btnProceed = gtk_button_new_with_mnemonic(_("Proceed")); - gtk_widget_set_can_default(btnProceed, TRUE); - gtk_box_pack_start(GTK_BOX(hbbox), btnProceed, TRUE, TRUE, 0); - gtk_widget_hide(btnProceed); - - gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0); - gtk_container_set_border_width(GTK_CONTAINER(hbbox), 2); - gtk_widget_grab_default(btnNext); - - /* Button handlers */ - g_signal_connect(G_OBJECT(btnPrev), "clicked", - G_CALLBACK(imp_ldif_prev), NULL); - g_signal_connect(G_OBJECT(btnNext), "clicked", - G_CALLBACK(imp_ldif_next), NULL); - g_signal_connect(G_OBJECT(btnProceed), "clicked", - G_CALLBACK(imp_ldif_next), NULL); - g_signal_connect(G_OBJECT(btnCancel), "clicked", - G_CALLBACK(imp_ldif_cancel), NULL); - - gtk_widget_show_all(vbox); - - impldif_dlg.window = window; - impldif_dlg.notebook = notebook; - impldif_dlg.btnPrev = btnPrev; - impldif_dlg.btnNext = btnNext; - impldif_dlg.btnProceed = btnProceed; - impldif_dlg.btnCancel = btnCancel; - impldif_dlg.statusbar = statusbar; - impldif_dlg.status_cid = gtk_statusbar_get_context_id( - GTK_STATUSBAR(statusbar), "Import LDIF Dialog" ); - -} - -/** - * Create import LDIF dialog. - */ -static void imp_ldif_create() { - imp_ldif_dialog_create(); - imp_ldif_page_file( PAGE_FILE_INFO, _( "File Info" ) ); - imp_ldif_page_fields( PAGE_ATTRIBUTES, _( "Attributes" ) ); - imp_ldif_page_finish( PAGE_FINISH, _( "Finish" ) ); - gtk_widget_show_all( impldif_dlg.window ); -} - -/** - * Import LDIF file. - * \param addrIndex Address index. - * \return Address book file of imported data, or <i>NULL</i> if import - * was cancelled. - */ -AddressBookFile *addressbook_imp_ldif( AddressIndex *addrIndex ) { - GtkWidget *view; - GtkTreeModel *model; - - _importedBook_ = NULL; - _imp_addressIndex_ = addrIndex; - - if( ! impldif_dlg.window ) - imp_ldif_create(); - - view = impldif_dlg.view_fields; - model = gtk_tree_view_get_model(GTK_TREE_VIEW(view)); - - gtk_button_set_label(GTK_BUTTON(impldif_dlg.btnCancel), - _("_Cancel")); - gtk_widget_hide(impldif_dlg.btnProceed); - gtk_widget_show(impldif_dlg.btnNext); - - impldif_dlg.cancelled = FALSE; - gtk_widget_show(impldif_dlg.window); - manage_window_set_transient(GTK_WINDOW(impldif_dlg.window)); - gtk_widget_grab_default(impldif_dlg.btnNext); - gtk_window_set_modal(GTK_WINDOW(impldif_dlg.window), TRUE); - - gtk_entry_set_text( GTK_ENTRY(impldif_dlg.entryName), IMPORTLDIF_GUESS_NAME ); - gtk_entry_set_text( GTK_ENTRY(impldif_dlg.entryFile), "" ); - gtk_label_set_text( GTK_LABEL(impldif_dlg.entryField), "" ); - gtk_entry_set_text( GTK_ENTRY(impldif_dlg.entryAttrib), "" ); - gtk_list_store_clear( GTK_LIST_STORE(model) ); - gtk_notebook_set_current_page( GTK_NOTEBOOK(impldif_dlg.notebook), PAGE_FILE_INFO ); - gtk_widget_set_sensitive( impldif_dlg.btnPrev, FALSE ); - gtk_widget_set_sensitive( impldif_dlg.btnNext, TRUE ); - stock_pixbuf_gdk(STOCK_PIXMAP_MARK, &markxpm ); - imp_ldif_message(); - gtk_widget_grab_focus(impldif_dlg.entryFile); - - impldif_dlg.rowCount = 0; - g_free( impldif_dlg.nameBook ); - g_free( impldif_dlg.fileName ); - impldif_dlg.nameBook = NULL; - impldif_dlg.fileName = NULL; - - _ldifFile_ = ldif_create(); - gtk_main(); - gtk_widget_hide(impldif_dlg.window); - gtk_window_set_modal(GTK_WINDOW(impldif_dlg.window), FALSE); - ldif_free( _ldifFile_ ); - _ldifFile_ = NULL; - _imp_addressIndex_ = NULL; - - g_free( impldif_dlg.nameBook ); - g_free( impldif_dlg.fileName ); - impldif_dlg.nameBook = NULL; - impldif_dlg.fileName = NULL; - - if( impldif_dlg.cancelled == TRUE ) return NULL; - return _importedBook_; -} - -/* - * ============================================================================ - * End of Source. - * ============================================================================ - */ - diff --git a/src/importldif.h b/src/importldif.h @@ -1,34 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2001-2012 Match Grun and the Claws Mail team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -/* - * Import LDIF data. - */ - -#ifndef __IMPORT_LDIF_H__ -#define __IMPORT_LDIF_H__ - -/* Function prototypes */ -AddressBookFile *addressbook_imp_ldif( AddressIndex *addrIndex ); - -#endif /* __IMPORT_LDIF_H__ */ - -/* -* End of Source. -*/ diff --git a/src/jpilot.c b/src/jpilot.c @@ -1,1668 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2001-2015 Match Grun and the Claws Mail team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * Functions necessary to access JPilot database files. - * JPilot is Copyright(c) by Judd Montgomery. - * Visit http://www.jpilot.org for more details. - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#include "claws-features.h" -#endif - -#ifdef USE_JPILOT - -#include <glib.h> -#include <time.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/stat.h> -#include <netinet/in.h> - -#ifdef HAVE_LIBPISOCK_PI_ARGS_H -# include <libpisock/pi-args.h> -# include <libpisock/pi-appinfo.h> -# include <libpisock/pi-address.h> -# include <libpisock/pi-version.h> -#else -# include <pi-args.h> -# include <pi-appinfo.h> -# include <pi-address.h> -# include <pi-version.h> -#endif - -#include "mgutils.h" -#include "addritem.h" -#include "addrcache.h" -#include "jpilot.h" -#include "codeconv.h" -#include "adbookbase.h" -#include "utils.h" -#include "file-utils.h" - -#define JPILOT_DBHOME_DIR ".jpilot" -#define JPILOT_DBHOME_FILE "AddressDB.pdb" -#define PILOT_LINK_LIB_NAME "libpisock.so" - -#define IND_LABEL_LASTNAME 0 /* Index of last name in address data */ -#define IND_LABEL_FIRSTNAME 1 /* Index of first name in address data */ -#define IND_PHONE_EMAIL 4 /* Index of E-Mail address in phone labels */ -#define OFFSET_PHONE_LABEL 3 /* Offset to phone data in address data */ -#define IND_CUSTOM_LABEL 14 /* Offset to custom label names */ -#define NUM_CUSTOM_LABEL 4 /* Number of custom labels */ - -/* Shamelessly copied from JPilot (libplugin.h) */ -typedef struct { - unsigned char db_name[32]; - unsigned char flags[2]; - unsigned char version[2]; - unsigned char creation_time[4]; - unsigned char modification_time[4]; - unsigned char backup_time[4]; - unsigned char modification_number[4]; - unsigned char app_info_offset[4]; - unsigned char sort_info_offset[4]; - unsigned char type[4];/*Database ID */ - unsigned char creator_id[4];/*Application ID */ - unsigned char unique_id_seed[4]; - unsigned char next_record_list_id[4]; - unsigned char number_of_records[2]; -} RawDBHeader; - -/* Shamelessly copied from JPilot (libplugin.h) */ -typedef struct { - char db_name[32]; - unsigned int flags; - unsigned int version; - time_t creation_time; - time_t modification_time; - time_t backup_time; - unsigned int modification_number; - unsigned int app_info_offset; - unsigned int sort_info_offset; - char type[5];/*Database ID */ - char creator_id[5];/*Application ID */ - char unique_id_seed[5]; - unsigned int next_record_list_id; - unsigned int number_of_records; -} DBHeader; - -/* Shamelessly copied from JPilot (libplugin.h) */ -typedef struct { - unsigned char Offset[4]; /*4 bytes offset from BOF to record */ - unsigned char attrib; - unsigned char unique_ID[3]; -} record_header; - -/* Shamelessly copied from JPilot (libplugin.h) */ -typedef struct mem_rec_header_s { - unsigned int rec_num; - unsigned int offset; - unsigned int unique_id; - unsigned char attrib; - struct mem_rec_header_s *next; -} mem_rec_header; - -/* Shamelessly copied from JPilot (libplugin.h) */ -#define SPENT_PC_RECORD_BIT 256 - -typedef enum { - PALM_REC = 100L, - MODIFIED_PALM_REC = 101L, - DELETED_PALM_REC = 102L, - NEW_PC_REC = 103L, - DELETED_PC_REC = SPENT_PC_RECORD_BIT + 104L, - DELETED_DELETED_PALM_REC = SPENT_PC_RECORD_BIT + 105L -} PCRecType; - -/* Shamelessly copied from JPilot (libplugin.h) */ -typedef struct { - PCRecType rt; - unsigned int unique_id; - unsigned char attrib; - void *buf; - int size; -} buf_rec; - -/* Shamelessly copied from JPilot (libplugin.h) */ -typedef struct { - unsigned long header_len; - unsigned long header_version; - unsigned long rec_len; - unsigned long unique_id; - unsigned long rt; /* Record Type */ - unsigned char attrib; -} PC3RecordHeader; - -enum { - FAMILY_LAST = 0, - FAMILY_FIRST = 1 -} name_order; - -gboolean convert_charcode = TRUE; - -static const gchar *jpilot_get_charset(void) -{ - static const gchar *charset = NULL; - - if (charset == NULL) - charset = g_getenv("PILOT_CHARSET"); - - if (charset == NULL) - charset = CS_CP1252; - - return charset; -} - -/* -* Create new pilot file object. -* \return Initialized JPilot file object. -*/ -JPilotFile *jpilot_create() { - JPilotFile *pilotFile; - pilotFile = g_new0( JPilotFile, 1 ); - pilotFile->type = ADBOOKTYPE_JPILOT; - pilotFile->addressCache = addrcache_create(); - pilotFile->retVal = MGU_SUCCESS; - - pilotFile->file = NULL; - pilotFile->path = NULL; - pilotFile->readMetadata = FALSE; - pilotFile->customLabels = NULL; - pilotFile->labelInd = NULL; - pilotFile->havePC3 = FALSE; - pilotFile->pc3ModifyTime = 0; - return pilotFile; -} - -/** - * Create new pilot file object for specified file. - * \param path Path to JPilot address book. - * \return Initialized JPilot file object. - */ -JPilotFile *jpilot_create_path( const gchar *path ) { - JPilotFile *pilotFile; - pilotFile = jpilot_create(); - jpilot_set_file( pilotFile, path ); - return pilotFile; -} - -/* -* Properties... -*/ -void jpilot_set_name( JPilotFile* pilotFile, const gchar *value ) { - cm_return_if_fail( pilotFile != NULL ); - addrcache_set_name( pilotFile->addressCache, value ); -} -void jpilot_set_file( JPilotFile* pilotFile, const gchar *value ) { - cm_return_if_fail( pilotFile != NULL ); - addrcache_refresh( pilotFile->addressCache ); - pilotFile->readMetadata = FALSE; - pilotFile->path = mgu_replace_string( pilotFile->path, value ); -} -void jpilot_set_accessed( JPilotFile *pilotFile, const gboolean value ) { - cm_return_if_fail( pilotFile != NULL ); - pilotFile->addressCache->accessFlag = value; -} - -gint jpilot_get_status( JPilotFile *pilotFile ) { - cm_return_val_if_fail( pilotFile != NULL, -1 ); - return pilotFile->retVal; -} -ItemFolder *jpilot_get_root_folder( JPilotFile *pilotFile ) { - cm_return_val_if_fail( pilotFile != NULL, NULL ); - return addrcache_get_root_folder( pilotFile->addressCache ); -} -gchar *jpilot_get_name( JPilotFile *pilotFile ) { - cm_return_val_if_fail( pilotFile != NULL, NULL ); - return addrcache_get_name( pilotFile->addressCache ); -} - -/* - * Test whether file was read. - * \param pilotFile JPilot control data. - * \return <i>TRUE</i> if file was read. - */ -gboolean jpilot_get_read_flag( JPilotFile *pilotFile ) { - cm_return_val_if_fail( pilotFile != NULL, FALSE ); - return pilotFile->addressCache->dataRead; -} - -/** - * Free up custom label list. - * \param pilotFile JPilot control data. - */ -void jpilot_clear_custom_labels( JPilotFile *pilotFile ) { - GList *node; - - cm_return_if_fail( pilotFile != NULL ); - - /* Release custom labels */ - g_list_free_full( pilotFile->customLabels, g_free ); - pilotFile->customLabels = NULL; - - /* Release indexes */ - node = pilotFile->labelInd; - while( node ) { - node->data = NULL; - node = g_list_next( node ); - } - g_list_free( pilotFile->labelInd ); - pilotFile->labelInd = NULL; - - /* Force a fresh read */ - addrcache_refresh( pilotFile->addressCache ); -} - -/** - * Append a custom label, representing an E-Mail address field to the - * custom label list. - * \param pilotFile JPilot control data. - */ -void jpilot_add_custom_label( JPilotFile *pilotFile, const gchar *labelName ) { - cm_return_if_fail( pilotFile != NULL ); - - if( labelName ) { - gchar *labelCopy = g_strdup( labelName ); - g_strstrip( labelCopy ); - if( *labelCopy == '\0' ) { - g_free( labelCopy ); - } - else { - pilotFile->customLabels = g_list_append( pilotFile->customLabels, labelCopy ); - /* Force a fresh read */ - addrcache_refresh( pilotFile->addressCache ); - } - } -} - -/** - * Get list of custom labels. - * \param pilotFile JPilot control data. - * \return List of labels. Must use g_free() when done. - */ -GList *jpilot_get_custom_labels( JPilotFile *pilotFile ) { - GList *retVal = NULL; - GList *node; - - cm_return_val_if_fail( pilotFile != NULL, NULL ); - - node = pilotFile->customLabels; - while( node ) { - retVal = g_list_append( retVal, g_strdup( node->data ) ); - node = g_list_next( node ); - } - return retVal; -} - -/** - * Return filespec of PC3 file corresponding to JPilot PDB file. - * \param pilotFile JPilot control data. - * \return File specification; should be g_free() when done. - */ -static gchar *jpilot_get_pc3_file( JPilotFile *pilotFile ) { - gchar *fileSpec, *r; - gint i, len, pos; - - if( pilotFile == NULL ) return NULL; - if( pilotFile->path == NULL ) return NULL; - - fileSpec = g_strdup( pilotFile->path ); - len = strlen( fileSpec ); - pos = -1; - r = NULL; - for( i = len; i > 0; i-- ) { - if( *(fileSpec + i) == '.' ) { - pos = i + 1; - r = fileSpec + pos; - break; - } - } - if( r ) { - if( len - pos == 3 ) { - *r++ = 'p'; *r++ = 'c'; *r = '3'; - return fileSpec; - } - } - g_free( fileSpec ); - return NULL; -} - -/** - * Save PC3 file time to cache. - * \param pilotFile JPilot control data. - * \return <i>TRUE</i> if time marked. - */ -static gboolean jpilot_mark_files( JPilotFile *pilotFile ) { - gboolean retVal = FALSE; - GStatBuf filestat; - gchar *pcFile; - - /* Mark PDB file cache */ - retVal = addrcache_mark_file( pilotFile->addressCache, pilotFile->path ); - - /* Now mark PC3 file */ - pilotFile->havePC3 = FALSE; - pilotFile->pc3ModifyTime = 0; - pcFile = jpilot_get_pc3_file( pilotFile ); - if( pcFile == NULL ) return retVal; - if( 0 == g_stat( pcFile, &filestat ) ) { - pilotFile->havePC3 = TRUE; - pilotFile->pc3ModifyTime = filestat.st_mtime; - retVal = TRUE; - } - g_free( pcFile ); - return retVal; -} - -/** - * Check whether JPilot PDB or PC3 file has changed by comparing - * with cached data. - * \param pilotFile JPilot control data. - * \return <i>TRUE</i> if file has changed. - */ -static gboolean jpilot_check_files( JPilotFile *pilotFile ) { - gboolean retVal = TRUE; - GStatBuf filestat; - gchar *pcFile; - - /* Check main file */ - if( addrcache_check_file( pilotFile->addressCache, pilotFile->path ) ) - return TRUE; - - /* Test PC3 file */ - if( ! pilotFile->havePC3 ) return FALSE; - pcFile = jpilot_get_pc3_file( pilotFile ); - if( pcFile == NULL ) return FALSE; - - if( 0 == g_stat( pcFile, &filestat ) ) { - if( filestat.st_mtime == pilotFile->pc3ModifyTime ) retVal = FALSE; - } - g_free( pcFile ); - return retVal; -} - -/* -* Test whether file was modified since last access. -* Return: TRUE if file was modified. -*/ -gboolean jpilot_get_modified( JPilotFile *pilotFile ) { - cm_return_val_if_fail( pilotFile != NULL, FALSE ); - pilotFile->addressCache->modified = jpilot_check_files( pilotFile ); - return pilotFile->addressCache->modified; -} -gboolean jpilot_get_accessed( JPilotFile *pilotFile ) { - cm_return_val_if_fail( pilotFile != NULL, FALSE ); - return pilotFile->addressCache->accessFlag; -} - -/** - * Free up pilot file object by releasing internal memory. - * \param pilotFile JPilot control data. - */ -void jpilot_free( JPilotFile *pilotFile ) { - cm_return_if_fail( pilotFile != NULL ); - - /* Release custom labels */ - jpilot_clear_custom_labels( pilotFile ); - - /* Clear cache */ - addrcache_clear( pilotFile->addressCache ); - addrcache_free( pilotFile->addressCache ); - - /* Free internal stuff */ - g_free( pilotFile->path ); - - pilotFile->file = NULL; - pilotFile->path = NULL; - pilotFile->readMetadata = FALSE; - pilotFile->havePC3 = FALSE; - pilotFile->pc3ModifyTime = 0; - - pilotFile->type = ADBOOKTYPE_NONE; - pilotFile->addressCache = NULL; - pilotFile->retVal = MGU_SUCCESS; - - /* Now release file object */ - g_free( pilotFile ); -} - -/* Shamelessly copied from JPilot (libplugin.c) */ -static unsigned int bytes_to_bin(unsigned char *bytes, unsigned int num_bytes) { -unsigned int i, n; - n=0; - for (i=0;i<num_bytes;i++) { - n = n*256+bytes[i]; - } - return n; -} - -/* Shamelessly copied from JPilot (utils.c) */ -/* These next 2 functions were copied from pi-file.c in the pilot-link app */ -/* Exact value of "Jan 1, 1970 0:00:00 GMT" - "Jan 1, 1904 0:00:00 GMT" */ -#define PILOT_TIME_DELTA (unsigned)(2082844800) - -static time_t pilot_time_to_unix_time ( unsigned long raw_time ) { - return (time_t)(raw_time - PILOT_TIME_DELTA); -} - -/* Shamelessly copied from JPilot (libplugin.c) */ -static int raw_header_to_header(RawDBHeader *rdbh, DBHeader *dbh) { - unsigned long temp; - - strncpy(dbh->db_name, rdbh->db_name, 31); - dbh->db_name[31] = '\0'; - dbh->flags = bytes_to_bin(rdbh->flags, 2); - dbh->version = bytes_to_bin(rdbh->version, 2); - temp = bytes_to_bin(rdbh->creation_time, 4); - dbh->creation_time = pilot_time_to_unix_time(temp); - temp = bytes_to_bin(rdbh->modification_time, 4); - dbh->modification_time = pilot_time_to_unix_time(temp); - temp = bytes_to_bin(rdbh->backup_time, 4); - dbh->backup_time = pilot_time_to_unix_time(temp); - dbh->modification_number = bytes_to_bin(rdbh->modification_number, 4); - dbh->app_info_offset = bytes_to_bin(rdbh->app_info_offset, 4); - dbh->sort_info_offset = bytes_to_bin(rdbh->sort_info_offset, 4); - strncpy(dbh->type, rdbh->type, 4); - dbh->type[4] = '\0'; - strncpy(dbh->creator_id, rdbh->creator_id, 4); - dbh->creator_id[4] = '\0'; - strncpy(dbh->unique_id_seed, rdbh->unique_id_seed, 4); - dbh->unique_id_seed[4] = '\0'; - dbh->next_record_list_id = bytes_to_bin(rdbh->next_record_list_id, 4); - dbh->number_of_records = bytes_to_bin(rdbh->number_of_records, 2); - return 0; -} - -/* Shamelessly copied from JPilot (libplugin.c) */ -/* returns 1 if found */ -/* 0 if eof */ -static int find_next_offset( mem_rec_header *mem_rh, long fpos, - unsigned int *next_offset, unsigned char *attrib, unsigned int *unique_id ) -{ - mem_rec_header *temp_mem_rh; - unsigned char found = 0; - unsigned long found_at; - - found_at=0xFFFFFF; - for (temp_mem_rh=mem_rh; temp_mem_rh; temp_mem_rh = temp_mem_rh->next) { - if ((temp_mem_rh->offset > fpos) && (temp_mem_rh->offset < found_at)) { - found_at = temp_mem_rh->offset; - /* *attrib = temp_mem_rh->attrib; */ - /* *unique_id = temp_mem_rh->unique_id; */ - } - if (temp_mem_rh->offset == fpos) { - found = 1; - *attrib = temp_mem_rh->attrib; - *unique_id = temp_mem_rh->unique_id; - } - } - *next_offset = found_at; - return found; -} - -/* Shamelessly copied from JPilot (libplugin.c) */ -static void free_mem_rec_header(mem_rec_header **mem_rh) { - mem_rec_header *h, *next_h; - for (h=*mem_rh; h; h=next_h) { - next_h=h->next; - free(h); - } - *mem_rh = NULL; -} - -/* Shamelessly copied from JPilot (libplugin.c) */ -/* Read file size */ -static int jpilot_get_info_size( FILE *in, int *size ) { - RawDBHeader rdbh; - DBHeader dbh; - unsigned int offset; - record_header rh; - int r; - - fseek(in, 0, SEEK_SET); - r = claws_fread(&rdbh, sizeof(RawDBHeader), 1, in); - if (r < 1) - return MGU_ERROR_READ; - if (claws_feof(in)) { - return MGU_EOF; - } - - raw_header_to_header(&rdbh, &dbh); - if (dbh.app_info_offset==0) { - *size=0; - return MGU_SUCCESS; - } - if (dbh.sort_info_offset!=0) { - *size = dbh.sort_info_offset - dbh.app_info_offset; - return MGU_SUCCESS; - } - if (dbh.number_of_records==0) { - fseek(in, 0, SEEK_END); - *size=ftell(in) - dbh.app_info_offset; - return MGU_SUCCESS; - } - - r = claws_fread(&rh, sizeof(record_header), 1, in); - if (r < 1) - return MGU_ERROR_READ; - - offset = ((rh.Offset[0]*256+rh.Offset[1])*256+rh.Offset[2])*256+rh.Offset[3]; - *size=offset - dbh.app_info_offset; - - return MGU_SUCCESS; -} - -/* - * Read address file into address list. Based on JPilot's - * libplugin.c (jp_get_app_info) - */ -static gint jpilot_get_file_info( JPilotFile *pilotFile, unsigned char **buf, int *buf_size ) { - FILE *in; - int num; - unsigned int rec_size; - RawDBHeader rdbh; - DBHeader dbh; - - if( ( !buf_size ) || ( ! buf ) ) { - return MGU_BAD_ARGS; - } - - *buf = NULL; - *buf_size=0; - - if( pilotFile->path ) { - in = claws_fopen( pilotFile->path, "rb" ); - if( !in ) { - return MGU_OPEN_FILE; - } - } - else { - return MGU_NO_FILE; - } - - num = claws_fread( &rdbh, sizeof( RawDBHeader ), 1, in ); - if( num != 1 ) { - if( claws_ferror(in) ) { - claws_fclose(in); - return MGU_ERROR_READ; - } - } - if (claws_feof(in)) { - claws_fclose(in); - return MGU_EOF; - } - - /* Convert header into something recognizable */ - raw_header_to_header(&rdbh, &dbh); - - num = jpilot_get_info_size(in, &rec_size); - if (num) { - claws_fclose(in); - return MGU_ERROR_READ; - } - - if (fseek(in, dbh.app_info_offset, SEEK_SET) < 0) { - claws_fclose(in); - return MGU_ERROR_READ; - } - *buf = ( char * ) malloc(rec_size); - if (!(*buf)) { - claws_fclose(in); - return MGU_OO_MEMORY; - } - num = claws_fread(*buf, rec_size, 1, in); - if (num != 1) { - if (claws_ferror(in)) { - claws_fclose(in); - free(*buf); - return MGU_ERROR_READ; - } - } - claws_fclose(in); - - *buf_size = rec_size; - - return MGU_SUCCESS; -} - -/* Shamelessly copied from JPilot (libplugin.c) */ -static int unpack_header(PC3RecordHeader *header, unsigned char *packed_header) { - unsigned char *p; - guint32 l; - - p = packed_header; - - memcpy(&l, p, sizeof(l)); - header->header_len=ntohl(l); - p+=sizeof(l); - - memcpy(&l, p, sizeof(l)); - header->header_version=ntohl(l); - p+=sizeof(l); - - memcpy(&l, p, sizeof(l)); - header->rec_len=ntohl(l); - p+=sizeof(l); - - memcpy(&l, p, sizeof(l)); - header->unique_id=ntohl(l); - p+=sizeof(l); - - memcpy(&l, p, sizeof(l)); - header->rt=ntohl(l); - p+=sizeof(l); - - memcpy(&(header->attrib), p, sizeof(unsigned char)); - p+=sizeof(unsigned char); - - return 0; -} - -/* Shamelessly copied from JPilot (libplugin.c) */ -static int read_header(FILE *pc_in, PC3RecordHeader *header) { - guint32 l; - unsigned long len; - unsigned char packed_header[256]; - int num; - - memset(header, 0, sizeof(PC3RecordHeader)); - - num = claws_fread(&l, sizeof(l), 1, pc_in); - if (claws_feof(pc_in)) { - return -1; - } - if (num!=1) { - return num; - } - memcpy(packed_header, &l, sizeof(l)); - len=ntohl(l); - if (len > 255 || len < sizeof(l)) { - return -1; - } - num = claws_fread(packed_header+sizeof(l), len-sizeof(l), 1, pc_in); - if (claws_feof(pc_in)) { - return -1; - } - if (num!=1) { - return num; - } - unpack_header(header, packed_header); - return 1; -} - -/** - * Read next record from PC3 file. Based on JPilot function - * <code>pc_read_next_rec()</code> (libplugin.c) - * - * \param in File handle. - * \param br Record buffer. - * \return Status/error code. <code>MGU_SUCCESS</code> if data read - * successfully. - */ -static gint jpilot_read_next_pc( FILE *in, buf_rec *br ) { - PC3RecordHeader header; - int rec_len, num; - char *record; - - if( claws_feof( in ) ) { - return MGU_EOF; - } - num = read_header( in, &header ); - if( num < 1 ) { - if( claws_ferror( in ) ) - return MGU_ERROR_READ; - else if( claws_feof( in ) ) - return MGU_EOF; - else - return -1; - } - rec_len = header.rec_len; - record = malloc( rec_len ); - if( ! record ) { - return MGU_OO_MEMORY; - } - num = claws_fread( record, rec_len, 1, in ); - if( num != 1 ) { - if( claws_ferror( in ) ) { - free( record ); - return MGU_ERROR_READ; - } - } - br->rt = header.rt; - br->unique_id = header.unique_id; - br->attrib = header.attrib; - br->buf = record; - br->size = rec_len; - - return MGU_SUCCESS; -} - -/** - * Read address file into a linked list. Based on JPilot function - * <code>jp_read_DB_files()</code> (from libplugin.c) - * - * \param pilotFile JPilot control data. - * \param records Pointer to linked list of records read. - * \return Status/error code. <code>MGU_SUCCESS</code> if data read - * successfully. - */ -static gint jpilot_read_db_files( JPilotFile *pilotFile, GList **records ) { - FILE *in, *pc_in; - char *buf; - GList *temp_list; - int num_records, recs_returned, i, num, r; - unsigned int offset, prev_offset, next_offset = 0, rec_size; - int out_of_order; - long fpos; /*file position indicator */ - unsigned char attrib = '\0'; - unsigned int unique_id = 0; - mem_rec_header *mem_rh, *temp_mem_rh, *last_mem_rh; - record_header rh; - RawDBHeader rdbh; - DBHeader dbh; - buf_rec *temp_br; - gchar *pcFile; - - mem_rh = last_mem_rh = NULL; - *records = NULL; - recs_returned = 0; - - if( pilotFile->path == NULL ) { - return MGU_BAD_ARGS; - } - - in = claws_fopen( pilotFile->path, "rb" ); - if (!in) { - return MGU_OPEN_FILE; - } - - /* Read the database header */ - num = claws_fread( &rdbh, sizeof( RawDBHeader ), 1, in ); - if( num != 1 ) { - if( claws_ferror( in ) ) { - claws_fclose( in ); - return MGU_ERROR_READ; - } - if( claws_feof( in ) ) { - claws_fclose( in ); - return MGU_EOF; - } - } - raw_header_to_header( &rdbh, &dbh ); - - /* Read each record entry header */ - num_records = dbh.number_of_records; - out_of_order = 0; - prev_offset = 0; - - for( i = 1; i < num_records + 1; i++ ) { - num = claws_fread( &rh, sizeof( record_header ), 1, in ); - if( num != 1 ) { - if( claws_ferror( in ) ) { - break; - } - if( claws_feof( in ) ) { - claws_fclose( in ); - if (mem_rh) - free_mem_rec_header( &mem_rh ); - return MGU_EOF; - } - } - - offset = - ( ( rh.Offset[0] * 256 + rh.Offset[1] ) * 256 - + rh.Offset[2] ) * 256 - + rh.Offset[3]; - if( offset < prev_offset ) { - out_of_order = 1; - } - prev_offset = offset; - temp_mem_rh = ( mem_rec_header * ) malloc( sizeof( mem_rec_header ) ); - if( ! temp_mem_rh ) { - break; - } - temp_mem_rh->next = NULL; - temp_mem_rh->rec_num = i; - temp_mem_rh->offset = offset; - temp_mem_rh->attrib = rh.attrib; - temp_mem_rh->unique_id = - ( rh.unique_ID[0] * 256 + rh.unique_ID[1] ) * 256 - + rh.unique_ID[2]; - if( mem_rh == NULL ) { - mem_rh = temp_mem_rh; - last_mem_rh = temp_mem_rh; - } - else { - last_mem_rh->next = temp_mem_rh; - last_mem_rh = temp_mem_rh; - } - } - - temp_mem_rh = mem_rh; - - if( num_records ) { - if( out_of_order ) { - find_next_offset( - mem_rh, 0, &next_offset, &attrib, &unique_id ); - } - else { - if( mem_rh ) { - next_offset = mem_rh->offset; - attrib = mem_rh->attrib; - unique_id = mem_rh->unique_id; - } - } - if (fseek( in, next_offset, SEEK_SET ) < 0) { - free_mem_rec_header( &mem_rh ); - claws_fclose(in); - return MGU_ERROR_READ; - } - while( ! claws_feof( in ) ) { - fpos = ftell( in ); - if( out_of_order ) { - find_next_offset( - mem_rh, fpos, &next_offset, &attrib, - &unique_id ); - } else { - next_offset = 0xFFFFFF; - if( temp_mem_rh ) { - attrib = temp_mem_rh->attrib; - unique_id = temp_mem_rh->unique_id; - if ( temp_mem_rh->next ) { - temp_mem_rh = temp_mem_rh->next; - next_offset = temp_mem_rh->offset; - } - } - } - rec_size = next_offset - fpos; - buf = malloc( rec_size ); - if( ! buf ) break; - num = claws_fread( buf, rec_size, 1, in ); - if( ( num != 1 ) ) { - if( claws_ferror( in ) ) { - free( buf ); - break; - } - } - - temp_br = malloc( sizeof( buf_rec ) ); - if( ! temp_br ) { - free( buf ); - break; - } - temp_br->rt = PALM_REC; - temp_br->unique_id = unique_id; - temp_br->attrib = attrib; - temp_br->buf = buf; - temp_br->size = rec_size; - - *records = g_list_append( *records, temp_br ); - - recs_returned++; - } - } - claws_fclose( in ); - free_mem_rec_header( &mem_rh ); - - /* Read the PC3 file, if present */ - pcFile = jpilot_get_pc3_file( pilotFile ); - if( pcFile == NULL ) return MGU_SUCCESS; - pc_in = claws_fopen( pcFile, "rb"); - g_free( pcFile ); - - if( pc_in == NULL ) { - return MGU_SUCCESS; - } - - while( ! claws_feof( pc_in ) ) { - gboolean linked; - - temp_br = malloc( sizeof( buf_rec ) ); - if( ! temp_br ) { - break; - } - r = jpilot_read_next_pc( pc_in, temp_br ); - if( r != MGU_SUCCESS ) { - if( (r != MGU_EOF) && (r != MGU_ERROR_READ) ) { - free( temp_br->buf ); - } - free( temp_br ); - break; - } - - linked = FALSE; - if( ( temp_br->rt != DELETED_PC_REC ) - && ( temp_br->rt != DELETED_PALM_REC ) - && ( temp_br->rt != MODIFIED_PALM_REC ) - && ( temp_br->rt != DELETED_DELETED_PALM_REC ) ) - { - *records = g_list_append( *records, temp_br ); - recs_returned++; - linked = TRUE; - } - - if( ( temp_br->rt == DELETED_PALM_REC ) - || ( temp_br->rt == MODIFIED_PALM_REC ) ) - { - temp_list = *records; - if( *records ) { - while( temp_list->next ) { - temp_list=temp_list->next; - } - } - for( ; temp_list; temp_list=temp_list->prev ) { - if( ( ( buf_rec * )temp_list->data )->unique_id == - temp_br->unique_id ) { - ( ( buf_rec * )temp_list->data )->rt = - temp_br->rt; - } - } - } - - if( ! linked ) { - free( temp_br->buf ); - free( temp_br ); - } - } - claws_fclose( pc_in ); - - return MGU_SUCCESS; -} - -/** - * Parse buffer containing multiple e-mail addresses into a linked list of - * addresses. Separator characters are " ,;|" and control characters. Address - * is only extracted if it contains an "at" (@) character. - * - * \param buf Buffer to process. - * \return List of strings. - */ -static GList *jpilot_parse_email( gchar *buf ) { - GList *list; - gchar *p, *st, *em; - gchar lch; - gint len; - gboolean valid, done; - - valid = done = FALSE; - lch = ' '; - list = NULL; - p = st = buf; - while( ! done ) { - if( *p == ' ' || *p == ',' || *p == ';' || *p == '|' || *p < 32 ) { - if( *p == '\0' ) { - done = TRUE; - } - else { - *p = ' '; - } - - if( *p == lch ) { - st++; - } - else { - len = p - st; - if( len > 0 ) { - if( valid ) { - em = g_strndup( st, len ); - list = g_list_append( list, em ); - } - st = p; - ++st; - valid = FALSE; - } - } - } - if( *p == '@' ) valid = TRUE; - lch = *p; - ++p; - } - - return list; -} - -#define FULLNAME_BUFSIZE 256 -#define EMAIL_BUFSIZE 256 - -/** - * Process a single label entry field, parsing multiple e-mail address entries. - * - * \param pilotFile JPilot control data. - * \param labelEntry Label entry data. - * \param person Person. - */ -static void jpilot_parse_label( JPilotFile *pilotFile, gchar *labelEntry, ItemPerson *person ) { - gchar buffer[ EMAIL_BUFSIZE ]; - ItemEMail *email; - GList *list, *node; - - if( labelEntry ) { - *buffer = '\0'; - g_strlcpy( buffer, labelEntry, sizeof(buffer) ); - node = list = jpilot_parse_email( buffer ); - while( node ) { - email = addritem_create_item_email(); - addritem_email_set_address( email, node->data ); - if (convert_charcode) { - gchar *convertBuff = NULL; - convertBuff = conv_codeset_strdup( labelEntry, - jpilot_get_charset(), - CS_INTERNAL ); - if (convertBuff) - addritem_email_set_remarks( email, convertBuff ); - g_free( convertBuff ); - } - else { - addritem_email_set_remarks(email, buffer); - } - - addrcache_id_email( pilotFile->addressCache, email ); - addrcache_person_add_email( pilotFile->addressCache, person, email ); - node = g_list_next( node ); - } - g_list_free_full( list, g_free ); - list = NULL; - } -} - -/** - * Unpack address, building new data inside cache. - * \param pilotFile JPilot control data. - * \param buf Record buffer. - * \param folderInd Array of (category) folders to load. - */ -static void jpilot_load_address( - JPilotFile *pilotFile, buf_rec *buf, ItemFolder *folderInd[] ) -{ - struct Address addr; - gchar **addrEnt; - gint k; - gint cat_id = 0; - guint unique_id; - guchar attrib; - gchar fullName[ FULLNAME_BUFSIZE ]; - ItemPerson *person; - gint *indPhoneLbl; - gchar *labelEntry; - GList *node; - gchar* extID; - gchar **firstName = NULL; - gchar **lastName = NULL; -#if (PILOT_LINK_MAJOR > 11) - pi_buffer_t *RecordBuffer; - RecordBuffer = pi_buffer_new(buf->size); - - memcpy(RecordBuffer->data, buf->buf, buf->size); - RecordBuffer->used = buf->size; - if (unpack_Address(&addr, RecordBuffer, address_v1) == -1) { - pi_buffer_free(RecordBuffer); - return; - } - pi_buffer_free(RecordBuffer); -#else - gint num; - - num = unpack_Address(&addr, buf->buf, buf->size); - if (num <= 0) { - return; - } -#endif /* PILOT_LINK_0_12 */ - - addrEnt = addr.entry; - attrib = buf->attrib; - unique_id = buf->unique_id; - cat_id = attrib & 0x0F; - - *fullName = '\0'; - if( addrEnt[ IND_LABEL_FIRSTNAME ] ) { - firstName = g_strsplit( addrEnt[ IND_LABEL_FIRSTNAME ], "\01", 2 ); - } - - if( addrEnt[ IND_LABEL_LASTNAME ] ) { - lastName = g_strsplit( addrEnt[ IND_LABEL_LASTNAME ], "\01", 2 ); - } - - if( name_order == FAMILY_LAST ) { - g_snprintf( fullName, FULLNAME_BUFSIZE, "%s %s", - firstName ? firstName[0] : "", - lastName ? lastName[0] : "" ); - } - else { - g_snprintf( fullName, FULLNAME_BUFSIZE, "%s %s", - lastName ? lastName[0] : "", - firstName ? firstName[0] : "" ); - } - - if( firstName ) { - g_strfreev( firstName ); - } - if( lastName ) { - g_strfreev( lastName ); - } - - g_strstrip( fullName ); - - if( convert_charcode ) { - gchar *nameConv = NULL; - nameConv = conv_codeset_strdup( fullName, - jpilot_get_charset(), - CS_INTERNAL ); - if (nameConv) - strncpy2( fullName, nameConv, FULLNAME_BUFSIZE ); - g_free( nameConv ); - } - - person = addritem_create_item_person(); - addritem_person_set_common_name( person, fullName ); - addritem_person_set_first_name( person, addrEnt[ IND_LABEL_FIRSTNAME ] ); - addritem_person_set_last_name( person, addrEnt[ IND_LABEL_LASTNAME ] ); - addrcache_id_person( pilotFile->addressCache, person ); - - extID = g_strdup_printf( "%d", unique_id ); - addritem_person_set_external_id( person, extID ); - g_free( extID ); - extID = NULL; - - /* Add entry for each email address listed under phone labels. */ - indPhoneLbl = addr.phoneLabel; - for( k = 0; k < JPILOT_NUM_ADDR_PHONE; k++ ) { - if( indPhoneLbl[k] == IND_PHONE_EMAIL ) { - labelEntry = addrEnt[ OFFSET_PHONE_LABEL + k ]; - jpilot_parse_label( pilotFile, labelEntry, person ); - } - } - - /* Add entry for each custom label */ - node = pilotFile->labelInd; - while( node ) { - gint ind; - - ind = GPOINTER_TO_INT( node->data ); - if( ind > -1 ) { - /* - * g_print( "%d : %20s : %s\n", ind, ai->labels[ind], - * addrEnt[ind] ); - */ - labelEntry = addrEnt[ind]; - jpilot_parse_label( pilotFile, labelEntry, person ); - } - - node = g_list_next( node ); - } - - if( person->listEMail ) { - /* Add to specified category */ - addrcache_folder_add_person( - pilotFile->addressCache, - folderInd[cat_id], person ); - } - else { - addritem_free_item_person( person ); - person = NULL; - } - /* Free up pointer allocated inside address */ - free_Address( & addr ); -} - -/** - * Free up address list. - * \param records List of records to free. - */ -static void jpilot_free_addrlist( GList *records ) { - GList *node; - buf_rec *br; - - node = records; - while( node ) { - br = node->data; - free( br->buf ); - free( br ); - node->data = NULL; - node = g_list_next( node ); - } - - /* Free up list */ - g_list_free( records ); -} - -/** - * Read metadata from file. - * \param pilotFile JPilot control data. - * \return Status/error code. <code>MGU_SUCCESS</code> if data read - * successfully. - */ -static gint jpilot_read_metadata( JPilotFile *pilotFile ) { - gint retVal; - unsigned int rec_size; - unsigned char *buf; - int num; - - cm_return_val_if_fail( pilotFile != NULL, -1 ); - - pilotFile->readMetadata = FALSE; - addrcache_clear( pilotFile->addressCache ); - - /* Read file info */ - retVal = jpilot_get_file_info( pilotFile, &buf, &rec_size); - if( retVal != MGU_SUCCESS ) { - pilotFile->retVal = retVal; - return pilotFile->retVal; - } - - num = unpack_AddressAppInfo( &pilotFile->addrInfo, buf, rec_size ); - if( buf ) { - free(buf); - } - if( num <= 0 ) { - pilotFile->retVal = MGU_ERROR_READ; - return pilotFile->retVal; - } - - pilotFile->readMetadata = TRUE; - pilotFile->retVal = MGU_SUCCESS; - return pilotFile->retVal; -} - -/** - * Setup labels and indexes from metadata. - * \param pilotFile JPilot control data. - * \return <i>TRUE</i> is setup successfully. - */ -static gboolean jpilot_setup_labels( JPilotFile *pilotFile ) { - gboolean retVal = FALSE; - struct AddressAppInfo *ai; - GList *node; - - cm_return_val_if_fail( pilotFile != NULL, -1 ); - - /* Release indexes */ - node = pilotFile->labelInd; - while( node ) { - node->data = NULL; - node = g_list_next( node ); - } - pilotFile->labelInd = NULL; - - if( pilotFile->readMetadata ) { - ai = & pilotFile->addrInfo; - node = pilotFile->customLabels; - while( node ) { - gchar *lbl = node->data; - gint ind = -1; - gint i; - for( i = 0; i < JPILOT_NUM_LABELS; i++ ) { - gchar *labelName = ai->labels[i]; - - if( convert_charcode ) { - gchar *convertBuff = NULL; - convertBuff = conv_codeset_strdup( labelName, - jpilot_get_charset(), - CS_INTERNAL ); - if (convertBuff) { - labelName = convertBuff; - } - } - - if( g_utf8_collate( labelName, lbl ) == 0 ) { - ind = i; - break; - } - } - pilotFile->labelInd = g_list_append( - pilotFile->labelInd, GINT_TO_POINTER(ind) ); - node = g_list_next( node ); - } - retVal = TRUE; - } - return retVal; -} - -/** - * Load list with character strings of custom label names. Only none blank - * names are loaded. - * \param pilotFile JPilot control data. - * \param labelList List of label names to load. - * \return List of label names loaded. Should be freed when done. - */ -GList *jpilot_load_custom_label( JPilotFile *pilotFile, GList *labelList ) { - gint i; - - cm_return_val_if_fail( pilotFile != NULL, NULL ); - - if( pilotFile->readMetadata ) { - struct AddressAppInfo *ai = & pilotFile->addrInfo; - for( i = 0; i < NUM_CUSTOM_LABEL; i++ ) { - gchar *labelName = ai->labels[i+IND_CUSTOM_LABEL]; - if( labelName ) { - g_strstrip( labelName ); - if( *labelName != '\0' ) { - if( convert_charcode ) { - gchar *convertBuff = NULL; - convertBuff = conv_codeset_strdup( labelName, - jpilot_get_charset(), - CS_INTERNAL ); - if (convertBuff) { - labelName = convertBuff; - } - } - else { - labelName = g_strdup( labelName ); - } - labelList = g_list_append( labelList, labelName ); - } - } - } - } - return labelList; -} - -/** - * Build folder in address book for each category. - * \param pilotFile JPilot control data. - */ -static void jpilot_build_category_list( JPilotFile *pilotFile ) { - struct AddressAppInfo *ai = & pilotFile->addrInfo; - struct CategoryAppInfo *cat = & ai->category; - gint i; - - for( i = 0; i < JPILOT_NUM_CATEG; i++ ) { - ItemFolder *folder = addritem_create_item_folder(); - - if( convert_charcode ) { - gchar *convertBuff = NULL; - convertBuff = conv_codeset_strdup( cat->name[i], - jpilot_get_charset(), - CS_INTERNAL ); - if (convertBuff) { - addritem_folder_set_name( folder, convertBuff ); - g_free( convertBuff ); - } else { - addritem_folder_set_name( folder, cat->name[i] ); - } - } - else { - addritem_folder_set_name( folder, cat->name[i] ); - } - - addrcache_id_folder( pilotFile->addressCache, folder ); - addrcache_add_folder( pilotFile->addressCache, folder ); - } -} - -/** - * Remove empty (category) folders. - * \param pilotFile JPilot control data. - */ -static void jpilot_remove_empty( JPilotFile *pilotFile ) { - GList *listFolder; - GList *remList; - GList *node; - gint i = 0; - - listFolder = addrcache_get_list_folder( pilotFile->addressCache ); - node = listFolder; - remList = NULL; - while( node ) { - ItemFolder *folder = node->data; - if( ADDRITEM_NAME(folder) == NULL || *ADDRITEM_NAME(folder) == '\0' ) { - if( folder->listPerson ) { - /* Give name to folder */ - gchar name[20]; - sprintf( name, "? %d", i ); - addritem_folder_set_name( folder, name ); - } - else { - /* Mark for removal */ - remList = g_list_append( remList, folder ); - } - } - node = g_list_next( node ); - i++; - } - node = remList; - while( node ) { - ItemFolder *folder = node->data; - addrcache_remove_folder( pilotFile->addressCache, folder ); - node = g_list_next( node ); - } - g_list_free( remList ); -} - -/** - * Read address file into address cache. - * \param pilotFile JPilot control data. - * \return Error/status code. <code>MGU_SUCCESS</code> if data read - * successfully. - */ -static gint jpilot_read_file( JPilotFile *pilotFile ) { - gint retVal, i; - GList *records = NULL; - GList *node; - buf_rec *br; - ItemFolder *folderInd[ JPILOT_NUM_CATEG ]; - - /* Read list of records from JPilot files */ - retVal = jpilot_read_db_files( pilotFile, &records ); - if( retVal != MGU_SUCCESS ) { - jpilot_free_addrlist( records ); - return retVal; - } - - /* Setup labels and category folders */ - jpilot_setup_labels( pilotFile ); - jpilot_build_category_list( pilotFile ); - - /* Build array of pointers to categories */ - i = 0; - node = addrcache_get_list_folder( pilotFile->addressCache ); - while( node ) { - if( i < JPILOT_NUM_CATEG ) { - folderInd[i] = node->data; - } - node = g_list_next( node ); - i++; - } - - /* Load all addresses, free up old stuff as we go */ - node = records; - while( node ) { - br = node->data; - if( ( br->rt != DELETED_PC_REC ) && - ( br->rt != DELETED_PALM_REC ) && - ( br->rt != MODIFIED_PALM_REC ) && - ( br->rt != DELETED_DELETED_PALM_REC ) ) { - jpilot_load_address( pilotFile, br, folderInd ); - } - free( br->buf ); - free( br ); - node->data = NULL; - node = g_list_next( node ); - } - - /* Free up list */ - g_list_free( records ); - - /* Remove empty category folders */ - jpilot_remove_empty( pilotFile ); - jpilot_mark_files( pilotFile ); - - return retVal; -} - -/** - * Read file into list. Main entry point - * \param pilotFile JPilot control data. - * \return Error/status code. <code>MGU_SUCCESS</code> if data read - * successfully. - */ -gint jpilot_read_data( JPilotFile *pilotFile ) { - const gchar *cur_locale; - - name_order = FAMILY_LAST; - - cur_locale = conv_get_current_locale(); - - if( g_ascii_strncasecmp( cur_locale, "hu", 2 ) == 0 || - g_ascii_strncasecmp( cur_locale, "ja", 2 ) == 0 || - g_ascii_strncasecmp( cur_locale, "ko", 2 ) == 0 || - g_ascii_strncasecmp( cur_locale, "vi", 2 ) == 0 || - g_ascii_strncasecmp( cur_locale, "zh", 2 ) == 0 ) { - name_order = FAMILY_FIRST; - } - - cm_return_val_if_fail( pilotFile != NULL, -1 ); - - pilotFile->retVal = MGU_SUCCESS; - pilotFile->addressCache->accessFlag = FALSE; - if( jpilot_check_files( pilotFile ) ) { - addrcache_clear( pilotFile->addressCache ); - jpilot_read_metadata( pilotFile ); - if( pilotFile->retVal == MGU_SUCCESS ) { - pilotFile->retVal = jpilot_read_file( pilotFile ); - if( pilotFile->retVal == MGU_SUCCESS ) { - pilotFile->addressCache->modified = FALSE; - pilotFile->addressCache->dataRead = TRUE; - } - } - } - return pilotFile->retVal; -} - -/** - * Return linked list of persons. This is a list of references to ItemPerson - * objects. Do <b>NOT</b> attempt to use the <code>addrbook_free_xxx()</code> - * functions... this will destroy the addressbook data! - * - * \param pilotFile JPilot control data. - * \return List of persons. - */ -GList *jpilot_get_list_person( JPilotFile *pilotFile ) { - cm_return_val_if_fail( pilotFile != NULL, NULL ); - return addrcache_get_list_person( pilotFile->addressCache ); -} - -/** - * Return linked list of folders. This is a list of references to non-empty - * category folders. Do <b>NOT</b> attempt to use the - * <code>addrbook_free_xxx()</code> functions... this will destroy the - * addressbook data! - * - * \param pilotFile JPilot control data. - * \return List of ItemFolder objects. This should not be freed. - */ -GList *jpilot_get_list_folder( JPilotFile *pilotFile ) { - cm_return_val_if_fail( pilotFile != NULL, NULL ); - return addrcache_get_list_folder( pilotFile->addressCache ); -} - -/** - * Return linked list of all persons. Note that the list contains references - * to items. Do <b>NOT</b> attempt to use the <code>addrbook_free_xxx()</code> - * functions... this will destroy the addressbook data! - * - * \param pilotFile JPilot control data. - * \return List of items, or NULL if none. - */ -GList *jpilot_get_all_persons( JPilotFile *pilotFile ) { - cm_return_val_if_fail( pilotFile != NULL, NULL ); - return addrcache_get_all_persons( pilotFile->addressCache ); -} - -#define WORK_BUFLEN 1024 - -/** - * Attempt to find a valid JPilot file. - * \param pilotFile JPilot control data. - * \return Filename, or home directory if not found, or empty string if - * no home. Filename should be <code>g_free()</code> when done. - */ -gchar *jpilot_find_pilotdb( void ) { - const gchar *homedir; - gchar str[ WORK_BUFLEN + 1 ]; - gint len; - FILE *fp; - - homedir = get_home_dir(); - if( ! homedir ) return g_strdup( "" ); - - g_strlcpy( str, homedir , sizeof(str)); - len = strlen( str ); - if( len > 0 ) { - if( str[ len-1 ] != G_DIR_SEPARATOR ) { - str[ len ] = G_DIR_SEPARATOR; - str[ ++len ] = '\0'; - } - } - strncat( str, JPILOT_DBHOME_DIR, WORK_BUFLEN - strlen(str) ); - strncat( str, G_DIR_SEPARATOR_S, WORK_BUFLEN - strlen(str) ); - strncat( str, JPILOT_DBHOME_FILE, WORK_BUFLEN - strlen(str) ); - - /* Attempt to open */ - if( ( fp = claws_fopen( str, "rb" ) ) != NULL ) { - claws_fclose( fp ); - } - else { - /* Truncate filename */ - str[ len ] = '\0'; - } - return g_strdup( str ); -} - -/** - * Check whether label is in list of custom labels. - * \param pilotFile JPilot control data. - * \param labelName to test. - * \return <i>TRUE</i> if found. - */ -gboolean jpilot_test_custom_label( JPilotFile *pilotFile, const gchar *labelName ) { - gboolean retVal; - GList *node; - - cm_return_val_if_fail( pilotFile != NULL, FALSE ); - - retVal = FALSE; - if( labelName ) { - node = pilotFile->customLabels; - while( node ) { - if( g_utf8_collate( labelName, ( gchar * ) node->data ) == 0 ) { - retVal = TRUE; - break; - } - node = g_list_next( node ); - } - } - return retVal; -} - -/** - * Test whether pilot link library installed. - * \return <i>TRUE</i> if library available. - */ -gboolean jpilot_test_pilot_lib( void ) { - return TRUE; -} - -#endif /* USE_JPILOT */ - -/* -* End of Source. -*/ diff --git a/src/jpilot.h b/src/jpilot.h @@ -1,107 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2001-2012 Match Grun and the Claws Mail team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -/* - * Definitions for accessing JPilot database files. - * JPilot is Copyright(c) by Judd Montgomery. - * Visit http://www.jpilot.org for more details. - */ - -#ifndef __JPILOT_H__ -#define __JPILOT_H__ - -#ifdef HAVE_CONFIG_H -#include "claws-features.h" -#endif - -#ifdef USE_JPILOT - -#include <glib.h> -#include <stdio.h> - -#ifdef HAVE_LIBPISOCK_PI_ADDRESS_H -# include <libpisock/pi-address.h> -#else -# include <pi-address.h> -#endif - -#include "addritem.h" -#include "addrcache.h" -#include "adbookbase.h" - -typedef struct _JPilotFile JPilotFile; - -struct _JPilotFile { - AddressBookType type; - AddressCache *addressCache; - gint retVal; - FILE *file; - gchar *path; - struct AddressAppInfo addrInfo; - gboolean readMetadata; - GList *customLabels; - GList *labelInd; - gboolean havePC3; - time_t pc3ModifyTime; -}; - -/* Limits */ -#define JPILOT_NUM_LABELS 22 /* Number of labels */ -#define JPILOT_NUM_PHONELABELS 8 /* Number of phone number labels */ -#define JPILOT_NUM_CATEG 16 /* Number of categories */ -#define JPILOT_LEN_LABEL 15 /* Max length of label */ -#define JPILOT_LEN_CATEG 15 /* Max length of category */ -#define JPILOT_NUM_ADDR_PHONE 5 /* Number of phone entries a person */ - /* can have */ - -/* Function prototypes */ -JPilotFile *jpilot_create ( void ); -JPilotFile *jpilot_create_path ( const gchar *path ); -void jpilot_set_name ( JPilotFile* pilotFile, const gchar *value ); -void jpilot_set_file ( JPilotFile* pilotFile, const gchar *value ); -void jpilot_free ( JPilotFile *pilotFile ); -gint jpilot_get_status ( JPilotFile *pilotFile ); -gboolean jpilot_get_modified ( JPilotFile *pilotFile ); -gboolean jpilot_get_accessed ( JPilotFile *pilotFile ); -void jpilot_set_accessed ( JPilotFile *pilotFile, const gboolean value ); -gboolean jpilot_get_read_flag ( JPilotFile *pilotFile ); -ItemFolder *jpilot_get_root_folder ( JPilotFile *pilotFile ); -gchar *jpilot_get_name ( JPilotFile *pilotFile ); - -gint jpilot_read_data ( JPilotFile *pilotFile ); -GList *jpilot_get_list_person ( JPilotFile *pilotFile ); -GList *jpilot_get_list_folder ( JPilotFile *pilotFile ); -GList *jpilot_get_all_persons ( JPilotFile *pilotFile ); - -GList *jpilot_load_custom_label ( JPilotFile *pilotFile, GList *labelList ); - -gchar *jpilot_find_pilotdb ( void ); - - -void jpilot_clear_custom_labels ( JPilotFile *pilotFile ); -void jpilot_add_custom_label ( JPilotFile *pilotFile, const gchar *labelName ); -GList *jpilot_get_custom_labels ( JPilotFile *pilotFile ); -gboolean jpilot_test_custom_label ( JPilotFile *pilotFile, const gchar *labelName ); -gboolean jpilot_test_pilot_lib ( void ); - -gint jpilot_read_modified ( JPilotFile *pilotFile ); - -#endif /* USE_JPILOT */ - -#endif /* __JPILOT_H__ */ diff --git a/src/ldapctrl.c b/src/ldapctrl.c @@ -1,794 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2003-2022 the Claws Mail team and Match Grun - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * Functions for LDAP control data. - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#include "claws-features.h" -#endif - -#ifdef USE_LDAP - -#include <glib.h> -#include <sys/time.h> -#include <string.h> - -#include "ldapctrl.h" -#include "mgutils.h" -#include "passwordstore.h" -#include "editaddress_other_attributes_ldap.h" -#include "common/utils.h" -#include "common/quoted-printable.h" - -/** - * Create new LDAP control block object. - * \return Initialized control object. - */ -LdapControl *ldapctl_create( void ) { - LdapControl *ctl; - - ctl = g_new0( LdapControl, 1 ); - ctl->hostName = NULL; - ctl->port = LDAPCTL_DFL_PORT; - ctl->baseDN = NULL; - ctl->bindDN = NULL; - ctl->listCriteria = NULL; - ctl->attribEMail = g_strdup( LDAPCTL_ATTR_EMAIL ); - ctl->attribCName = g_strdup( LDAPCTL_ATTR_COMMONNAME ); - ctl->attribFName = g_strdup( LDAPCTL_ATTR_GIVENNAME ); - ctl->attribLName = g_strdup( LDAPCTL_ATTR_SURNAME ); - ctl->attribDName = g_strdup( LDAPCTL_ATTR_DISPLAYNAME ); - ctl->maxEntries = LDAPCTL_MAX_ENTRIES; - ctl->timeOut = LDAPCTL_DFL_TIMEOUT; - ctl->maxQueryAge = LDAPCTL_DFL_QUERY_AGE; - ctl->matchingOption = LDAPCTL_MATCH_BEGINWITH; - ctl->version = 0; - ctl->enableTLS = FALSE; - ctl->enableSSL = FALSE; - - /* Mutex to protect control block */ - ctl->mutexCtl = g_malloc0( sizeof( pthread_mutex_t ) ); - pthread_mutex_init( ctl->mutexCtl, NULL ); - - return ctl; -} - -/** - * Specify hostname to be used. - * \param ctl Control object to process. - * \param value Host name. - */ -void ldapctl_set_host( LdapControl* ctl, const gchar *value ) { - ctl->hostName = mgu_replace_string( ctl->hostName, value ); - - if ( ctl->hostName == NULL ) - return; - - g_strstrip( ctl->hostName ); - debug_print("setting hostname: %s\n", ctl->hostName); -} - -/** - * Specify port to be used. - * \param ctl Control object to process. - * \param value Port. - */ -void ldapctl_set_port( LdapControl* ctl, const gint value ) { - if( value > 0 ) { - ctl->port = value; - } - else { - ctl->port = LDAPCTL_DFL_PORT; - } - debug_print("setting port: %d\n", ctl->port); -} - -/** - * Specify base DN to be used. - * \param ctl Control object to process. - * \param value Base DN. - */ -void ldapctl_set_base_dn( LdapControl* ctl, const gchar *value ) { - ctl->baseDN = mgu_replace_string( ctl->baseDN, value ); - - if ( ctl->baseDN == NULL ) - return; - - g_strstrip( ctl->baseDN ); - debug_print("setting baseDN: %s\n", ctl->baseDN); -} - -/** - * Specify bind DN to be used. - * \param ctl Control object to process. - * \param value Bind DN. - */ -void ldapctl_set_bind_dn( LdapControl* ctl, const gchar *value ) { - ctl->bindDN = mgu_replace_string( ctl->bindDN, value ); - - if ( ctl->bindDN == NULL ) - return; - - g_strstrip( ctl->bindDN ); - debug_print("setting bindDN: %s\n", ctl->bindDN); -} - -/** - * Specify maximum number of entries to retrieve. - * \param ctl Control object to process. - * \param value Maximum entries. - */ -void ldapctl_set_max_entries( LdapControl* ctl, const gint value ) { - if( value > 0 ) { - ctl->maxEntries = value; - } - else { - ctl->maxEntries = LDAPCTL_MAX_ENTRIES; - } - debug_print("setting maxEntries: %d\n", ctl->maxEntries); -} - -/** - * Specify timeout value for LDAP operation (in seconds). - * \param ctl Control object to process. - * \param value Timeout. - */ -void ldapctl_set_timeout( LdapControl* ctl, const gint value ) { - if( value > 0 ) { - ctl->timeOut = value; - } - else { - ctl->timeOut = LDAPCTL_DFL_TIMEOUT; - } - debug_print("setting timeOut: %d\n", ctl->timeOut); -} - -/** - * Specify maximum age of query (in seconds) before query is retired. - * \param ctl Control object to process. - * \param value Maximum age. - */ -void ldapctl_set_max_query_age( LdapControl* ctl, const gint value ) { - if( value > LDAPCTL_MAX_QUERY_AGE ) { - ctl->maxQueryAge = LDAPCTL_MAX_QUERY_AGE; - } - else if( value < 1 ) { - ctl->maxQueryAge = LDAPCTL_DFL_QUERY_AGE; - } - else { - ctl->maxQueryAge = value; - } - debug_print("setting maxAge: %d\n", ctl->maxQueryAge); -} - -/** - * Specify matching option to be used for searches. - * \param ctl Control object to process. - * \param value Matching option, as follows: - * <ul> - * <li><code>LDAPCTL_MATCH_BEGINWITH</code> for "begins with" search</li> - * <li><code>LDAPCTL_MATCH_CONTAINS</code> for "contains" search</li> - * </ul> - */ -void ldapctl_set_matching_option( LdapControl* ctl, const gint value ) { - if( value < LDAPCTL_MATCH_BEGINWITH ) { - ctl->matchingOption = LDAPCTL_MATCH_BEGINWITH; - } - else if( value > LDAPCTL_MATCH_CONTAINS ) { - ctl->matchingOption = LDAPCTL_MATCH_BEGINWITH; - } - else { - ctl->matchingOption = value; - } - debug_print("setting matchingOption: %d\n", ctl->matchingOption); -} - -/** - * Specify TLS option. - * \param ctl Control object to process. - * \param value <i>TRUE</i> to enable TLS. - */ -void ldapctl_set_tls( LdapControl* ctl, const gboolean value ) { -#if (defined USE_LDAP_TLS || defined G_OS_WIN32) - ctl->enableTLS = value; - debug_print("setting STARTTLS: %d\n", ctl->enableTLS); -#endif -} - -void ldapctl_set_ssl( LdapControl* ctl, const gboolean value ) { -#if (defined USE_LDAP_TLS || defined G_OS_WIN32) - ctl->enableSSL = value; - debug_print("setting TLS: %d\n", ctl->enableSSL); -#endif -} - -/** - * Return search criteria list. - * \param ctl Control data object. - * \return Linked list of character strings containing LDAP attribute names to - * use for a search. This should not be modified directly. Use the - * <code>ldapctl_set_criteria_list()</code>, - * <code>ldapctl_criteria_list_clear()</code> and - * <code>ldapctl_criteria_list_add()</code> functions for this purpose. - */ -GList *ldapctl_get_criteria_list( const LdapControl* ctl ) { - cm_return_val_if_fail( ctl != NULL, NULL ); - return ctl->listCriteria; -} - -/** - * Clear list of LDAP search attributes. - * \param ctl Control data object. - */ -void ldapctl_criteria_list_clear( LdapControl *ctl ) { - cm_return_if_fail( ctl != NULL ); - g_list_free_full( ctl->listCriteria, g_free ); - ctl->listCriteria = NULL; -} - -/** - * Add LDAP attribute to criteria list. - * \param ctl Control object to process. - * \param attr Attribute name to append. If not NULL and unique, a copy will - * be appended to the list. - */ -void ldapctl_criteria_list_add( LdapControl *ctl, gchar *attr ) { - cm_return_if_fail( ctl != NULL ); - if( attr != NULL ) { - if( !g_list_find_custom( ctl->listCriteria, attr, - (GCompareFunc)g_utf8_collate ) ) { - debug_print("adding to criteria list: %s\n", attr); - ctl->listCriteria = g_list_append( - ctl->listCriteria, g_strdup( attr ) ); - } - } -} - -/** - * Clear LDAP server member variables. - * \param ctl Control object to clear. - */ -static void ldapctl_clear( LdapControl *ctl ) { - cm_return_if_fail( ctl != NULL ); - - debug_print("clearing ldap controller members\n"); - /* Free internal stuff */ - g_free( ctl->hostName ); - g_free( ctl->baseDN ); - g_free( ctl->bindDN ); - g_free( ctl->attribEMail ); - g_free( ctl->attribCName ); - g_free( ctl->attribFName ); - g_free( ctl->attribLName ); - g_free( ctl->attribDName ); - - ldapctl_criteria_list_clear( ctl ); - - /* Clear pointers */ - ctl->hostName = NULL; - ctl->port = 0; - ctl->baseDN = NULL; - ctl->bindDN = NULL; - ctl->attribEMail = NULL; - ctl->attribCName = NULL; - ctl->attribFName = NULL; - ctl->attribLName = NULL; - ctl->attribDName = NULL; - ctl->maxEntries = 0; - ctl->timeOut = 0; - ctl->maxQueryAge = 0; - ctl->matchingOption = LDAPCTL_MATCH_BEGINWITH; - ctl->version = 0; - ctl->enableTLS = FALSE; - ctl->enableSSL = FALSE; -} - -/** - * Free up LDAP server interface object by releasing internal memory. - * \param ctl Control object to free. - */ -void ldapctl_free( LdapControl *ctl ) { - cm_return_if_fail( ctl != NULL ); - - debug_print("releasing requested memory for ldap controller\n"); - /* Free internal stuff */ - ldapctl_clear( ctl ); - - /* Free the mutex */ - pthread_mutex_destroy( ctl->mutexCtl ); - g_free( ctl->mutexCtl ); - ctl->mutexCtl = NULL; - - /* Now release LDAP control object */ - g_free( ctl ); -} - -#ifdef DEBUG_LDAP -/** - * Display object to specified stream. - * \param ctl Control object to process. - * \param stream Output stream. - */ -void ldapctl_print( const LdapControl *ctl, FILE *stream ) { - cm_return_if_fail( ctl != NULL ); - gchar *pwd; - - pthread_mutex_lock( ctl->mutexCtl ); - fprintf( stream, "LdapControl:\n" ); - fprintf( stream, "host name: '%s'\n", ctl->hostName?ctl->hostName:"null" ); - fprintf( stream, " port: %d\n", ctl->port ); - fprintf( stream, " base dn: '%s'\n", ctl->baseDN?ctl->baseDN:"null" ); - fprintf( stream, " bind dn: '%s'\n", ctl->bindDN?ctl->bindDN:"null" ); - pwd = passwd_store_get(PWS_CORE, "LDAP", ctl->hostName); - fprintf( stream, "bind pass: '%s'\n", pwd?pwd:"null" ); - if (pwd != NULL && strlen(pwd) > 0) - memset(pwd, 0, strlen(pwd)); - g_free(pwd); - fprintf( stream, "attr mail: '%s'\n", ctl->attribEMail?ctl->attribEMail:"null" ); - fprintf( stream, "attr comn: '%s'\n", ctl->attribCName?ctl->attribCName:"null" ); - fprintf( stream, "attr frst: '%s'\n", ctl->attribFName?ctl->attribFName:"null" ); - fprintf( stream, "attr last: '%s'\n", ctl->attribLName?ctl->attribLName:"null" ); - fprintf( stream, "attr disn: '%s'\n", ctl->attribDName?ctl->attribDName:"null" ); - fprintf( stream, "max entry: %d\n", ctl->maxEntries ); - fprintf( stream, " timeout: %d\n", ctl->timeOut ); - fprintf( stream, " max age: %d\n", ctl->maxQueryAge ); - fprintf( stream, "match opt: %d\n", ctl->matchingOption ); - fprintf( stream, " version: %d\n", ctl->version ); - fprintf( stream, " STARTTLS: %s\n", ctl->enableTLS ? "yes" : "no" ); - fprintf( stream, " TLS: %s\n", ctl->enableSSL ? "yes" : "no" ); - fprintf( stream, "crit list:\n" ); - if( ctl->listCriteria ) { - mgu_print_dlist( ctl->listCriteria, stream ); - } - else { - fprintf( stream, "\t!!!none!!!\n" ); - } - pthread_mutex_unlock( ctl->mutexCtl ); -} -#endif - -/** - * Copy member variables to specified object. Mutex lock object is - * not copied. - * \param ctlFrom Object to copy from. - * \param ctlTo Destination object. - */ -void ldapctl_copy( const LdapControl *ctlFrom, LdapControl *ctlTo ) { - GList *node; - - cm_return_if_fail( ctlFrom != NULL ); - cm_return_if_fail( ctlTo != NULL ); - - debug_print("ldap controller copy\n"); - /* Lock both objects */ - pthread_mutex_lock( ctlFrom->mutexCtl ); - pthread_mutex_lock( ctlTo->mutexCtl ); - - /* Clear our destination */ - ldapctl_clear( ctlTo ); - - /* Copy strings */ - ctlTo->hostName = g_strdup( ctlFrom->hostName ); - ctlTo->baseDN = g_strdup( ctlFrom->baseDN ); - ctlTo->bindDN = g_strdup( ctlFrom->bindDN ); - ctlTo->attribEMail = g_strdup( ctlFrom->attribEMail ); - ctlTo->attribCName = g_strdup( ctlFrom->attribCName ); - ctlTo->attribFName = g_strdup( ctlFrom->attribFName ); - ctlTo->attribLName = g_strdup( ctlFrom->attribLName ); - ctlTo->attribDName = g_strdup( ctlFrom->attribDName ); - - /* Copy search criteria */ - node = ctlFrom->listCriteria; - while( node ) { - ctlTo->listCriteria = g_list_append( - ctlTo->listCriteria, g_strdup( node->data ) ); - node = g_list_next( node ); - } - - /* Copy other members */ - ctlTo->port = ctlFrom->port; - ctlTo->maxEntries = ctlFrom->maxEntries; - ctlTo->timeOut = ctlFrom->timeOut; - ctlTo->maxQueryAge = ctlFrom->maxQueryAge; - ctlTo->matchingOption = ctlFrom->matchingOption; - ctlTo->version = ctlFrom->version; - ctlTo->enableTLS = ctlFrom->enableTLS; - ctlTo->enableSSL = ctlFrom->enableSSL; - - /* Unlock */ - pthread_mutex_unlock( ctlTo->mutexCtl ); - pthread_mutex_unlock( ctlFrom->mutexCtl ); -} - -/** - * Search criteria fragment - two terms - begin with (default). - */ -static gchar *_criteria2BeginWith = "(&(givenName=%s*)(sn=%s*))"; - -/** - * Search criteria fragment - two terms - contains. - */ -static gchar *_criteria2Contains = "(&(givenName=*%s*)(sn=*%s*))"; - -/** - * Create an LDAP search criteria by parsing specified search term. The search - * term may contain two names separated by the first embedded space found in - * the search term. It is assumed that the two tokens are first name and last - * name, or vice versa. An appropriate search criteria will be constructed. - * - * \param searchTerm Reference to search term to process. - * \param matchOption Set to the following: - * <ul> - * <li><code>LDAPCTL_MATCH_BEGINWITH</code> for "begins with" search</li> - * <li><code>LDAPCTL_MATCH_CONTAINS</code> for "contains" search</li> - * </ul> - * - * \return Formatted search criteria, or <code>NULL</code> if there is no - * embedded spaces. The search term should be g_free() when no - * longer required. - */ -static gchar *ldapctl_build_ldap_criteria( - const gchar *searchTerm, const gint matchOption ) -{ - gchar *p; - gchar *t1; - gchar *t2 = NULL; - gchar *term; - gchar *crit = NULL; - gchar *criteriaFmt; - - if( matchOption == LDAPCTL_MATCH_CONTAINS ) { - criteriaFmt = _criteria2Contains; - } - else { - criteriaFmt = _criteria2BeginWith; - } - - term = g_strdup( searchTerm ); - g_strstrip( term ); - - /* Find first space character */ - t1 = p = term; - while( *p ) { - if( *p == ' ' ) { - *p = '\0'; - t2 = g_strdup( 1 + p ); - break; - } - p++; - } - - if( t2 ) { - /* Format search criteria */ - gchar *p1, *p2; - - g_strstrip( t2 ); - p1 = g_strdup_printf( criteriaFmt, t1, t2 ); - p2 = g_strdup_printf( criteriaFmt, t2, t1 ); - crit = g_strdup_printf( "(&(|%s%s)(mail=*))", p1, p2 ); - - g_free( t2 ); - g_free( p1 ); - g_free( p2 ); - } - g_free( term ); - debug_print("search criteria: %s\n", crit?crit:"null"); - return crit; -} - - -/** - * Search criteria fragment - single term - begin with (default). - */ -static gchar *_criteriaBeginWith = "(%s=%s*)"; - -/** - * Search criteria fragment - single term - contains. - */ -static gchar *_criteriaContains = "(%s=*%s*)"; - -/** - * Build a formatted LDAP search criteria string from criteria list. - * \param ctl Control object to process. - * \param searchVal Value to search for. - * \return Formatted string. Should be g_free() when done. - */ -gchar *ldapctl_format_criteria( LdapControl *ctl, const gchar *searchVal ) { - GList *node; - gchar *p1, *p2, *retVal; - gchar *criteriaFmt; - - cm_return_val_if_fail( ctl != NULL, NULL ); - cm_return_val_if_fail( searchVal != NULL, NULL ); - - /* Test whether there are more that one search terms */ - retVal = ldapctl_build_ldap_criteria( searchVal, ctl->matchingOption ); - if( retVal ) return retVal; - - if( ctl->matchingOption == LDAPCTL_MATCH_CONTAINS ) { - criteriaFmt = _criteriaContains; - } - else { - criteriaFmt = _criteriaBeginWith; - } - - /* No - just a simple search */ - /* p1 contains previous formatted criteria */ - /* p2 contains next formatted criteria */ - retVal = p1 = p2 = NULL; - node = ctl->listCriteria; - while( node ) { - gchar *attr, *tmp; - attr = node->data; - node = g_list_next( node ); - - /* Switch pointers */ - tmp = p1; p1 = p2; p2 = tmp; - - if( p1 ) { - /* Subsequent time through */ - gchar *crit; - - debug_print("crit: %s\n", searchVal); - /* fix bug when doing a search any */ - if (strcmp("*@", searchVal) == 0) { - crit = g_strdup_printf( "(%s=*)", attr ); - } - else { - /* Format query criteria */ - crit = g_strdup_printf( criteriaFmt, attr, searchVal ); - } - - /* Append to existing criteria */ - g_free( p2 ); - p2 = g_strdup_printf( "(|%s%s)", p1, crit ); - - g_free( crit ); - } - else { - /* First time through - Format query criteria */ - /* fix bug when doing a search any */ - if (strcmp("*@", searchVal) == 0) { - p2 = g_strdup_printf( "(%s=*)", attr ); - } - else { - p2 = g_strdup_printf( criteriaFmt, attr, searchVal ); - } - } - } - - if( p2 == NULL ) { - /* Nothing processed - format a default attribute */ - retVal = g_strdup_printf( "(%s=*)", LDAPCTL_ATTR_EMAIL ); - } - else { - /* We have something - free up previous result */ - retVal = p2; - } - if (p1) - g_free( p1 ); - debug_print("current search string: %s\n", retVal); - return retVal; -} - -/** - * Return array of pointers to attributes for LDAP query. - * \param ctl Control object to process. - * \return NULL terminated list. - */ -char **ldapctl_attribute_array( LdapControl *ctl ) { - char **ptrArray; - GList *node; - guint cnt, i; - cm_return_val_if_fail( ctl != NULL, NULL ); - - node = ctl->listCriteria; - cnt = g_list_length( ctl->listCriteria ); - ptrArray = g_new0( char *, 1 + cnt ); - i = 0; - while( node ) { - ptrArray[ i++ ] = node->data; - /*debug_print("adding search attribute: %s\n", (gchar *) node->data);*/ - node = g_list_next( node ); - } - ptrArray[ i ] = NULL; - return ptrArray; -} - -/** - * Return array of pointers to attributes for LDAP query. - * \param ctl Control object to process. - * \return NULL terminated list. - */ -char **ldapctl_full_attribute_array( LdapControl *ctl ) { - char **ptrArray; - GList *node, *def; - GList *tmp = NULL; - guint cnt, i; - cm_return_val_if_fail( ctl != NULL, NULL ); - - def = ctl->listCriteria; - while (def) { - tmp = g_list_append(tmp, g_strdup(def->data)); - def = def->next; - } - - def = ldapctl_get_default_criteria_list(); - node = def; - - while (node) { - if( g_list_find_custom(tmp, (gpointer)def->data, - (GCompareFunc)g_strcmp0) == NULL) { - tmp = g_list_append(tmp, g_strdup(node->data)); - } - node = node->next; - } - - g_list_free_full(def, g_free); - - node = tmp; - cnt = g_list_length( tmp ); - ptrArray = g_new0( char *, 1 + cnt); - i = 0; - while( node ) { - ptrArray[ i++ ] = node->data; - /*debug_print("adding search attribute: %s\n", (gchar *) node->data);*/ - node = g_list_next( node ); - } - g_list_free(tmp); - ptrArray[ i ] = NULL; - return ptrArray; -} - -/** - * Free array of pointers allocated by ldapctl_criteria_array(). - * param ptrArray Array to clear. - */ -void ldapctl_free_attribute_array( char **ptrArray ) { - gint i; - - /* Clear array to NULL's */ - for( i = 0; ptrArray[i] != NULL; i++ ) { - g_free(ptrArray[i]); - ptrArray[i] = NULL; - } - g_free( ptrArray ); -} - -/** - * Parse LDAP search string, building list of LDAP criteria attributes. This - * may be used to convert an old style Sylpheed LDAP search criteria to the - * new format. The old style uses a standard LDAP search string, for example: - * <pre> - * (&(mail=*)(cn=%s*)) - * </pre> - * This function extracts the two LDAP attributes <code>mail</code> and - * <code>cn</code>, adding each to a list. - * - * \param ctl Control object to process. - * \param criteria LDAP search criteria string. - */ -void ldapctl_parse_ldap_search( LdapControl *ctl, gchar *criteria ) { - gchar *ptr; - gchar *pFrom; - gchar *attrib; - gint iLen; - - cm_return_if_fail( ctl != NULL ); - - ldapctl_criteria_list_clear( ctl ); - if( criteria == NULL ) return; - - pFrom = NULL; - ptr = criteria; - while( *ptr ) { - if( *ptr == '(' ) { - pFrom = 1 + ptr; - } - if( *ptr == '=' ) { - if( pFrom ) { - iLen = ptr - pFrom; - attrib = g_strndup( pFrom, iLen ); - g_strstrip( attrib ); - ldapctl_criteria_list_add( ctl, attrib ); - g_free( attrib ); - } - pFrom = NULL; - } - ptr++; - } -} - -/** - * Return the default LDAP search criteria string. - * \return Formatted string or <i>""</i>. Should be g_free() when done. - */ -gchar *ldapctl_get_default_criteria() { - gchar *retVal = g_strdup(LDAPCTL_DFL_ATTR_LIST); - const gchar **attrs = ATTRIBUTE; - - while (*attrs) { - gchar *tmp = g_strdup_printf("%s, %s", retVal, *attrs++); - g_free(retVal); - retVal = tmp; - } - debug_print("default search criteria: %s\n", retVal); - return retVal; -} - -/** - * Return the default LDAP search criteria list. - * \return GList or <i>NULL</i>. - */ -GList *ldapctl_get_default_criteria_list() { - gchar *criteria, *item; - gchar **c_list, **w_list; - GList *attr_list = NULL; - - criteria = ldapctl_get_default_criteria(); - c_list = g_strsplit(criteria, " ", 0); - g_free(criteria); - criteria = NULL; - w_list = c_list; - while ((criteria = *w_list++) != 0) { - /* copy string elimination <,> */ - if (*w_list) - item = g_strndup(criteria, strlen(criteria) - 1); - else - item = g_strdup(criteria); - debug_print("adding attribute to list: %s\n", item); - attr_list = g_list_append(attr_list, item); - } - g_strfreev(c_list); - return attr_list; -} - -/** - * Compare to GList for equality. - * \param l1 First GList - * \param l2 Second GList - * \Return TRUE or FALSE - */ -gboolean ldapctl_compare_list(GList *l1, GList *l2) { - gchar *first, *second; - if (! l1 && ! l2) - return TRUE; - if ((! l1 && l2) || (l1 && ! l2)) - return FALSE; - while (l1 && l2) { - first = (gchar *) l1->data; - second = (gchar *) l2->data; - /*debug_print("comparing: %s = %s\n", first, second);*/ - if ( ! (first && second) || strcmp(first, second) != 0) { - return FALSE; - } - l1 = g_list_next(l1); - l2 = g_list_next(l2); - } - return TRUE; -} - -#endif /* USE_LDAP */ - -/* - * End of Source. - */ - diff --git a/src/ldapctrl.h b/src/ldapctrl.h @@ -1,118 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2003-2022 Match Grun and the Claws Mail team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * Functions for LDAP control data. - */ - -#ifndef __LDAPCTRL_H__ -#define __LDAPCTRL_H__ - -#ifdef USE_LDAP - -#include <glib.h> -#include <stdio.h> -#include <pthread.h> - -/* - * Constants. - */ -#define LDAPCTL_DFL_PORT 389 -#define LDAPCTL_DFL_SSL_PORT 636 -#define LDAPCTL_MAX_ENTRIES 30 -#define LDAPCTL_DFL_TIMEOUT 30 -#define LDAPCTL_DFL_QUERY_AGE 600 -#define LDAPCTL_MAX_QUERY_AGE 86400 - -#define LDAPCTL_ATTR_EMAIL "mail" -#define LDAPCTL_ATTR_COMMONNAME "cn" -#define LDAPCTL_ATTR_GIVENNAME "givenName" -#define LDAPCTL_ATTR_SURNAME "sn" -#define LDAPCTL_ATTR_PHONE "telephoneNumber" -#define LDAPCTL_ATTR_DISPLAYNAME "displayName" - -#define LDAPCTL_DFL_ATTR_LIST "mail, cn, givenName, sn, displayName" - -/* - * Search matching options. - */ -#define LDAPCTL_MATCH_BEGINWITH 0 -#define LDAPCTL_MATCH_CONTAINS 1 - -/* - * Data structures. - */ -typedef struct _LdapControl LdapControl; -struct _LdapControl { - gchar *hostName; - gint port; - gchar *baseDN; - gchar *bindDN; - gint maxEntries; - gint timeOut; - gint maxQueryAge; - gint matchingOption; - gint version; - gboolean enableTLS; - gboolean enableSSL; - gchar *attribEMail; - gchar *attribCName; - gchar *attribFName; - gchar *attribLName; - gchar *attribDName; - GList *listCriteria; - pthread_mutex_t *mutexCtl; -}; - -/* Function prototypes */ -LdapControl *ldapctl_create ( void ); -void ldapctl_set_host ( LdapControl* ctl, const gchar *value ); -void ldapctl_set_port ( LdapControl* ctl, const gint value ); -void ldapctl_set_base_dn ( LdapControl* ctl, const gchar *value ); -void ldapctl_set_bind_dn ( LdapControl* ctl, const gchar *value ); -void ldapctl_set_bind_password - ( LdapControl* ctl, const gchar *value, gboolean encrypt, gboolean change ); -gchar* ldapctl_get_bind_password ( LdapControl* ctl ); -void ldapctl_set_max_entries ( LdapControl* ctl, const gint value ); -void ldapctl_set_timeout ( LdapControl* ctl, const gint value ); -void ldapctl_set_max_query_age ( LdapControl* ctl, const gint value ); -void ldapctl_set_matching_option( LdapControl* ctl, const gint value ); -void ldapctl_set_tls ( LdapControl* ctl, const gboolean value ); -void ldapctl_set_ssl ( LdapControl* ctl, const gboolean value ); -GList *ldapctl_get_criteria_list( const LdapControl* ctl ); -void ldapctl_criteria_list_clear( LdapControl *ctl ); -void ldapctl_criteria_list_add ( LdapControl *ctl, gchar *attr ); -void ldapctl_free ( LdapControl *ctl ); -#ifdef DEBUG_LDAP -void ldapctl_print ( const LdapControl *ctl, FILE *stream ); -#endif -void ldapctl_copy ( const LdapControl *ctlFrom, - LdapControl *ctlTo ); -gchar *ldapctl_format_criteria ( LdapControl *ctl, const gchar *searchVal ); -char **ldapctl_attribute_array ( LdapControl *ctl ); -char **ldapctl_full_attribute_array( LdapControl *ctl ); -void ldapctl_free_attribute_array( char **ptrArray ); -void ldapctl_parse_ldap_search ( LdapControl *ctl, gchar *criteria ); -gchar *ldapctl_get_default_criteria(void); -GList *ldapctl_get_default_criteria_list(); -gboolean ldapctl_compare_list(GList *l1, GList *l2); - -#endif /* USE_LDAP */ - -#endif /* __LDAPCTRL_H__ */ - diff --git a/src/ldaplocate.c b/src/ldaplocate.c @@ -1,152 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2003-2012 Match Grun and the Claws Mail team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -/* - * Functions to perform searches for LDAP entries. - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#include "claws-features.h" -#endif - -#ifdef USE_LDAP - -#include <glib.h> -#include "addrquery.h" -#include "ldapserver.h" -#include "ldapquery.h" - -void ldapsvr_add_query( LdapServer *server, LdapQuery *qry ); -void ldapsvr_execute_query( LdapServer *server, LdapQuery *qry ); -/** - * Setup the search that will be performed and registered with the query - * manager. - * - * \param server LDAP server object. - * \param searchTerm Search term to locate. - * \param callBackEntry Function to call when each attribute is returned. - * \param callBackEnd Function to call when search is complete. - * \return Query ID allocated to query that will be executed. - */ -gint ldaplocate_search_setup( - LdapServer *server, const gchar *searchTerm, void *callBackEntry, - void *callBackEnd ) -{ - QueryRequest *req; - LdapQuery *qry; - gint queryID; - gchar *name; - - /* Name the query */ - name = g_strdup_printf( "Locate '%s'", searchTerm ); - - /* Set up a generic address query */ - req = qrymgr_add_request( searchTerm, callBackEnd, callBackEntry ); - qryreq_set_search_type( req, ADDRSEARCH_LOCATE ); - queryID = req->queryID; - - /* Construct a query */ - qry = ldapqry_create(); - ldapqry_set_query_id( qry, queryID ); - ldapqry_set_name( qry, name ); - ldapqry_set_search_value( qry, searchTerm ); - ldapqry_set_search_type( qry, ADDRSEARCH_LOCATE ); - ldapqry_set_callback_end( qry, callBackEnd ); - ldapqry_set_callback_entry( qry, callBackEntry ); - - /* Setup server */ - ldapsvr_add_query( server, qry ); - - /* Set up query request */ - qryreq_add_query( req, ADDRQUERY_OBJECT(qry) ); - - g_free( name ); - - return queryID; -} - -/** - * Perform the previously registered search. - * \param queryID ID of search query to be executed. - * \return <i>TRUE</i> if search started successfully, or <i>FALSE</i> if - * failed. - */ -gboolean ldaplocate_search_start( const gint queryID ) { - gboolean retVal; - LdapServer *server; - LdapQuery *qry; - QueryRequest *req; - AddrQueryObject *aqo; - - retVal = FALSE; - req = qrymgr_find_request( queryID ); - if( req == NULL ) { - return retVal; - } - - /* Note: there should only be one query in the list */ - aqo = req->queryList->data; - if( aqo->queryType == ADDRQUERY_LDAP ) { - qry = ( LdapQuery * ) aqo; - server = qry->server; - - /* Retire any aged queries */ - ldapsvr_retire_query( server ); - - /* Start the search */ - retVal = TRUE; - ldapsvr_execute_query( server, qry ); - } - return retVal; -} - -/** - * Notify search to stop execution. - * \param queryID Query to terminate. - */ -void ldaplocate_search_stop( const gint queryID ) { - QueryRequest *req; - AddrQueryObject *aqo; - LdapQuery *qry; - - req = qrymgr_find_request( queryID ); - if( req == NULL ) { - return; - } - - aqo = req->queryList->data; - if( aqo->queryType == ADDRQUERY_LDAP ) { - /* Notify query to stop */ - qry = ( LdapQuery * ) aqo; - ldapqry_set_stop_flag( qry, TRUE ); - } - req->queryList->data = NULL; - - /* Delete query */ - qrymgr_delete_request( queryID ); -} - -#endif /* USE_LDAP */ - -/* - * End of Source. - */ - - diff --git a/src/ldaplocate.h b/src/ldaplocate.h @@ -1,44 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2003-2012 Match Grun and the Claws Mail team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -/* - * Functions to perform searches for LDAP entries. - */ - -#ifndef __LDAPLOCATE_H__ -#define __LDAPLOCATE_H__ - -#ifdef USE_LDAP - -#include <glib.h> -#include "ldapserver.h" - -/* Function prototypes */ -gint ldaplocate_search_setup ( LdapServer *server, - const gchar *searchTerm, - void *callBackEntry, - void *callBackEnd ); -gboolean ldaplocate_search_start( const gint queryID ); -void ldaplocate_search_stop ( const gint queryID ); - -#endif /* USE_LDAP */ - -#endif /* __LDAPLOCATE_H__ */ - - diff --git a/src/ldapquery.c b/src/ldapquery.c @@ -1,1380 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2003-2022 Match Grun and the Claws Mail team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * Functions necessary to define and perform LDAP queries. - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#include "claws-features.h" -#endif - -#ifdef USE_LDAP - -#include <glib.h> -#include <glib/gi18n.h> -#include <sys/time.h> -#include <string.h> - -#include "defs.h" -#include "ldaputil.h" -#include "ldapquery.h" -#include "ldapctrl.h" -#include "ldapserver.h" -#include "mgutils.h" -#include "file-utils.h" - -#include "addritem.h" -#include "addrcache.h" -#include "common/utils.h" -#include "log.h" - -/* - * Key for thread specific data. - */ -static pthread_key_t _queryThreadKey_; -static gboolean _queryThreadInit_ = FALSE; - -static gboolean callbackend (gpointer data) -{ - LdapQuery *qry = (LdapQuery *)data; - qry->callBackEnd( qry, ADDRQUERY_ID(qry), ADDRQUERY_RETVAL(qry), qry->data ); - return FALSE; -} - - -/** - * Create new LDAP query object. - * \return Initialized query object. - */ -LdapQuery *ldapqry_create( void ) { - LdapQuery *qry; - - qry = g_new0( LdapQuery, 1 ); - ADDRQUERY_TYPE(qry) = ADDRQUERY_LDAP; - ADDRQUERY_ID(qry) = 0; - ADDRQUERY_SEARCHTYPE(qry) = ADDRSEARCH_NONE; - ADDRQUERY_NAME(qry) = NULL; - ADDRQUERY_RETVAL(qry) = LDAPRC_SUCCESS; - ADDRQUERY_FOLDER(qry) = NULL; - ADDRQUERY_SEARCHVALUE(qry) = NULL; - qry->control = NULL; - qry->server = NULL; - qry->entriesRead = 0; - qry->elapsedTime = 0; - qry->stopFlag = FALSE; - qry->busyFlag = FALSE; - qry->agedFlag = FALSE; - qry->completed = FALSE; - qry->thread = NULL; - qry->callBackEntry = NULL; - qry->callBackEnd = NULL; - qry->ldap = NULL; - qry->data = NULL; - - /* Mutex to protect stop and busy flags */ - qry->mutexStop = g_malloc0( sizeof( pthread_mutex_t ) ); - pthread_mutex_init( qry->mutexStop, NULL ); - qry->mutexBusy = g_malloc0( sizeof( pthread_mutex_t ) ); - pthread_mutex_init( qry->mutexBusy, NULL ); - - /* Mutex to protect critical section */ - qry->mutexEntry = g_malloc0( sizeof( pthread_mutex_t ) ); - pthread_mutex_init( qry->mutexEntry, NULL ); - - return qry; -} - -/** - * Specify the reference to control data that will be used for the query. The calling - * module should be responsible for creating and destroying this control object. - * \param qry Query object. - * \param ctl Control object. - */ -void ldapqry_set_control( LdapQuery *qry, LdapControl *ctl ) { - cm_return_if_fail( qry != NULL ); - qry->control = ctl; -} - -/** - * Specify query name to be used. - * \param qry Query object. - * \param value Name. - */ -void ldapqry_set_name( LdapQuery* qry, const gchar *value ) { - cm_return_if_fail( qry != NULL ); - ADDRQUERY_NAME(qry) = mgu_replace_string( ADDRQUERY_NAME(qry), value ); - if (ADDRQUERY_NAME(qry) == NULL) - return; - g_strstrip( ADDRQUERY_NAME(qry) ); - debug_print("set name: %s\n", ADDRQUERY_NAME(qry)); -} - -/** - * Specify search value to be used. - * \param qry Query object. - * \param value - */ -void ldapqry_set_search_value( LdapQuery *qry, const gchar *value ) { - cm_return_if_fail( qry != NULL ); - ADDRQUERY_SEARCHVALUE(qry) = mgu_replace_string( ADDRQUERY_SEARCHVALUE(qry), value ); - if (ADDRQUERY_SEARCHVALUE(qry) == NULL) - return; - g_strstrip( ADDRQUERY_SEARCHVALUE(qry) ); - debug_print("search value: %s\n", ADDRQUERY_SEARCHVALUE(qry)); -} - -/** - * Specify query type. - * \param qry Query object. - * \param value Query type, either: - * <ul> - * <li><code>LDAPQUERY_NONE</code></li> - * <li><code>LDAPQUERY_STATIC</code></li> - * <li><code>LDAPQUERY_DYNAMIC</code></li> - * </ul> - */ -/* -void ldapqry_set_query_type( LdapQuery* qry, const gint value ) { - ADDRQUERY_TYPE(qry) = value; -} -*/ - -/** - * Specify search type. - * \param qry Query object. - * \param value Type. - */ -void ldapqry_set_search_type( LdapQuery *qry, const AddrSearchType value ) { - cm_return_if_fail( qry != NULL ); - ADDRQUERY_SEARCHTYPE(qry) = value; -} - -/** - * Specify query ID. - * \param qry Query object. - * \param value ID for the query. - */ -void ldapqry_set_query_id( LdapQuery* qry, const gint value ) { - cm_return_if_fail( qry != NULL ); - ADDRQUERY_ID(qry) = value; -} - -/** - * Register a callback function that will be executed when each entry - * has been read and processed. When called, the function will be passed - * this query object and a GList of ItemEMail objects as arguments. An - * example of typical usage is shown below. - * - * <pre> - * ------------------------------------------------------------ - * void myCallbackEntry( LdapQuery *qry, GList *listEMail ) { - * GList *node; - * - * node = listEMail; - * while( node ) { - * ItemEMail *email = node->data; - * ... process email object ... - * node = g_list_next( node ); - * } - * g_list_free( listEMail ); - * } - * ... - * ... - * ldapqry_set_callback_entry( qry, myCallbackEntry ); - * ------------------------------------------------------------ - * </pre> - * - * \param qry Query object. - * \param func Function. - */ -void ldapqry_set_callback_entry( LdapQuery *qry, void *func ) { - pthread_mutex_lock( qry->mutexEntry ); - qry->callBackEntry = func; - pthread_mutex_unlock( qry->mutexEntry ); -} - -/** - * Register a callback function that will be executed when the search - * is complete. When called, the function will be passed this query - * object as an argument. - * \param qry Query object. - * \param func Function. - */ -void ldapqry_set_callback_end( LdapQuery *qry, void *func ) { - qry->callBackEnd = func; -} - -/** - * Notify query to start/stop executing. This method should be called with a - * value if <i>TRUE</i> to terminate an existing running query. - * - * \param qry Query object. - * \param value Value of stop flag. - */ -void ldapqry_set_stop_flag( LdapQuery *qry, const gboolean value ) { - cm_return_if_fail( qry != NULL ); - - pthread_mutex_lock( qry->mutexStop ); - qry->stopFlag = value; - pthread_mutex_unlock( qry->mutexStop ); -} - -/** - * Test value of stop flag. This method should be used to determine whether a - * query has stopped running. - * \param qry Query object. - * \return Value of stop flag. - */ -static gboolean ldapqry_get_stop_flag( LdapQuery *qry ) { - gboolean value; - cm_return_val_if_fail( qry != NULL, TRUE ); - - pthread_mutex_lock( qry->mutexStop ); - value = qry->stopFlag; - pthread_mutex_unlock( qry->mutexStop ); - return value; -} - -/** - * Set busy flag. - * \param qry Query object. - * \param value Value of busy flag. - */ -static void ldapqry_set_busy_flag( LdapQuery *qry, const gboolean value ) { - cm_return_if_fail( qry != NULL ); - if (qry->mutexBusy == NULL) - return; /* exiting, mutex already freed */ - - pthread_mutex_lock( qry->mutexBusy ); - qry->busyFlag = value; - pthread_mutex_unlock( qry->mutexBusy ); -} - -/** - * Test value of busy flag. This method will return a value of <i>FALSE</i> - * when a query has completed running. - * \param qry Query object. - * \return Value of busy flag. - */ -static gboolean ldapqry_get_busy_flag( LdapQuery *qry ) { - gboolean value; - cm_return_val_if_fail( qry != NULL, FALSE ); - - pthread_mutex_lock( qry->mutexBusy ); - value = qry->busyFlag; - pthread_mutex_unlock( qry->mutexBusy ); - return value; -} - -/** - * Set query aged flag. - * \param qry Query object. - * \param value Value of aged flag. - */ -static void ldapqry_set_aged_flag( LdapQuery *qry, const gboolean value ) { - cm_return_if_fail( qry != NULL ); - qry->agedFlag = value; -} - -/** - * Clear LDAP query member variables. - * \param qry Query object. - */ -static void ldapqry_clear( LdapQuery *qry ) { - cm_return_if_fail( qry != NULL ); - - /* Free internal stuff */ - g_free( ADDRQUERY_NAME(qry) ); - g_free( ADDRQUERY_SEARCHVALUE(qry) ); - - /* Clear pointers and value */ - ADDRQUERY_NAME(qry) = NULL; - ADDRQUERY_SEARCHVALUE(qry) = NULL; - ADDRQUERY_ID(qry) = 0; - ADDRQUERY_SEARCHTYPE(qry) = ADDRSEARCH_NONE; - ADDRQUERY_RETVAL(qry) = LDAPRC_SUCCESS; - qry->entriesRead = 0; - qry->elapsedTime = 0; - qry->stopFlag = FALSE; - qry->busyFlag = FALSE; - qry->agedFlag = FALSE; - qry->completed = FALSE; - qry->callBackEntry = NULL; - qry->callBackEnd = NULL; - qry->ldap = NULL; - qry->data = NULL; -} - -/** - * Free up LDAP query object by releasing internal memory. Note that - * the thread object will be freed by the OS. - * \param qry Query object to process. - */ -void ldapqry_free( LdapQuery *qry ) { - cm_return_if_fail( qry != NULL ); - - /* Clear out internal members */ - ADDRQUERY_TYPE(qry) = ADDRQUERY_NONE; - ldapqry_clear( qry ); - - /* Free the mutex */ - pthread_mutex_destroy( qry->mutexStop ); - pthread_mutex_destroy( qry->mutexBusy ); - pthread_mutex_destroy( qry->mutexEntry ); - g_free( qry->mutexStop ); - g_free( qry->mutexBusy ); - g_free( qry->mutexEntry ); - qry->mutexEntry = NULL; - qry->mutexBusy = NULL; - qry->mutexStop = NULL; - - /* Do not free folder - parent server object should free */ - ADDRQUERY_FOLDER(qry) = NULL; - - /* Do not free thread - thread should be terminated before freeing */ - qry->thread = NULL; - - /* Do not free LDAP control - should be destroyed before freeing */ - qry->control = NULL; - - /* Now release object */ - g_free( qry ); -} - -/** - * Free linked lists of character strings. - * \param listName List of common names. - * \param listAddr List of addresses. - * \param listFirst List of first names. - * \param listLast List of last names. - */ -static void ldapqry_free_lists( - GSList *listName, GSList *listAddr, GSList *listFirst, - GSList *listLast, GSList *listDisplay, GSList *other_attrs ) -{ - GSList *cur = other_attrs; - g_slist_free_full( listName, g_free ); - g_slist_free_full( listAddr, g_free ); - g_slist_free_full( listFirst, g_free ); - g_slist_free_full( listLast, g_free ); - g_slist_free_full( listDisplay, g_free ); - for(;cur; cur = cur->next) - addritem_free_attribute((UserAttribute *)cur->data); - g_slist_free(other_attrs); -} - -/** - * Add all LDAP attribute values to a list. - * \param ld LDAP handle. - * \param entry LDAP entry to process. - * \param attr LDAP attribute. - * \return List of values. - */ -static GSList *ldapqry_add_list_values( - LDAP *ld, LDAPMessage *entry, char *attr ) -{ - GSList *list = NULL; - gint i; - struct berval **vals; - - if( ( vals = ldap_get_values_len( ld, entry, attr ) ) != NULL ) { - for( i = 0; vals[i] != NULL; i++ ) { - /*debug_print("lv\t%s: %s\n", attr?attr:"null", - vals[i]->bv_val?vals[i]->bv_val:"null");*/ - list = g_slist_append( list, g_strndup( vals[i]->bv_val, vals[i]->bv_len) ); - } - } - ldap_value_free_len( vals ); - return list; -} - -/** - * Add a single attribute value to a list. - * \param ld LDAP handle. - * \param entry LDAP entry to process. - * \param attr LDAP attribute name to process. - * \return List of values; only one value will be present. - */ -static GSList *ldapqry_add_single_value( LDAP *ld, LDAPMessage *entry, char *attr ) { - GSList *list = NULL; - struct berval **vals; - - if( ( vals = ldap_get_values_len( ld, entry, attr ) ) != NULL ) { - if( vals[0] != NULL ) { - if (strcmp(attr, "jpegPhoto")) { - debug_print("sv\t%s: %s\n", attr?attr:"null", - vals[0]->bv_val?vals[0]->bv_val:"null"); - list = g_slist_append( list, g_strndup( vals[0]->bv_val, vals[0]->bv_len )); - } else { - char *file = get_tmp_file(); - FILE *fp = claws_fopen(file, "wb"); - if (fp) { - claws_fwrite(vals[0]->bv_val, 1, vals[0]->bv_len, fp); - claws_safe_fclose(fp); - } - list = g_slist_append( list, file); - } - } - } - ldap_value_free_len( vals ); - return list; -} - -/** - * Build an address list entry and append to list of address items. Name is formatted - * as "<first-name> <last-name>". - * - * \param cache Address cache to load. - * \param qry Query object to process. - * \param dn DN for entry found on server. - * \param listName List of common names for entry; see notes below. - * \param listAddr List of EMail addresses for entry. - * \param listFirst List of first names for entry. - * \param listLast List of last names for entry. - * - * \return List of ItemEMail objects. - * - * Notes: - * 1) Each LDAP server entry may have multiple LDAP attributes with the same - * name. For example, a single entry for a person may have more than one - * common name, email address, etc. -* - * 2) The DN for the entry is unique for the server. - */ -static GList *ldapqry_build_items_fl( - AddressCache *cache, LdapQuery *qry, gchar *dn, - GSList *listName, GSList *listAddr, GSList *listFirst, - GSList *listLast, GSList *listDisplay, GSList *attributes ) -{ - GSList *nodeAddress, *cur; - gchar *firstName = NULL, *lastName = NULL, *fullName = NULL; - gboolean allocated = FALSE; - ItemPerson *person; - ItemEMail *email; - ItemFolder *folder; - gchar *picfile = NULL; - GList *listReturn = NULL; - - folder = ADDRQUERY_FOLDER(qry); - if( folder == NULL ) return listReturn; - if( listAddr == NULL ) return listReturn; - - if ( listDisplay ) { - allocated = FALSE; - fullName = listDisplay->data; - } - - /* Find longest first name in list */ - firstName = mgu_slist_longest_entry( listFirst ); - - /* Format last name */ - if( listLast ) { - lastName = listLast->data; - } - - if ( fullName == NULL ) { - /* Find longest common name */ - allocated = FALSE; - fullName = mgu_slist_longest_entry( listName ); - if( fullName == NULL ) { - /* Format a full name from first and last names */ - if( firstName ) { - if( lastName ) { - fullName = g_strdup_printf( "%s %s", firstName, lastName ); - } - else { - fullName = g_strdup_printf( "%s", firstName ); - } - } - else { - if( lastName ) { - fullName = g_strdup_printf( "%s", lastName ); - } - } - if( fullName ) { - g_strstrip( fullName ); - allocated = TRUE; - } - } - } - - /* Add person into folder */ - person = addritem_create_item_person(); - addritem_person_set_common_name( person, fullName ); - addritem_person_set_first_name( person, firstName ); - addritem_person_set_last_name( person, lastName ); - addritem_person_set_nick_name( person, fullName ); - addrcache_id_person( cache, person ); - addritem_person_set_external_id( person, dn ); - - for (cur = attributes; cur; cur = cur->next) { - UserAttribute *attrib = addritem_copy_attribute((UserAttribute *)cur->data); - if (attrib->name && strcmp(attrib->name, "jpegPhoto")) { - addritem_person_add_attribute( person, attrib ); - } else { - if (qry->server && qry->server->control) { - gchar *dir = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, - ADDRBOOK_DIR, G_DIR_SEPARATOR_S, NULL ); - gchar *filename = g_strdup_printf("%s-%s-%s", - qry->server->control->hostName?qry->server->control->hostName:"nohost", - qry->server->control->baseDN?qry->server->control->baseDN:"nobase", - dn); - picfile = g_strdup_printf("%s%s.png", dir, filename); - addritem_person_set_picture( person, filename ); - rename_force(attrib->value, picfile); - g_free(filename); - g_free(picfile); - g_free(dir); - } - addritem_free_attribute(attrib); - } - } - - addrcache_folder_add_person( cache, ADDRQUERY_FOLDER(qry), person ); - - qry->entriesRead++; - - /* Add each address item */ - nodeAddress = listAddr; - while( nodeAddress ) { - email = addritem_create_item_email(); - addritem_email_set_address( email, nodeAddress->data ); - addrcache_id_email( cache, email ); - addrcache_person_add_email( cache, person, email ); - addritem_person_add_email( person, email ); - /*if (debug_get_mode()) { - addritem_print_item_email(email, stdout); - }*/ - listReturn = g_list_append( listReturn, email ); - nodeAddress = g_slist_next( nodeAddress ); - } - - /* Free any allocated memory */ - if( allocated ) { - g_free( fullName ); - } - fullName = firstName = lastName = NULL; - - return listReturn; -} - -/** - * Process a single search entry. - * \param cache Address cache to load. - * \param qry Query object to process. - * \param ld LDAP handle. - * \param e LDAP message. - * \return List of EMail objects found. - */ -static GList *ldapqry_process_single_entry( - AddressCache *cache, LdapQuery *qry, LDAP *ld, LDAPMessage *e ) -{ - char *dnEntry; - char *attribute; - LdapControl *ctl; - BerElement *ber; - GSList *listName = NULL, *listAddress = NULL; - GSList *listFirst = NULL, *listLast = NULL; - GSList *listDisplay = NULL; - GSList *other_attrs = NULL; - GList *listReturn; - - listReturn = NULL; - ctl = qry->control; - dnEntry = ldap_get_dn( ld, e ); - debug_print( "DN: %s\n", dnEntry?dnEntry:"null" ); - - /* Process all attributes */ - for( attribute = ldap_first_attribute( ld, e, &ber ); attribute != NULL; - attribute = ldap_next_attribute( ld, e, ber ) ) { - if( strcasecmp( attribute, ctl->attribEMail ) == 0 ) { - listAddress = ldapqry_add_list_values( ld, e, attribute ); - } - else if( strcasecmp( attribute, ctl->attribCName ) == 0 ) { - listName = ldapqry_add_list_values( ld, e, attribute ); - } - else if( strcasecmp( attribute, ctl->attribFName ) == 0 ) { - listFirst = ldapqry_add_list_values( ld, e, attribute ); - } - else if( strcasecmp( attribute, ctl->attribLName ) == 0 ) { - listLast = ldapqry_add_single_value( ld, e, attribute ); - } else if( strcasecmp( attribute, ctl->attribDName ) == 0 ) { - listDisplay = ldapqry_add_single_value( ld, e, attribute ); - } else { - GSList *attlist = ldapqry_add_single_value( ld, e, attribute ); - const gchar *attvalue = attlist?((gchar *)attlist->data):NULL; - if (attvalue) { - UserAttribute *attrib = addritem_create_attribute(); - addritem_attrib_set_name( attrib, attribute ); - addritem_attrib_set_value( attrib, attvalue ); - other_attrs = g_slist_prepend(other_attrs, attrib); - } - g_slist_free_full(attlist, g_free); - } - /* Free memory used to store attribute */ - ldap_memfree( attribute ); - } - - /* Format and add items to cache */ - listReturn = ldapqry_build_items_fl( - cache, qry, dnEntry, listName, listAddress, listFirst, listLast, listDisplay, other_attrs ); - - /* Free up */ - ldapqry_free_lists( listName, listAddress, listFirst, listLast, listDisplay, other_attrs ); - listName = listAddress = listFirst = listLast = listDisplay = other_attrs = NULL; - - if( ber != NULL ) { - ber_free( ber, 0 ); - } - ldap_memfree( dnEntry ); - - return listReturn; -} - -/** - * Check parameters that are required for a search. This should - * be called before performing a search. - * \param qry Query object to process. - * \return <i>TRUE</i> if search criteria appear OK. - */ -gboolean ldapqry_check_search( LdapQuery *qry ) { - LdapControl *ctl; - ADDRQUERY_RETVAL(qry) = LDAPRC_CRITERIA; - - /* Test for control data */ - ctl = qry->control; - if( ctl == NULL ) { - return FALSE; - } - - /* Test for search value */ - if( ADDRQUERY_SEARCHVALUE(qry) == NULL ) { - return FALSE; - } - if( strlen( ADDRQUERY_SEARCHVALUE(qry) ) < 1 ) { - return FALSE; - } - ADDRQUERY_RETVAL(qry) = LDAPRC_SUCCESS; - return TRUE; -} - -/** - * Touch the query. This nudges the touch time with the current time. - * \param qry Query object to process. - */ -void ldapqry_touch( LdapQuery *qry ) { - qry->touchTime = time( NULL ); - qry->agedFlag = FALSE; -} - -/** - * Connect to LDAP server. - * \param qry Query object to process. - * \return Error/status code. - */ -static gint ldapqry_connect( LdapQuery *qry ) { - LdapControl *ctl; - LDAP *ld = NULL; - - /* Initialize connection */ - if (debug_get_mode()) { - debug_print("===ldapqry_connect===\n"); -#ifdef DEBUG_LDAP - ldapqry_print(qry, stdout); -#endif - } - ctl = qry->control; -#ifdef DEBUG_LDAP - if (debug_get_mode()) { - ldapctl_print(ctl, stdout); - debug_print("======\n"); - } -#endif - ldapqry_touch( qry ); - qry->startTime = qry->touchTime; - qry->elapsedTime = -1; - ADDRQUERY_RETVAL(qry) = LDAPRC_INIT; - - ld = ldapsvr_connect(ctl); - - if (ld == NULL) - return ADDRQUERY_RETVAL(qry); - - qry->ldap = ld; - ADDRQUERY_RETVAL(qry) = LDAPRC_STOP_FLAG; - if( ldapqry_get_stop_flag( qry ) ) { - return ADDRQUERY_RETVAL(qry); - } - ldapqry_touch( qry ); - - debug_print("connected to LDAP host %s on port %d\n", - ctl->hostName?ctl->hostName:"null", ctl->port); - - ADDRQUERY_RETVAL(qry) = LDAPRC_STOP_FLAG; - if( ldapqry_get_stop_flag( qry ) ) { - return ADDRQUERY_RETVAL(qry); - } - ldapqry_touch( qry ); - - ADDRQUERY_RETVAL(qry) = LDAP_SUCCESS; - - return ADDRQUERY_RETVAL(qry); -} - -/** - * Connect to LDAP server. - * \param qry Query object to process. - * \return Error/status code. - */ -static gint ldapqry_disconnect( LdapQuery *qry ) { - gint rc; - /* Disconnect */ - if( qry->ldap ) { - rc = ldap_unbind_ext( qry->ldap, NULL, NULL ); - if (rc != LDAP_SUCCESS) { - log_error(LOG_PROTOCOL, _("LDAP error (unbind): %d (%s)\n"), - rc, ldaputil_get_error(qry->ldap)); - } else { - log_print(LOG_PROTOCOL, _("LDAP (unbind): successful\n")); - } - } - qry->ldap = NULL; - - ldapqry_touch( qry ); - qry->elapsedTime = qry->touchTime - qry->startTime; - - return ADDRQUERY_RETVAL(qry); -} - -/** - * Perform the LDAP search, reading LDAP entries into cache. - * Note that one LDAP entry can have multiple values for many of its - * attributes. If these attributes are E-Mail addresses; these are - * broken out into separate address items. For any other attribute, - * only the first occurrence is read. - * - * \param qry Query object to process. - * \return Error/status code. - */ -static gint ldapqry_search_retrieve( LdapQuery *qry ) { - LdapControl *ctl; - LDAP *ld; - LDAPMessage *result = NULL, *e = NULL; - char **attribs; - gchar *criteria; - gboolean searchFlag; - gboolean entriesFound; - gboolean first; - struct timeval timeout; - gint rc; - AddressCache *cache; - GList *listEMail; - - /* Initialize some variables */ - ld = qry->ldap; - ctl = qry->control; - cache = qry->server->addressCache; - timeout.tv_sec = ctl->timeOut; - timeout.tv_usec = 0L; - entriesFound = FALSE; - ADDRQUERY_RETVAL(qry) = LDAPRC_SUCCESS; - - /* Define all attributes we are interested in. */ - attribs = ldapctl_full_attribute_array( ctl ); - - /* Create LDAP search string */ - criteria = ldapctl_format_criteria( ctl, ADDRQUERY_SEARCHVALUE(qry) ); - debug_print("Search criteria ::%s::\n", criteria?criteria:"null"); - - /* - * Execute the search - this step may take some time to complete - * depending on network traffic and server response time. - */ - ADDRQUERY_RETVAL(qry) = LDAPRC_TIMEOUT; - rc = ldap_search_ext_s( ld, ctl->baseDN, LDAP_SCOPE_SUBTREE, criteria, - attribs, 0, NULL, NULL, &timeout, 0, &result ); - debug_print("LDAP ldap_search_ext_s: %d (%s)\n", rc, ldaputil_get_error(ld)); - ldapctl_free_attribute_array( attribs ); - g_free( criteria ); - criteria = NULL; - if( rc == LDAP_TIMEOUT ) { - log_warning(LOG_PROTOCOL, _("LDAP (search): timeout\n")); - return ADDRQUERY_RETVAL(qry); - } - ADDRQUERY_RETVAL(qry) = LDAPRC_SEARCH; - - /* Test valid returns */ - searchFlag = FALSE; - if( rc == LDAP_ADMINLIMIT_EXCEEDED ) { - log_warning(LOG_PROTOCOL, _("LDAP (search): server limits exceeded\n")); - searchFlag = TRUE; - } - else if( rc == LDAP_SUCCESS ) { - log_print(LOG_PROTOCOL, _("LDAP (search): successful\n")); - searchFlag = TRUE; - } - else if( rc == LDAP_PARTIAL_RESULTS || (result && ldap_count_entries(ld, result) > 0) ) { - log_print(LOG_PROTOCOL, _("LDAP (search): successful (partial results)\n")); - searchFlag = TRUE; - } - else { - log_error(LOG_PROTOCOL, _("LDAP error (search): %d (%s)\n"), rc, ldaputil_get_error(ld)); - return ADDRQUERY_RETVAL(qry); - } - ADDRQUERY_RETVAL(qry) = LDAPRC_STOP_FLAG; - -#ifdef G_OS_WIN32 - debug_print("Total results are: %lu\n", ldap_count_entries(ld, result)); -#else - debug_print("Total results are: %d\n", ldap_count_entries(ld, result)); -#endif - - /* Process results */ - first = TRUE; - while( searchFlag ) { - ldapqry_touch( qry ); - if( qry->entriesRead >= ctl->maxEntries ) break; - - /* Test for stop */ - if( ldapqry_get_stop_flag( qry ) ) { - break; - } - - /* Retrieve entry */ - if( first ) { - first = FALSE; - e = ldap_first_entry( ld, result ); - } - else { - e = ldap_next_entry( ld, e ); - } - if( e == NULL ) break; - entriesFound = TRUE; - - /* Setup a critical section here */ - pthread_mutex_lock( qry->mutexEntry ); - - /* Process entry */ - listEMail = ldapqry_process_single_entry( cache, qry, ld, e ); - - /* Process callback */ - if( qry->callBackEntry ) - qry->callBackEntry( qry, ADDRQUERY_ID(qry), listEMail, qry->data ); - else - g_list_free( listEMail ); - pthread_mutex_unlock( qry->mutexEntry ); - } - - /* Free up and disconnect */ - ldap_msgfree( result ); - - if( searchFlag ) { - if( entriesFound ) { - ADDRQUERY_RETVAL(qry) = LDAPRC_SUCCESS; - } - else { - ADDRQUERY_RETVAL(qry) = LDAPRC_NOENTRIES; - } - } - - return ADDRQUERY_RETVAL(qry); -} - -/** - * Connection, perform search and disconnect. - * \param qry Query object to process. - * \return Error/status code. - */ -static gint ldapqry_perform_search( LdapQuery *qry ) { - /* Check search criteria */ - if( ! ldapqry_check_search( qry ) ) { - return ADDRQUERY_RETVAL(qry); - } - - /* Connect */ - qry->ldap = NULL; - ldapqry_connect( qry ); - if( ADDRQUERY_RETVAL(qry) == LDAPRC_SUCCESS ) { - /* Perform search */ - ldapqry_search_retrieve( qry ); - } - /* Disconnect */ - ldapqry_disconnect( qry ); - qry->ldap = NULL; - - return ADDRQUERY_RETVAL(qry); -} - -static gint ldapqry_perform_locate( LdapQuery *qry ); - -/** - * Wrapper around search. - * \param qry Query object to process. - * \return Error/status code. - */ -static gint ldapqry_search( LdapQuery *qry ) { - gint retVal; - - cm_return_val_if_fail( qry != NULL, -1 ); - cm_return_val_if_fail( qry->control != NULL, -1 ); - - ldapqry_touch( qry ); - qry->completed = FALSE; - - /* Setup pointer to thread specific area */ - pthread_setspecific( _queryThreadKey_, qry ); - - pthread_detach( pthread_self() ); - - /* Now perform the search */ - qry->entriesRead = 0; - ADDRQUERY_RETVAL(qry) = LDAPRC_SUCCESS; - ldapqry_set_busy_flag( qry, TRUE ); - ldapqry_set_stop_flag( qry, FALSE ); - if( ADDRQUERY_SEARCHTYPE(qry) == ADDRSEARCH_LOCATE ) { - retVal = ldapqry_perform_locate( qry ); - } - else { - retVal = ldapqry_perform_search( qry ); - } - if( retVal == LDAPRC_SUCCESS ) { - qry->server->addressCache->dataRead = TRUE; - qry->server->addressCache->accessFlag = FALSE; - if( ldapqry_get_stop_flag( qry ) ) { - debug_print("Search was terminated prematurely\n"); - } - else { - ldapqry_touch( qry ); - qry->completed = TRUE; - debug_print("Search ran to completion\n"); - } - } - ldapqry_set_stop_flag( qry, TRUE ); - ldapqry_set_busy_flag( qry, FALSE ); - - /* Process callback */ - if( qry->callBackEnd ) { - g_timeout_add(0, callbackend, qry); - } - - return ADDRQUERY_RETVAL(qry); -} - -/** - * Read data into list using a background thread. Callback function will be - * notified when search is complete. - * \param qry Query object to process. - * \return Error/status code. - */ -gint ldapqry_read_data_th( LdapQuery *qry ) { - cm_return_val_if_fail( qry != NULL, -1 ); - cm_return_val_if_fail( qry->control != NULL, -1 ); - - ldapqry_set_stop_flag( qry, FALSE ); - ldapqry_touch( qry ); - if( ldapqry_check_search( qry ) ) { - if( ADDRQUERY_RETVAL(qry) == LDAPRC_SUCCESS ) { - debug_print("Starting LDAP search thread\n"); - ldapqry_set_busy_flag( qry, TRUE ); - qry->thread = g_malloc0( sizeof( pthread_t ) ); - - /* Setup thread */ - if (pthread_create( qry->thread, NULL, - (void *) ldapqry_search, (void *) qry ) != 0) { - g_free(qry->thread); - qry->thread = NULL; - ADDRQUERY_RETVAL(qry) = LDAPRC_SEARCH; - } - } - } - return ADDRQUERY_RETVAL(qry); -} - -/** - * Cleanup LDAP thread data. This function will be called when each thread - * exits. Note that the thread object will be freed by the kernel. - * \param ptr Pointer to object being destroyed (a query object in this case). - */ -static void ldapqry_destroyer( void * ptr ) { - LdapQuery *qry; - - qry = ( LdapQuery * ) ptr; - cm_return_if_fail( qry != NULL ); - - /* Perform any destruction here */ - if( qry->control != NULL ) { - ldapctl_free( qry->control ); - } - qry->control = NULL; - qry->thread = NULL; - ldapqry_set_busy_flag( qry, FALSE ); -} - -/** - * Cancel thread associated with query. - * \param qry Query object to process. - */ -void ldapqry_cancel( LdapQuery *qry ) { - cm_return_if_fail( qry != NULL ); - - if( ldapqry_get_busy_flag( qry ) ) { - if( qry->thread ) { - debug_print("calling pthread_cancel\n"); - pthread_cancel( * qry->thread ); - } - } -} - -/** - * Initialize LDAP query. This function should be called once before executing - * any LDAP queries to initialize thread specific data. - */ -void ldapqry_initialize( void ) { - debug_print("ldapqry_initialize...\n"); - if( ! _queryThreadInit_ ) { - debug_print("ldapqry_initialize::creating thread specific area\n"); - pthread_key_create( &_queryThreadKey_, ldapqry_destroyer ); - _queryThreadInit_ = TRUE; - } - debug_print("ldapqry_initialize... done!\n"); -} - -/** - * Age the query based on LDAP control parameters. - * \param qry Query object to process. - * \param maxAge Maximum age of query (in seconds). - */ -void ldapqry_age( LdapQuery *qry, gint maxAge ) { - gint age; - - cm_return_if_fail( qry != NULL ); - - /* Limit the time that queries can hang around */ - if( maxAge < 1 ) maxAge = LDAPCTL_MAX_QUERY_AGE; - - /* Check age of query */ - age = time( NULL ) - qry->touchTime; - if( age > maxAge ) { - qry->agedFlag = TRUE; - } -} - -/** - * Delete folder associated with query results. - * \param qry Query object to process. - */ -void ldapqry_delete_folder( LdapQuery *qry ) { - AddressCache *cache; - ItemFolder *folder; - - cm_return_if_fail( qry != NULL ); - - folder = ADDRQUERY_FOLDER(qry); - if( folder ) { - cache = qry->server->addressCache; - folder = addrcache_remove_folder_delete( cache, folder ); - if( folder ) { - addritem_free_item_folder( folder ); - } - ADDRQUERY_FOLDER(qry) = NULL; - } -} - -/** - * Create a name/value pair object. - * \param n Name. - * \param v Value. - * \return Initialized object. - */ -static NameValuePair *ldapqry_create_name_value( const gchar *n, const gchar *v ) { - NameValuePair *nvp = g_new0( NameValuePair, 1 ); - - nvp->name = g_strdup( n ); - nvp->value = g_strdup( v ); - return nvp; -} - -/** - * Free up name/value pair object. - * \param nvp Name/value object. - */ -void ldapqry_free_name_value( NameValuePair *nvp ) { - if( nvp ) { - g_free( nvp->name ); - g_free( nvp->value ); - nvp->name = nvp->value = NULL; - g_free( nvp ); - } -} - -/** - * Free up a list name/value pair objects. - * \param list List of name/value objects. - */ -void ldapqry_free_list_name_value( GList *list ) { - GList *node; - - node = list; - while( node ) { - NameValuePair *nvp = ( NameValuePair * ) node->data; - ldapqry_free_name_value( nvp ); - node->data = NULL; - node = g_list_next( node ); - } - g_list_free( list ); -} - -/** - * Load a list of name/value pairs from LDAP attributes. - * \param ld LDAP handle. - * \param e LDAP message. - * \param attr Attribute name. - * \param listValues List to populate. - * \return List of attribute name/value pairs. - */ -static GList *ldapqry_load_attrib_values( - LDAP *ld, LDAPMessage *entry, char *attr, - GList *listValues ) -{ - GList *list = NULL; - gint i; - struct berval **vals; - NameValuePair *nvp; - - list = listValues; - if( ( vals = ldap_get_values_len( ld, entry, attr ) ) != NULL ) { - for( i = 0; vals[i] != NULL; i++ ) { - gchar *tmp = g_strndup( vals[i]->bv_val, vals[i]->bv_len); - nvp = ldapqry_create_name_value( attr, tmp ); - g_free(tmp); - list = g_list_append( list, nvp ); - } - } - ldap_value_free_len( vals ); - return list; -} - -/** - * Fetch a list of all attributes. - * \param ld LDAP handle. - * \param e LDAP message. - * \return List of attribute name/value pairs. - */ -static GList *ldapqry_fetch_attribs( LDAP *ld, LDAPMessage *e ) -{ - char *attribute; - BerElement *ber; - GList *listValues = NULL; - - /* Process all attributes */ - for( attribute = ldap_first_attribute( ld, e, &ber ); attribute != NULL; - attribute = ldap_next_attribute( ld, e, ber ) ) { - listValues = ldapqry_load_attrib_values( ld, e, attribute, listValues ); - ldap_memfree( attribute ); - } - - /* Free up */ - if( ber != NULL ) { - ber_free( ber, 0 ); - } - return listValues; -} - -#define CRITERIA_SINGLE "(objectclass=*)" - -/** - * Perform the data retrieval for a specific LDAP record. - * - * \param qry Query object to process. - * \return Error/status code. - */ -static gint ldapqry_locate_retrieve( LdapQuery *qry ) { - LdapControl *ctl; - LDAP *ld; - LDAPMessage *result, *e = NULL; - gboolean entriesFound; - gboolean first; - struct timeval timeout; - gint rc; - gchar *dn; - GList *listValues; - - /* Initialize some variables */ - ld = qry->ldap; - ctl = qry->control; - dn = ADDRQUERY_SEARCHVALUE(qry); - timeout.tv_sec = ctl->timeOut; - timeout.tv_usec = 0L; - entriesFound = FALSE; - - /* - * Execute the search - this step may take some time to complete - * depending on network traffic and server response time. - */ - ADDRQUERY_RETVAL(qry) = LDAPRC_TIMEOUT; - rc = ldap_search_ext_s( ld, dn, LDAP_SCOPE_BASE, CRITERIA_SINGLE, - NULL, 0, NULL, NULL, &timeout, 0, &result ); - if( rc == LDAP_TIMEOUT ) { - return ADDRQUERY_RETVAL(qry); - } - ADDRQUERY_RETVAL(qry) = LDAPRC_SEARCH; - if( rc != LDAP_SUCCESS ) { - log_error(LOG_PROTOCOL, _("LDAP error (search): %d (%s)\n"), - rc, ldaputil_get_error(ld)); - debug_print("LDAP Error: ldap_search_ext_s: %d (%s)\n", - rc, ldaputil_get_error(ld)); - return ADDRQUERY_RETVAL(qry); - } else { - log_print(LOG_PROTOCOL, _("LDAP (search): successful\n")); - } - -#ifdef G_OS_WIN32 - debug_print("Total results are: %lu\n", ldap_count_entries(ld, result)); -#else - debug_print("Total results are: %d\n", ldap_count_entries(ld, result)); -#endif - - /* Process results */ - ADDRQUERY_RETVAL(qry) = LDAPRC_STOP_FLAG; - first = TRUE; - while( TRUE ) { - ldapqry_touch( qry ); - if( qry->entriesRead >= ctl->maxEntries ) break; - - /* Test for stop */ - if( ldapqry_get_stop_flag( qry ) ) { - break; - } - - /* Retrieve entry */ - if( first ) { - first = FALSE; - e = ldap_first_entry( ld, result ); - } - else { - e = ldap_next_entry( ld, e ); - } - if( e == NULL ) break; - - entriesFound = TRUE; - - /* Setup a critical section here */ - pthread_mutex_lock( qry->mutexEntry ); - - /* Process entry */ - listValues = ldapqry_fetch_attribs( ld, e ); - - /* Process callback */ - if( qry->callBackEntry ) { - qry->callBackEntry( qry, ADDRQUERY_ID(qry), listValues, qry->data ); - } - ldapqry_free_list_name_value( listValues ); - listValues = NULL; - - pthread_mutex_unlock( qry->mutexEntry ); - } - - /* Free up and disconnect */ - ldap_msgfree( result ); - - if( entriesFound ) { - ADDRQUERY_RETVAL(qry) = LDAPRC_SUCCESS; - } - else { - ADDRQUERY_RETVAL(qry) = LDAPRC_NOENTRIES; - } - - return ADDRQUERY_RETVAL(qry); -} - -/** - * Perform the search to locate a specific LDAP record identified by - * distinguished name (dn). - * - * \param qry Query object to process. - * \return Error/status code. - */ -static gint ldapqry_perform_locate( LdapQuery *qry ) { - /* Connect */ - qry->ldap = NULL; - ldapqry_connect( qry ); - if( ADDRQUERY_RETVAL(qry) == LDAPRC_SUCCESS ) { - /* Perform search */ - ldapqry_locate_retrieve( qry ); - } - /* Disconnect */ - ldapqry_disconnect( qry ); - qry->ldap = NULL; - - /* Process callback */ - if( qry->callBackEnd ) { - g_timeout_add(0, callbackend, qry); - } - - return ADDRQUERY_RETVAL(qry); -} - -/** - * Remove results (folder and data) for specified LDAP query. - * \param qry Query object to process. - * \return TRUE if folder deleted successfully. - */ -gboolean ldapquery_remove_results( LdapQuery *qry ) { - gboolean retVal = FALSE; - - ldapqry_set_aged_flag( qry, TRUE ); - - if( ldapqry_get_busy_flag( qry ) ) { - ldapqry_set_stop_flag( qry, TRUE ); - } - else { - LdapServer *server = qry->server; - server->listQuery = g_list_remove(server->listQuery, qry); - - retVal = TRUE; - } - return retVal; -} - -#ifdef DEBUG_LDAP -void ldapqry_print(LdapQuery *qry, FILE *stream) { - cm_return_if_fail( qry != NULL ); - - ldapsvr_print_data(qry->server, stream); - ldapctl_print(qry->control, stream); - fprintf(stream, "entriesRead: %d\n", qry->entriesRead); - fprintf(stream, "elapsedTime: %d\n", qry->elapsedTime); - fprintf(stream, "stopFlag: %d\n", qry->stopFlag); - fprintf(stream, "busyFlag: %d\n", qry->busyFlag); - fprintf(stream, "agedFlag: %d\n", qry->agedFlag); - fprintf(stream, "completed: %d\n", qry->completed); - fprintf(stream, "startTime: %d\n", (int) qry->startTime); - fprintf(stream, "touchTime: %d\n", (int) qry->touchTime); - fprintf(stream, "data: %s\n", qry->data?(gchar *)qry->data:"null"); -} -#endif - -#endif /* USE_LDAP */ - -/* - * End of Source. - */ - - diff --git a/src/ldapquery.h b/src/ldapquery.h @@ -1,102 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2003-2022 Match Grun and the Claws Mail team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * Functions necessary to define an LDAP query. - */ - -#ifndef __LDAPQUERY_H__ -#define __LDAPQUERY_H__ - -#ifdef USE_LDAP - -#include <glib.h> -#include <stdio.h> -#include <sys/time.h> -#include <pthread.h> - -#ifdef G_OS_UNIX -#include <ldap.h> -#include <lber.h> -#else -#include <windows.h> -#include <winldap.h> -#endif -#include "addrquery.h" -#include "ldapctrl.h" -#include "addritem.h" -#include "addrcache.h" -#include "ldapserver.h" - -typedef struct _LdapQuery LdapQuery; -struct _LdapQuery { - AddrQueryObject obj; - LdapControl *control; - LdapServer *server; /* Reference to (parent) LDAP server */ - gint entriesRead; - gint elapsedTime; - gboolean stopFlag; - gboolean busyFlag; - gboolean agedFlag; - gboolean completed; - time_t startTime; - time_t touchTime; - pthread_t *thread; - pthread_mutex_t *mutexStop; - pthread_mutex_t *mutexBusy; - pthread_mutex_t *mutexEntry; - void (*callBackEntry)( void *, gint, void *, void * ); - void (*callBackEnd)( void *, gint, gint, void * ); - LDAP *ldap; - gpointer data; -}; - -typedef struct _NameValuePair NameValuePair; -struct _NameValuePair { - gchar *name; - gchar *value; -}; - -/* Function prototypes */ -#ifdef DEBUG_LDAP -void ldapqry_print(LdapQuery *qry, FILE *stream); -#endif -void ldapqry_initialize ( void ); -LdapQuery *ldapqry_create ( void ); -void ldapqry_set_control ( LdapQuery *qry, LdapControl *ctl ); -void ldapqry_set_name ( LdapQuery* qry, const gchar *value ); -void ldapqry_set_search_value ( LdapQuery *qry, const gchar *value ); -void ldapqry_set_search_type ( LdapQuery *qry, const AddrSearchType value ); -void ldapqry_set_query_id ( LdapQuery* qry, const gint value ); -void ldapqry_set_callback_start ( LdapQuery *qry, void *func ); -void ldapqry_set_callback_entry ( LdapQuery *qry, void *func ); -void ldapqry_set_callback_end ( LdapQuery *qry, void *func ); -void ldapqry_free ( LdapQuery *qry ); -void ldapqry_set_stop_flag( LdapQuery *qry, const gboolean value ); -gboolean ldapqry_check_search ( LdapQuery *qry ); -void ldapqry_touch ( LdapQuery *qry ); -gint ldapqry_read_data_th ( LdapQuery *qry ); -void ldapqry_cancel ( LdapQuery *qry ); -void ldapqry_age ( LdapQuery *qry, gint maxAge ); -void ldapqry_delete_folder ( LdapQuery *qry ); -gboolean ldapquery_remove_results( LdapQuery *qry ); -void ldapqry_free_list_name_value( GList *list ); -void ldapqry_free_name_value( NameValuePair *nvp ); -#endif /* USE_LDAP */ - -#endif /* __LDAPQUERY_H__ */ diff --git a/src/ldapserver.c b/src/ldapserver.c @@ -1,924 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2003-2022 the Claws Mail team and Match Grun - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * Functions necessary to access LDAP servers. - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#include "claws-features.h" -#endif - -#ifdef USE_LDAP - -#include <glib.h> -#include <glib/gi18n.h> -#include <sys/time.h> -#include <string.h> - -#include "mgutils.h" -#include "addritem.h" -#include "addrcache.h" -#include "ldapctrl.h" -#include "ldapquery.h" -#include "ldapserver.h" -#include "ldaputil.h" -#include "utils.h" -#include "adbookbase.h" -#include "passwordstore.h" -#include "log.h" - -/** - * Create new LDAP server interface object with no control object. - * \return Initialized LDAP server object. - */ -LdapServer *ldapsvr_create_noctl( void ) { - LdapServer *server; - - server = g_new0( LdapServer, 1 ); - server->type = ADBOOKTYPE_LDAP; - server->addressCache = addrcache_create(); - server->retVal = MGU_SUCCESS; - server->control = NULL; - server->listQuery = NULL; - server->searchFlag = FALSE; - return server; -} - -/** - * Create new LDAP server interface object. - * \return Initialized LDAP server object. - */ -LdapServer *ldapsvr_create( void ) { - LdapServer *server; - server = ldapsvr_create_noctl(); - server->control = ldapctl_create(); - return server; -} - -/** - * Return name of server. - * \param server Server object. - * \return Name for server. - */ -gchar *ldapsvr_get_name( LdapServer *server ) { - cm_return_val_if_fail( server != NULL, NULL ); - return addrcache_get_name( server->addressCache ); -} - -/** - * Specify name to be used. - * \param server Server object. - * \param value Name for server. - */ -void ldapsvr_set_name( LdapServer* server, const gchar *value ) { - cm_return_if_fail( server != NULL ); - addrcache_set_name( server->addressCache, value ); - debug_print("setting name: %s\n", value?value:"null"); -} - -/** - * Refresh internal variables to force a file read. - * \param server Server object. - */ -void ldapsvr_force_refresh( LdapServer *server ) { - cm_return_if_fail( server != NULL ); - addrcache_refresh( server->addressCache ); -} - -/** - * Return status/error code. - * \param server Server object. - * \return Status/error code. - */ -gint ldapsvr_get_status( LdapServer *server ) { - cm_return_val_if_fail( server != NULL, -1 ); - return server->retVal; -} - -/** - * Return reference to root level folder. - * \param server Server object. - * \return Root level folder. - */ -ItemFolder *ldapsvr_get_root_folder( LdapServer *server ) { - cm_return_val_if_fail( server != NULL, NULL ); -#ifdef DEBUG_LDAP - debug_print( "ldapsvr_get_root_folder/start\n" ); - ldapsvr_print_data( server, stdout ); - debug_print( "ldapsvr_get_root_folder/done\n" ); -#endif - return addrcache_get_root_folder( server->addressCache ); -} - -/** - * Test whether server data has been accessed. - * \param server Server object. - * \return <i>TRUE</i> if data was accessed. - */ -gboolean ldapsvr_get_accessed( LdapServer *server ) { - cm_return_val_if_fail( server != NULL, FALSE ); - return server->addressCache->accessFlag; -} - -/** - * Specify that server's data whas beed accessed. - * \param server Server object. - * \param value Value for flag. - */ -void ldapsvr_set_accessed( LdapServer *server, const gboolean value ) { - cm_return_if_fail( server != NULL ); - server->addressCache->accessFlag = value; - debug_print("setting accessFlag: %d\n", value); -} - -/** - * Test whether server data has been modified. - * \param server Server object. - * \return <i>TRUE</i> if data was modified. - */ -gboolean ldapsvr_get_modified( LdapServer *server ) { - cm_return_val_if_fail( server != NULL, FALSE ); - return server->addressCache->modified; -} - -/** - * Specify modify flag. - * \param server Server object. - * \param value Value for flag. - */ -void ldapsvr_set_modified( LdapServer *server, const gboolean value ) { - cm_return_if_fail( server != NULL ); - server->addressCache->modified = value; - debug_print("setting modified: %d\n", value); -} - -/** - * Test whether data was read from server. - * \param server Server object. - * \return <i>TRUE</i> if data was read. - */ -gboolean ldapsvr_get_read_flag( LdapServer *server ) { - cm_return_val_if_fail( server != NULL, FALSE ); - return server->addressCache->dataRead; -} - -/** - * Test whether server is to be used for dynamic searches. - * \param server Server object. - * \return <i>TRUE</i> if server is used for dynamic searches. - */ -gboolean ldapsvr_get_search_flag( LdapServer *server ) { - cm_return_val_if_fail( server != NULL, FALSE ); - return server->searchFlag; -} - -/** - * Specify that server is to be used for dynamic searches. - * \param server Server object. - * \param value Name for server. - */ -void ldapsvr_set_search_flag( LdapServer *server, const gboolean value ) { - cm_return_if_fail( server != NULL ); - server->searchFlag = value; - debug_print("setting searchFlag: %d\n", value); -} - -/** - * Specify the reference to control data that will be used for the query. The calling - * module should be responsible for creating and destroying this control object. - * \param server Server object. - * \param ctl Control data. - */ -void ldapsvr_set_control( LdapServer *server, LdapControl *ctl ) { - cm_return_if_fail( server != NULL ); - addrcache_refresh( server->addressCache ); - server->control = ctl; -} - -/** - * Free all queries. - * \param server Server object. - */ -void ldapsvr_free_all_query( LdapServer *server ) { - GList *node; - cm_return_if_fail( server != NULL ); - - node = server->listQuery; - while( node ) { - LdapQuery *qry = node->data; - ldapqry_free( qry ); - node->data = NULL; - node = g_list_next( node ); - } - g_list_free( server->listQuery ); - server->listQuery = NULL; -} - -/** - * Add query to server. - * \param server Server object. - * \param qry Query object. - */ -void ldapsvr_add_query( LdapServer *server, LdapQuery *qry ) { - cm_return_if_fail( server != NULL ); - cm_return_if_fail( qry != NULL ); - - server->listQuery = g_list_append( server->listQuery, qry ); - qry->server = server; -} - -/** - * Free up LDAP server interface object by releasing internal memory. - * \param server Server object. - */ -void ldapsvr_free( LdapServer *server ) { - cm_return_if_fail( server != NULL ); - - /* Stop and cancel any queries that may be active */ - ldapsvr_stop_all_query( server ); - ldapsvr_cancel_all_query( server ); - - /* Clear cache */ - addrcache_clear( server->addressCache ); - addrcache_free( server->addressCache ); - - /* Free LDAP control block */ - ldapctl_free( server->control ); - server->control = NULL; - - /* Free all queries */ - ldapsvr_free_all_query( server ); - - /* Clear pointers */ - server->type = ADBOOKTYPE_NONE; - server->addressCache = NULL; - server->retVal = MGU_SUCCESS; - server->listQuery = NULL; - server->searchFlag = FALSE; - - /* Now release LDAP object */ - g_free( server ); -} - -#ifdef DEBUG_LDAP -/** - * Display object to specified stream. - * \param server Server object. - * \param stream Output stream. - */ -void ldapsvr_print_data( LdapServer *server, FILE *stream ) { - GList *node; - gint i; - - cm_return_if_fail( server != NULL ); - - fprintf( stream, "LdapServer:\n" ); - fprintf( stream, " ret val: %d\n", server->retVal ); - fprintf( stream, "srch flag: %s\n", - server->searchFlag ? "yes" : "no" ); - if( server->control ) { - ldapctl_print( server->control, stream ); - } - else { - fprintf( stream, " control: NULL\n" ); - } - addrcache_print( server->addressCache, stream ); - addritem_print_item_folder( server->addressCache->rootFolder, stream ); - - /* Dump queries */ - i = 1; - node = server->listQuery; - while( node ) { - LdapQuery *qry = node->data; - fprintf( stream, " query: %2d : %s\n", i, ADDRQUERY_NAME(qry) ); - i++; - node = g_list_next( node ); - } -} -#endif - -/** - * Return link list of persons. - * \param server Server object. - * \return List of persons. - */ -GList *ldapsvr_get_list_person( LdapServer *server ) { - cm_return_val_if_fail( server != NULL, NULL ); - return addrcache_get_list_person( server->addressCache ); -} - -/** - * Return link list of folders. There are no "real" folders that are returned - * from the server. - * \param server Server object. - * \return List of folders. - */ -GList *ldapsvr_get_list_folder( LdapServer *server ) { - cm_return_val_if_fail( server != NULL, NULL ); - /* return addrcache_get_list_folder( server->addressCache ); */ - return NULL; -} - -/** - * Execute specified query. - * \param server LDAP server. - * \param qry LDAP query. - */ -void ldapsvr_execute_query( LdapServer *server, LdapQuery *qry ) { - LdapControl *ctlCopy; - - cm_return_if_fail( server != NULL ); - cm_return_if_fail( qry != NULL ); - - /* Copy server's control data to the query */ - ctlCopy = ldapctl_create(); - ldapctl_copy( server->control, ctlCopy ); - ldapqry_set_control( qry, ctlCopy ); - ldapqry_initialize(); - - /* Perform query */ - debug_print("ldapsvr_execute_query::checking query...\n"); - if( ldapqry_check_search( qry ) ) { - debug_print("ldapsvr_execute_query::reading with thread...\n"); - ldapqry_read_data_th( qry ); - if(qry->server->retVal == LDAPRC_SUCCESS) { - debug_print("ldapsvr_execute_query::SUCCESS with thread...\n"); - } - } - debug_print("ldapsvr_execute_query... terminated\n"); -} - -/** - * Stop all queries for specified ID. - * \param server Server object. - * \param queryID Query ID to stop. - */ -void ldapsvr_stop_query_id( LdapServer *server, const gint queryID ) { - GList *node; - cm_return_if_fail( server != NULL ); - - node = server->listQuery; - while( node ) { - LdapQuery *qry = node->data; - if( ADDRQUERY_ID(qry) == queryID ) { - /* Notify thread to stop */ - ldapqry_set_stop_flag( qry, TRUE ); - } - node = g_list_next( node ); - } -} - -/** - * Stop all queries by notifying each thread to stop. - * \param server Server object. - */ -void ldapsvr_stop_all_query( LdapServer *server ) { - GList *node; - cm_return_if_fail( server != NULL ); - - node = server->listQuery; - while( node ) { - LdapQuery *qry = node->data; - ldapqry_set_stop_flag( qry, TRUE ); - node = g_list_next( node ); - } -} - -/** - * Cancel all query threads for server. - * \param server Server object. - */ -void ldapsvr_cancel_all_query( LdapServer *server ) { - GList *node; - cm_return_if_fail( server != NULL ); - - node = server->listQuery; - while( node ) { - LdapQuery *qry = node->data; - /* Notify thread to stop */ - ldapqry_set_stop_flag( qry, TRUE ); - /* Now cancel thread */ - ldapqry_cancel( qry ); - node = g_list_next( node ); - } -} - -/** - * Search most recent query for specified search term. The most recent - * completed query is returned. If no completed query is found, the most recent - * incomplete is returned. - * \param server LdapServer. - * \param searchTerm Search term to locate. - * \return Query object, or <i>NULL</i> if none found. - */ -static LdapQuery *ldapsvr_locate_query( - const LdapServer *server, const gchar *searchTerm ) -{ - LdapQuery *incomplete = NULL; - GList *node; - cm_return_val_if_fail( server != NULL, NULL ); - - node = server->listQuery; - node = g_list_last( node ); - /* Search backwards for query */ - while( node ) { - LdapQuery *qry = node->data; - if( g_utf8_collate( ADDRQUERY_SEARCHVALUE(qry), searchTerm ) == 0 ) { - if( qry->agedFlag ) continue; - if( qry->completed ) { - /* Found */ - return qry; - } - if( ! incomplete ) { - incomplete = qry; - } - } - node = g_list_previous( node ); - } - return incomplete; -} - -/** - * Retire aged queries. Only the following queries are retired: - * - * a) Dynamic queries. - * b) Explicit searches that have a hidden folders. - * c) Locate searches that have a hidden folder. - * - * \param server LdapServer. - */ -void ldapsvr_retire_query( LdapServer *server ) { - GList *node; - GList *listDelete; - GList *listQuery; - gint maxAge; - LdapControl *ctl; - ItemFolder *folder; - - debug_print("ldapsvr_retire_query\n"); - cm_return_if_fail( server != NULL ); - ctl = server->control; - maxAge = ctl->maxQueryAge; - - /* Identify queries to age and move to deletion list */ - listDelete = NULL; - node = server->listQuery; - while( node ) { - LdapQuery *qry = node->data; - - node = g_list_next( node ); - folder = ADDRQUERY_FOLDER(qry); - if( folder == NULL ) continue; - if( ! folder->isHidden ) { - if( ADDRQUERY_SEARCHTYPE(qry) == ADDRSEARCH_EXPLICIT ) continue; - if( ADDRQUERY_SEARCHTYPE(qry) == ADDRSEARCH_LOCATE ) continue; - } - - ldapqry_age( qry, maxAge ); - if( qry->agedFlag ) { - /* Delete folder associated with query */ - debug_print("deleting folder... ::%s::\n", - ADDRQUERY_NAME(qry)?ADDRQUERY_NAME(qry):"null"); - ldapqry_delete_folder( qry ); - listDelete = g_list_append( listDelete, qry ); - } - } - - /* Delete queries */ - listQuery = server->listQuery; - node = listDelete; - while( node ) { - LdapQuery *qry = node->data; - - listQuery = g_list_remove( listQuery, qry ); - ldapqry_free( qry ); - node->data = NULL; - node = g_list_next( node ); - } - server->listQuery = listQuery; - - /* Free up deletion list */ - g_list_free( listDelete ); -} - -/** - * Return results of a previous query by executing callback for each address - * contained in specified folder. - * - * \param folder Address book folder to process. - * \param req Address query request object. - */ -static void ldapsvr_previous_query( - const ItemFolder *folder, const QueryRequest *req, AddrQueryObject *aqo ) -{ - AddrSearchCallbackEntry *callBack; - GList *listEMail; - GList *node; - GList *nodeEM; - gpointer sender; - - sender = aqo; - callBack = ( AddrSearchCallbackEntry * ) req->callBackEntry; - if( callBack ) { - listEMail = NULL; - node = folder->listPerson; - while( node ) { - AddrItemObject *aio = node->data; - if( aio && aio->type == ITEMTYPE_PERSON ) { - ItemPerson *person = node->data; - nodeEM = person->listEMail; - while( nodeEM ) { - ItemEMail *email = nodeEM->data; - - nodeEM = g_list_next( nodeEM ); - listEMail = g_list_append( listEMail, email ); - } - } - node = g_list_next( node ); - } - ( callBack ) ( sender, req->queryID, listEMail, NULL ); - /* // g_list_free( listEMail ); */ - } -} - -/** - * Reuse search results from a previous LDAP query. If there is a query that - * has the same search term as specified in the query request, then the query - * will be reused. - * - * \param server LDAP server object. - * \param req Address query object. - * \return <i>TRUE</i> if previous query was used. - */ -gboolean ldapsvr_reuse_previous( const LdapServer *server, const QueryRequest *req ) { - LdapQuery *qry; - gchar *searchTerm; - ItemFolder *folder; - - cm_return_val_if_fail( server != NULL, FALSE ); - cm_return_val_if_fail( req != NULL, FALSE ); - - searchTerm = req->searchTerm; - - /* Test whether any queries for the same term exist */ - qry = ldapsvr_locate_query( server, searchTerm ); - if( qry ) { - /* Touch query to ensure it hangs around for a bit longer */ - ldapqry_touch( qry ); - folder = ADDRQUERY_FOLDER(qry); - if( folder ) { - ldapsvr_previous_query( folder, req, ADDRQUERY_OBJECT(qry) ); - return TRUE; - } - } - return FALSE; -} - -/** - * Construct a new LdapQuery object that will be used to perform an dynamic - * search request. - * - * \param server LdapServer. - * \param req Query request. - * \return LdapQuery object, or <i>NULL</i> if none created. - */ -LdapQuery *ldapsvr_new_dynamic_search( LdapServer *server, QueryRequest *req ) -{ - LdapQuery *qry; - gchar *name; - gchar *searchTerm; - ItemFolder *folder; - - cm_return_val_if_fail( server != NULL, NULL ); - cm_return_val_if_fail( req != NULL, NULL ); - - /* Retire any aged queries */ - /* // ldapsvr_retire_query( server ); */ - - /* Name of folder and query */ - searchTerm = req->searchTerm; - name = g_strdup_printf( "Search '%s'", searchTerm ); - - /* Create a folder for the search results */ - folder = addrcache_add_new_folder( server->addressCache, NULL ); - addritem_folder_set_name( folder, name ); - addritem_folder_set_remarks( folder, "" ); - - /* Construct a query */ - qry = ldapqry_create(); - ldapqry_set_query_id( qry, req->queryID ); - ldapqry_set_search_value( qry, searchTerm ); - ldapqry_set_search_type( qry, ADDRSEARCH_DYNAMIC ); - ldapqry_set_callback_entry( qry, req->callBackEntry ); - ldapqry_set_callback_end( qry, req->callBackEnd ); - - /* Specify folder type and back reference */ - ADDRQUERY_FOLDER(qry) = folder; - folder->folderType = ADDRFOLDER_QUERY_RESULTS; - folder->folderData = ( gpointer ) qry; - folder->isHidden = TRUE; - - /* Name the query */ - ldapqry_set_name( qry, name ); - g_free( name ); - - /* Add query to request */ - qryreq_add_query( req, ADDRQUERY_OBJECT(qry) ); - - /* Now start the search */ - ldapsvr_add_query( server, qry ); - - return qry; -} - -/** - * Construct a new LdapQuery object that will be used to perform an explicit - * search request. - * - * \param server LdapServer. - * \param req Query request. - * \param folder Folder that will be used to contain search results. - * \return LdapQuery object, or <i>NULL</i> if none created. - */ -LdapQuery *ldapsvr_new_explicit_search( - LdapServer *server, QueryRequest *req, ItemFolder *folder ) -{ - LdapQuery *qry; - gchar *searchTerm; - gchar *name; - - cm_return_val_if_fail( server != NULL, NULL ); - cm_return_val_if_fail( req != NULL, NULL ); - cm_return_val_if_fail( folder != NULL, NULL ); - - /* Retire any aged queries */ - /* // ldapsvr_retire_query( server ); */ - - /* Name the query */ - searchTerm = req->searchTerm; - name = g_strdup_printf( "Explicit search for '%s'", searchTerm ); - - /* Construct a query */ - qry = ldapqry_create(); - ldapqry_set_query_id( qry, req->queryID ); - ldapqry_set_name( qry, name ); - ldapqry_set_search_value( qry, searchTerm ); - ldapqry_set_search_type( qry, ADDRSEARCH_EXPLICIT ); - ldapqry_set_callback_end( qry, req->callBackEnd ); - ldapqry_set_callback_entry( qry, req->callBackEntry ); - - /* Specify folder type and back reference */ - ADDRQUERY_FOLDER(qry) = folder; - folder->folderType = ADDRFOLDER_QUERY_RESULTS; - folder->folderData = ( gpointer ) qry; - - /* Setup server */ - ldapsvr_add_query( server, qry ); - - /* Set up query request */ - qryreq_add_query( req, ADDRQUERY_OBJECT(qry) ); - - g_free( name ); - - return qry; -} - -gint ldapsvr_read_data( LdapServer *server ) -{ - gchar *name; - - cm_return_val_if_fail( server != NULL, -1 ); - - name = addrcache_get_name(server->addressCache); - debug_print("...addrbook_read_data :%s:\n", name?name:"null"); - - addrcache_clear(server->addressCache); - ldapsvr_free_all_query( server ); - server->listQuery = NULL; - server->addressCache->modified = FALSE; - server->addressCache->accessFlag = FALSE; - server->addressCache->dataRead = TRUE; - addrcache_set_dirty(server->addressCache, FALSE); - return 0; -} - -void ldapsrv_set_options (gint secs, LDAP *ld) -{ -#ifdef G_OS_UNIX - static struct timeval timeout; - timeout.tv_sec = secs; - timeout.tv_usec = 0; - int i, rc; - i = LDAP_OPT_X_TLS_ALLOW; - rc = ldap_set_option(NULL, LDAP_OPT_X_TLS_REQUIRE_CERT, &i); - if (ld) - debug_print("cert %s\n", ldaputil_get_error(ld)); - else - debug_print("cert %s\n", ldap_err2string(rc)); - /* can crash old libldaps... */ - rc = ldap_set_option(NULL, LDAP_OPT_NETWORK_TIMEOUT, &timeout); - if (ld) - debug_print("tm %s\n", ldaputil_get_error(ld)); - else - debug_print("tm %s\n", ldap_err2string(rc)); -#endif -} - -#ifdef G_OS_WIN32 -#if LDAP_UNICODE -#define LDAP_START_TLS_S "ldap_start_tls_sW" -typedef ULONG (* PFldap_start_tls_s) (LDAP *, PULONG, LDAPMessage **, PLDAPControlW *, PLDAPControlW *); -#else -#define LDAP_START_TLS_S "ldap_start_tls_sA" -typedef ULONG (* PFldap_start_tls_s) (LDAP *, PULONG, LDAPMessage **, PLDAPControlA *, PLDAPControlA *); -#endif /* LDAP_UNICODE */ -PFldap_start_tls_s Win32_ldap_start_tls_s = NULL; -#endif - -/** - * Connect to LDAP server. - * \param ctl Control object to process. - * \return LDAP Resource to LDAP. - */ -LDAP *ldapsvr_connect(LdapControl *ctl) { - LDAP *ld = NULL; - gint rc; -#ifndef G_OS_UNIX - intptr_t op; -#endif - gint version; - gchar *uri = NULL; - gchar *pwd; - - cm_return_val_if_fail(ctl != NULL, NULL); - - ldapsrv_set_options (ctl->timeOut, NULL); - if (ctl->enableSSL) - uri = g_strdup_printf("ldaps://%s:%d", ctl->hostName, ctl->port); - else - uri = g_strdup_printf("ldap://%s:%d", ctl->hostName, ctl->port); -#ifdef G_OS_UNIX - ldap_initialize(&ld, uri); -#else - ld = ldap_sslinit(ctl->hostName, ctl->port, ctl->enableSSL); - if (ld && ctl->enableSSL) { - version = LDAP_VERSION3; - debug_print("Setting version 3\n"); - rc = ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, (void *)&version); - if (rc == LDAP_SUCCESS) { - ctl->version = LDAP_VERSION3; - log_print(LOG_PROTOCOL, "LDAP (options): set version 3\n"); - } else { - log_error(LOG_PROTOCOL, _("LDAP error (options): %d (%s)\n"), - rc, ldaputil_get_error(ld)); - debug_print("Failed: %s\n", ldaputil_get_error(ld)); - } - - rc = ldap_get_option(ld, LDAP_OPT_SSL, (void*)&op); - if (rc != LDAP_SUCCESS) { - log_warning(LOG_PROTOCOL, _("LDAP warning (options): can't get TLS state\n")); - debug_print("Can't get TLS state\n"); - } - - if ((void *)op != LDAP_OPT_ON) { - debug_print("Enabling TLS\n"); - rc = ldap_set_option(ld, LDAP_OPT_SSL, LDAP_OPT_ON); - if (rc != LDAP_SUCCESS) { - log_error(LOG_PROTOCOL, _("LDAP error (options): %d (%s)\n"), - rc, ldaputil_get_error(ld)); - debug_print("Failed: %s\n", ldaputil_get_error(ld)); - } else { - rc = ldap_get_option(ld, LDAP_OPT_SSL, (void*)&op); - if (rc != LDAP_SUCCESS) { - log_error(LOG_PROTOCOL, _("LDAP error (options): %d (%s)\n"), - rc, ldaputil_get_error(ld)); - } else { - log_print(LOG_PROTOCOL, _("LDAP (options): TLS enabled (%d)\n"), (gint)op); - } - debug_print("TLS now %d\n", (gint)op); - } - } - - if (!ld || (rc = ldap_connect(ld, NULL)) != LDAP_SUCCESS) { - log_error(LOG_PROTOCOL, _("LDAP error (connect): %d (%s)\n"), - rc, ldaputil_get_error(ld)); - debug_print("ldap_connect failed: %d %s\n", rc, ldaputil_get_error(ld)); - } else { - log_print(LOG_PROTOCOL, _("LDAP (connect): completed successfully\n")); - } - } -#endif - g_free(uri); - - if (ld == NULL) - return NULL; - - debug_print("Got handle to LDAP host %s on port %d\n", ctl->hostName, ctl->port); - - version = LDAP_VERSION3; - debug_print("Setting version 3\n"); - rc = ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, &version); - if (rc == LDAP_OPT_SUCCESS) { - ctl->version = LDAP_VERSION3; - log_print(LOG_PROTOCOL, "LDAP (options): set version 3\n"); - } else { - log_error(LOG_PROTOCOL, _("LDAP error (options): %d (%s)\n"), - rc, ldaputil_get_error(ld)); - } - -#if (defined USE_LDAP_TLS || defined G_OS_WIN32) - /* Handle TLS */ - if (ctl->version == LDAP_VERSION3) { - if (ctl->enableTLS && !ctl->enableSSL) { -#ifdef G_OS_WIN32 - ULONG serv_rc; - if (Win32_ldap_start_tls_s == NULL) { - void *lib = LoadLibrary("wldap32.dll"); - if (!lib || (Win32_ldap_start_tls_s = (PFldap_start_tls_s) GetProcAddress(lib, LDAP_START_TLS_S)) == NULL) { - log_error(LOG_PROTOCOL, _("LDAP error (TLS): " - "ldap_start_tls_s not supported on this platform\n")); - if (lib) - FreeLibrary(lib); - return NULL; - } - } - debug_print("Setting STARTTLS\n"); - rc = Win32_ldap_start_tls_s(ld, &serv_rc, NULL, NULL, NULL); - debug_print("ldap_start_tls_s: %d server %ld %s\n", - rc, serv_rc, ldaputil_get_error(ld)); -#else - debug_print("Setting STARTTLS\n"); - rc = ldap_start_tls_s(ld, NULL, NULL); -#endif - if (rc != LDAP_SUCCESS) { - log_error(LOG_PROTOCOL, _("LDAP error (TLS): ldap_start_tls_s: %d (%s)\n"), - rc, ldaputil_get_error(ld)); - return NULL; - } else { - log_print(LOG_PROTOCOL, _("LDAP (TLS): started successfully\n")); - debug_print("Done\n"); - } - } - } -#endif - - /* Bind to the server, if required */ - if (ctl->bindDN) { - if (* ctl->bindDN != '\0') { - pwd = passwd_store_get(PWS_CORE, "LDAP", ctl->hostName); - rc = claws_ldap_simple_bind_s(ld, ctl->bindDN, pwd); - if (pwd != NULL && strlen(pwd) > 0) - memset(pwd, 0, strlen(pwd)); - g_free(pwd); - if (rc != LDAP_SUCCESS) { - log_error(LOG_PROTOCOL, _("LDAP error (bind): binding DN '%s': %d (%s)\n" ), - ctl->bindDN, rc, ldaputil_get_error(ld)); - return NULL; - } - log_print(LOG_PROTOCOL, _("LDAP (bind): successfully for DN '%s'\n"), - ctl->bindDN); - } - } - return ld; -} - -/** - * Disconnect to LDAP server. - * \param ld Resource to LDAP. - */ -void ldapsvr_disconnect(LDAP *ld) { - gint rc; - /* Disconnect */ - cm_return_if_fail(ld != NULL); - rc = ldap_unbind_ext(ld, NULL, NULL); - if (rc != LDAP_SUCCESS) { - log_error(LOG_PROTOCOL, _("LDAP error (unbind): %d (%s)\n"), - rc, ldaputil_get_error(ld)); - } else { - log_print(LOG_PROTOCOL, _("LDAP (unbind): successful\n")); - } -} - -#endif /* USE_LDAP */ - -/* - * End of Source. - */ - diff --git a/src/ldapserver.h b/src/ldapserver.h @@ -1,115 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2003-2022 Match Grun and the Claws Mail team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * Definitions necessary to access LDAP servers. - */ - -#ifndef __LDAPSERVER_H__ -#define __LDAPSERVER_H__ - -#ifdef USE_LDAP - -#include <glib.h> -#ifdef G_OS_UNIX -#include <ldap.h> -#else -#include <stdio.h> -#include <string.h> -#include <stdarg.h> -#include <stdlib.h> -#include <ctype.h> -#include <errno.h> -#include <windows.h> -#include <winldap.h> -#include <winber.h> -#endif - -#include "ldapctrl.h" -#include "addritem.h" -#include "addrcache.h" -#include "adbookbase.h" -#include "addrquery.h" - -/* Error codes */ -#define LDAPRC_SUCCESS 0 -#define LDAPRC_CONNECT -1 -#define LDAPRC_INIT -2 -#define LDAPRC_BIND -3 -#define LDAPRC_SEARCH -4 -#define LDAPRC_TIMEOUT -5 -#define LDAPRC_CRITERIA -6 -#define LDAPRC_NOENTRIES -7 -#define LDAPRC_STOP_FLAG -8 -#define LDAPRC_TLS -9 -#define LDAPRC_NODN -10 -#define LDAPRC_NAMING_VIOLATION -11 -#define LDAPRC_ALREADY_EXIST -12 -#define LDAPRC_STRONG_AUTH -13 - -typedef struct _LdapServer LdapServer; -struct _LdapServer { - AddressBookType type; - AddressCache *addressCache; - gint retVal; - LdapControl *control; - gboolean searchFlag; - GList *listQuery; -}; - -/* Function prototypes */ -LdapServer *ldapsvr_create_noctl( void ); -LdapServer *ldapsvr_create ( void ); -void ldapsvr_set_name ( LdapServer *server, const gchar *value ); -void ldapsvr_set_accessed ( LdapServer *server, const gboolean value ); -void ldapsvr_force_refresh ( LdapServer *server ); -void ldapsvr_free_all_query ( LdapServer *server ); -void ldapsvr_free ( LdapServer *server ); -gint ldapsvr_get_status ( LdapServer *server ); -gboolean ldapsvr_get_accessed ( LdapServer *server ); -gchar *ldapsvr_get_name ( LdapServer *server ); -gboolean ldapsvr_get_modified ( LdapServer *server ); -void ldapsvr_set_modified ( LdapServer *server, const gboolean value ); -gboolean ldapsvr_get_read_flag ( LdapServer *server ); -gboolean ldapsvr_get_search_flag( LdapServer *server ); -void ldapsvr_set_search_flag ( LdapServer *server, const gboolean value ); -gint ldapsvr_read_data ( LdapServer *server ); - -#ifdef DEBUG_LDAP -void ldapsvr_print_data ( LdapServer *server, FILE *stream ); -#endif -void ldapsvr_cancel_read ( LdapServer *server ); - -ItemFolder *ldapsvr_get_root_folder ( LdapServer *server ); -GList *ldapsvr_get_list_person ( LdapServer *server ); -GList *ldapsvr_get_list_folder ( LdapServer *server ); - -void ldapsvr_stop_query_id ( LdapServer *server, const gint queryID ); -void ldapsvr_stop_all_query ( LdapServer *server ); -void ldapsvr_cancel_all_query ( LdapServer *server ); -void ldapsvr_retire_query ( LdapServer *server ); - -gboolean ldapsvr_reuse_previous ( const LdapServer *server, - const QueryRequest *req ); -void ldapsrv_set_options (gint secs, LDAP *ld); -LDAP *ldapsvr_connect(LdapControl *ctl); -void ldapsvr_disconnect(LDAP *ld); -#endif /* USE_LDAP */ - -#endif /* __LDAPSERVER_H__ */ - diff --git a/src/ldapupdate.c b/src/ldapupdate.c @@ -1,1441 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2003-2018 Michael Rasmussen and the Claws Mail team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * Functions necessary to access LDAP servers. - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#include "claws-features.h" -#endif - -#ifdef USE_LDAP - -#include <glib.h> -#include <glib/gi18n.h> -#include <sys/time.h> -#include <string.h> - -#include "ldapupdate.h" -#include "mgutils.h" -#include "addritem.h" -#include "addrcache.h" -#include "ldapctrl.h" -#include "ldapquery.h" -#include "ldapserver.h" -#include "ldaputil.h" -#include "utils.h" -#include "adbookbase.h" -#include "editaddress_other_attributes_ldap.h" -#include "log.h" - -/** - * Structure to hold user defined attributes - * from contacts - */ -typedef struct _AttrKeyValue AttrKeyValue; -struct _AttrKeyValue { - gchar *key; - gchar *value; -}; - -/** - * Structure to hold contact information. - * Each addressbook will have 0..N contacts. - */ -typedef struct _EmailKeyValue EmailKeyValue; -struct _EmailKeyValue { - gchar *mail; - gchar *alias; - gchar *remarks; -}; - -/** - * Structure to hold information about RDN. - */ -typedef struct _Rdn Rdn; -struct _Rdn { - gchar *attribute; - gchar *value; - gchar *new_dn; -}; - -/** - * Retrieve address group item for update. - * \param group Group to print. - * \param array GHashTAble of item_group, or <i>NULL</i> if none created. - */ -void ldapsvr_retrieve_item_group(ItemGroup *group, GHashTable *array) { - /* Not implemented in this release */ - cm_return_if_fail(group != NULL); -} - -/** - * Create an initial EmailKeyValue structure - * \return empty structure - */ -EmailKeyValue *emailkeyvalue_create() { - EmailKeyValue *buf; - - buf = g_new0(EmailKeyValue, 1); - buf->alias = NULL; - buf->mail = NULL; - buf->remarks = NULL; - return buf; -} - -/** - * Create an initial AttrKeyValue structure - * \return empty structure - */ -AttrKeyValue *attrkeyvalue_create() { - AttrKeyValue *buf; - - buf = g_new0(AttrKeyValue, 1); - buf->key = NULL; - buf->value = NULL; - return buf; -} - -/** - * Free created AttrKeyValue structure - * \param akv AttrKeyValue structure to free - */ -void attrkeyvalue_free(AttrKeyValue *akv) { - if (akv->key) { - g_free(akv->key); - akv->key = NULL; - } - if (akv->value) { - g_free(akv->value); - akv->value = NULL; - } - g_free(akv); - akv = NULL; -} - -/** - * Retrieve E-Mail address object for update. - * \param item ItemEmail to update. - * \return object, or <i>NULL</i> if none created. - */ -EmailKeyValue *ldapsvr_retrieve_item_email(ItemEMail *item) { - EmailKeyValue *newItem; - cm_return_val_if_fail(item != NULL, NULL); - newItem = emailkeyvalue_create(); - newItem->alias = g_strdup(ADDRITEM_NAME(item)); - newItem->mail = g_strdup(item->address); - newItem->remarks = g_strdup(item->remarks); - return newItem; -} - -/** - * Retrieve user attribute object for update. - * \param item UserAttribute to update. - * \return object, or <i>NULL</i> if none created. - */ -AttrKeyValue *ldapsvr_retrieve_attribute(UserAttribute *item) { - AttrKeyValue *newItem; - cm_return_val_if_fail(item != NULL, NULL); - newItem = attrkeyvalue_create(); - newItem->key = g_strdup(item->name); - newItem->value = g_strdup(item->value); - return newItem; -} - -/** - * Retrieve person object for update. - * \param person ItemPerson to update. - * \param array GHashTable with user input. - * \return false if update is not needed, or true if update is needed. - */ -gboolean ldapsvr_retrieve_item_person(ItemPerson *person, GHashTable *array) { - GList *node, *attr; - - cm_return_val_if_fail(person != NULL, FALSE); - switch (person->status) { - case NONE: return FALSE; - case ADD_ENTRY: g_hash_table_insert(array, "status", "new"); break; - case UPDATE_ENTRY: g_hash_table_insert(array, "status", "update"); break; - case DELETE_ENTRY: g_hash_table_insert(array, "status", "delete"); break; - default: g_critical("ldapsvr_retrieve_item_person->Unknown status: %d", person->status); - } - g_hash_table_insert(array, "uid", ADDRITEM_ID(person)); - g_hash_table_insert(array, "cn", ADDRITEM_NAME(person)); - g_hash_table_insert(array, "givenName", person->firstName); - g_hash_table_insert(array, "sn", person->lastName); - g_hash_table_insert(array, "nickName", person->nickName); - g_hash_table_insert(array, "dn", person->externalID); - g_hash_table_insert(array, "person", person); - node = person->listEMail; - attr = NULL; - while (node) { - EmailKeyValue *newEmail = ldapsvr_retrieve_item_email(node->data); - if (newEmail) - attr = g_list_append(attr, newEmail); - node = g_list_next(node); - } - g_hash_table_insert(array, "mail", attr); - node = person->listAttrib; - attr = NULL; - while (node) { - AttrKeyValue *newAttr = ldapsvr_retrieve_attribute(node->data); - if (newAttr) - attr = g_list_append(attr, newAttr); - node = g_list_next(node); - } - g_hash_table_insert(array, "attribute", attr); - return TRUE; -} - -/** - * Print contents of contacts hashtable for debug. - * This function must be called with g_hash_table_foreach. - * \param key Key to process. - * \param data Data to process. - * \param fd Output stream. - */ -void ldapsvr_print_contacts_hashtable(gpointer key, gpointer data, gpointer fd) { - gchar *keyName = (gchar *) key; - GList *node; - - if (g_ascii_strcasecmp("mail", keyName) == 0) { - node = (GList *) data; - while (node) { - EmailKeyValue *item = node->data; - if (debug_get_mode()) { - debug_print("\t\talias = %s\n", item->alias?item->alias:"null"); - debug_print("\t\tmail = %s\n", item->mail?item->mail:"null"); - debug_print("\t\tremarks = %s\n", item->remarks?item->remarks:"null"); - } - else if (fd) { - FILE *stream = (FILE *) fd; - fprintf(stream, "\t\talias = %s\n", item->alias?item->alias:"null"); - fprintf(stream, "\t\tmail = %s\n", item->mail?item->mail:"null"); - fprintf(stream, "\t\tremarks = %s\n", item->remarks?item->remarks:"null"); - } - node = g_list_next(node); - } - } - else if (g_ascii_strcasecmp("attribute", keyName) == 0) { - node = (GList *) data; - while (node) { - AttrKeyValue *item = node->data; - if (debug_get_mode()) { - debug_print("\t\t%s = %s\n", item->key?item->key:"null", - item->value?item->value:"null"); - } - else if (fd) { - FILE *stream = (FILE *) fd; - fprintf(stream, "\t\t%s = %s\n", item->key?item->key:"null", - item->value?item->value:"null"); - } - node = g_list_next(node); - } - } - else { - if (debug_get_mode()) - debug_print("\t\t%s = %s\n", keyName?keyName:"null", data?(gchar *)data:"null"); - else if (fd) { - FILE *stream = (FILE *) fd; - fprintf(stream, "\t\t%s = %s\n", keyName?keyName:"null", data?(gchar *)data:"null"); - } - } -} - -/** - * Free list of changed contacts - * - * \param list List of GHashTable - */ -void ldapsvr_free_hashtable(GList *list) { - GList *tmp = list; - while (tmp) { - g_hash_table_destroy(tmp->data); - tmp->data = NULL; - tmp = g_list_next(tmp); - } - g_list_free(list); - list = NULL; -} - -/** - * Get person object from cache - * - * \param server Resource to LDAP - * \param uid PersonID in cache - * \return person object, or <i>NULL</i> if fail - */ -ItemPerson *ldapsvr_get_contact(LdapServer *server, gchar *uid) { - AddrItemObject *aio; - cm_return_val_if_fail(server != NULL || uid != NULL, NULL); - aio = addrcache_get_object(server->addressCache, uid); - if (aio) { - if(aio->type == ITEMTYPE_PERSON) { - return (ItemPerson *) aio; - } - } - return NULL; -} - -/** - * Create an initial Rdn structure - * - * \return empty structure - */ -Rdn *rdn_create() { - Rdn *buf; - - buf = g_new0(Rdn, 1); - buf->attribute = NULL; - buf->value = NULL; - buf->new_dn = NULL; - return buf; -} - -/** - * Free a created Rdn structure - * \param rdn Structure to free - */ -void rdn_free(Rdn *rdn) { - if (rdn->attribute) { - g_free(rdn->attribute); - rdn->attribute = NULL; - } - if (rdn->value) { - g_free(rdn->value); - rdn->value = NULL; - } - if (rdn->new_dn) { - g_free(rdn->new_dn); - rdn->new_dn = NULL; - } - g_free(rdn); - rdn = NULL; -} - -/** - * update Rdn structure - * - * \param rdn Rdn structure to update - * \param head Uniq part of dn - * \param tail Common part of dn - */ -void update_rdn(Rdn *rdn, gchar *head, gchar *tail) { - rdn->value = g_strdup(head); - rdn->new_dn = g_strdup_printf("%s=%s%s", rdn->attribute, head, tail); -} - -/** - * Deside if dn needs to be changed - * - * \param hash GHashTable with user input. - * \param dn dn for current object - * \return Rdn structure - */ -Rdn *ldapsvr_modify_dn(GHashTable *hash, gchar *dn) { - Rdn *rdn; - gchar *pos, *compare; - gchar *rest; - gchar *val; - cm_return_val_if_fail(hash != NULL || dn != NULL, NULL); - - pos = g_strstr_len(dn, strlen(dn), "="); - if (!pos) - return NULL; - - compare = g_strndup(dn, pos - dn); - - pos++; - rest = g_strstr_len(pos, strlen(pos), ","); - val = g_strndup(pos, rest - pos); - if (val == NULL) { - if (compare) - g_free(compare); - return NULL; - } - rdn = rdn_create(); - rdn->value = val; - rdn->attribute = compare; - - if (strcmp("mail", rdn->attribute) == 0) { - GList *list = g_hash_table_lookup(hash, rdn->attribute); - while (list) { - EmailKeyValue *item = list->data; - compare = (gchar *) item->mail; - if (strcmp(compare, rdn->value) == 0) { - update_rdn(rdn, compare, rest); - return rdn; - } - list = g_list_next(list); - } - /* if compare and rdn->attribute are equal then last email removed/empty */ - if (strcmp(compare, rdn->attribute) != 0) { - /* RDN changed. Find new */ - update_rdn(rdn, compare, rest); - return rdn; - } - } - else { - compare = g_hash_table_lookup(hash, rdn->attribute); - /* if compare and rdn->attribute are equal then dn removed/empty */ - if (compare != NULL && strcmp(compare, rdn->attribute) != 0) { - update_rdn(rdn, compare, rest); - return rdn; - } - } - rdn_free(rdn); - return NULL; -} - -/** - * This macro is borrowed from the Balsa project - * Creates a LDAPMod structure - * - * \param mods Empty LDAPMod structure - * \param modarr Array with values to insert - * \param op Operation to perform on LDAP - * \param attr Attribute to insert - * \param strv Empty array which is NULL terminated - * \param val Value for attribute - */ -#define SETMOD(mods,modarr,op,attr,strv,val) \ - do { (mods) = &(modarr); (modarr).mod_type=attr; (modarr).mod_op=op;\ - (strv)[0]=(val); (modarr).mod_values=strv; \ - } while(0) - -/** - * Creates a LDAPMod structure - * - * \param mods Empty LDAPMod structure - * \param modarr Array with values to insert - * \param op Operation to perform on LDAP - * \param attr Attribute to insert - * \param strv Array with values to insert. Must be NULL terminated - */ -#define SETMODS(mods,modarr,op,attr,strv) \ - do { (mods) = &(modarr); (modarr).mod_type=attr; \ - (modarr).mod_op=op; (modarr).mod_values=strv; \ - } while(0) -#define MODSIZE 10 - -/** - * Clean up, close LDAP connection, and refresh cache - * - * \param ld Resource to LDAP - * \param server AddressBook resource - * \param contact GHashTable with current changed object - */ -void clean_up(LDAP *ld, LdapServer *server, GHashTable *contact) { - ItemPerson *person = - ldapsvr_get_contact(server, g_hash_table_lookup(contact , "uid")); - if (person) { - gchar *displayName; - person->status = NONE; - displayName = g_hash_table_lookup(contact, "displayName"); - if (displayName) - person->nickName = g_strdup(displayName); - } - if (server->retVal != LDAPRC_SUCCESS) { - if (person) { - ItemPerson *res = - addrcache_remove_person(server->addressCache, person); - if (!res) - g_critical("ldapsvr_update_book: Could not clean cache\n"); - else - addritem_free_item_person(res); - } - } - if (ld) - ldapsvr_disconnect(ld); -} - -/** - * Get cn attribute from dn - * - * \param dn Distinguesh Name for current object - * \return AttrKeyValue, or <i>NULL</i> if none created - */ -AttrKeyValue *get_cn(gchar *dn) { - AttrKeyValue *cn; - gchar *start; - gchar *end; - gchar *item; - gchar **key_value; - cm_return_val_if_fail(dn != NULL, NULL); - - cn = attrkeyvalue_create(); - start = g_strstr_len(dn, strlen(dn), "cn"); - if (start == NULL) { - attrkeyvalue_free(cn); - return NULL; - } - end = g_strstr_len(start, strlen(start), ","); - item = g_strndup(start, end - start); - if (item == NULL) { - attrkeyvalue_free(cn); - return NULL; - } - key_value = g_strsplit(item, "=", 2); - cn->key = g_strdup(key_value[0]); - cn->value = g_strdup(key_value[1]); - g_strfreev(key_value); - g_free(item); - return cn; -} - -/** - * Get mail attribute from dn - * - * \param dn Distinguesh Name for current object - * \return AttrKeyValue, or <i>NULL</i> if none created - */ -AttrKeyValue *get_mail(gchar *dn) { - AttrKeyValue *mail; - gchar *start; - gchar *end; - gchar *item; - gchar **key_value; - cm_return_val_if_fail(dn != NULL, NULL); - - mail = attrkeyvalue_create(); - start = g_strstr_len(dn, strlen(dn), "mail"); - if (start == NULL) { - attrkeyvalue_free(mail); - return NULL; - } - end = g_strstr_len(start, strlen(start), ","); - item = g_strndup(start, end - start); - if (item == NULL) { - attrkeyvalue_free(mail); - return NULL; - } - key_value = g_strsplit(item, "=", 2); - mail->key = g_strdup(key_value[0]); - mail->value = g_strdup(key_value[1]); - g_strfreev(key_value); - g_free(item); - return mail; -} - -/** - * Get ou or o attribute from dn - * - * \param dn Distinguesh Name for current object - * \return AttrKeyValue, or <i>NULL</i> if none created - */ -AttrKeyValue *get_ou(gchar *dn) { - AttrKeyValue *ou; - gchar *start; - gchar *end; - gchar *item; - gchar **key_value; - - cm_return_val_if_fail(dn != NULL, NULL); - ou = attrkeyvalue_create(); - start = g_strstr_len(dn, strlen(dn), ",o="); - if (start == NULL) - start = g_strstr_len(dn, strlen(dn), ",ou="); - if (start == NULL) { - attrkeyvalue_free(ou); - return NULL; - } - start++; - end = g_strstr_len(start, strlen(start), ","); - item = g_strndup(start, end - start); - if (item == NULL) { - attrkeyvalue_free(ou); - return NULL; - } - key_value = g_strsplit(item, "=", 2); - ou->key = g_strdup(key_value[0]); - ou->value = g_strdup(key_value[1]); - g_strfreev(key_value); - g_free(item); - return ou; -} - -/** - * Print the contents of a LDAPMod structure for debuging purposes - * - * \param mods LDAPMod structure - */ -void ldapsvr_print_ldapmod(LDAPMod *mods[]) { - gchar *mod_op; - int i; - - cm_return_if_fail(mods != NULL); - g_printerr( "Type\n"); - for (i = 0; NULL != mods[i]; i++) { - LDAPMod *mod = (LDAPMod *) mods[i]; - gchar **vals; - switch (mod->mod_op) { - case LDAP_MOD_ADD: mod_op = g_strdup("ADD"); break; - case LDAP_MOD_REPLACE: mod_op = g_strdup("MODIFY"); break; - case LDAP_MOD_DELETE: mod_op = g_strdup("DELETE"); break; - default: mod_op = g_strdup("UNKNOWN"); - } - g_printerr( "Operation: %s\tType:%s\nValues:\n", mod_op, mod->mod_type); - vals = mod->mod_vals.modv_strvals; - while (*vals) { - g_printerr( "\t%s\n", *vals++); - } - } -} - -/** - * Make a compare for every new value we want to store in the - * directory with the current values. Great tool for debugging - * against invalid syntax in attributes - * - * \param ld AddressBook resource - * \param dn dn for the entry - * \param cnt Number of attributes to compare - * \param mods LDAPMod structure - */ -void ldapsvr_compare_attr(LDAP *ld, gchar *dn, gint cnt, LDAPMod *mods[]) { - int i, rc; - -#ifdef OPEN_LDAP_API_AT_LEAST_3000 - - struct berval val; - -#endif - - cm_return_if_fail(ld != NULL || dn != NULL || cnt >= 0 || mods != NULL); - for (i = 0; i < cnt; i++) { - gchar *value = g_strdup(mods[i]->mod_vals.modv_strvals[0]); - if (!value || strcmp(value, "") == 0) - value = g_strdup("thisisonlyadummy"); - -#ifdef OPEN_LDAP_API_AT_LEAST_3000 - - val.bv_val = value; - val.bv_len = strlen(value); - - rc = ldap_compare_ext_s(ld, dn, mods[i]->mod_type, &val, NULL, NULL); - -#else - - /* This is deprecated as of OpenLDAP-2.3.0 */ - rc = ldap_compare_s(ld, dn, mods[i]->mod_type, value); - -#endif - - g_printerr("ldap_compare for (%s:%s)\" failed[0x%x]: %s\n", - mods[i]->mod_type, value, rc, ldaputil_get_error(ld)); - g_free(value); - } -} - -/** - * compare attribute to LDAP in case of LDAP_INAPPROPRIATE_MATCHING - * - * \param ld AddressBook resource - * \param server Reference to server - * \param dn dn for the entry - * \param attr Attribute - * \param value New value - * \return int, return will be LDAP_MOD_ADD, LDAP_MOD_REPLACE, or LDAP_MOD_DELETE - */ -int ldapsvr_compare_manual_attr(LDAP *ld, LdapServer *server, gchar *dn, char *attr, char *value) { - LDAPMessage *res, *e = NULL; - BerElement *ber; - struct berval **vals; - int rc; - LdapControl *ctl; - gchar *filter; - gchar *attribute; - int retVal = -2, i; - AttrKeyValue *mail; - - cm_return_val_if_fail(ld != NULL || server != NULL || attr != NULL, -1); - ctl = server->control; - mail = get_mail(dn); - if (! mail) - return -2; - filter = g_strdup_printf("(&(mail=%s)(%s=*))", mail->value, attr); - attrkeyvalue_free(mail); - if (ctl) { - - rc = ldap_search_ext_s(ld, ctl->baseDN, LDAP_SCOPE_ONELEVEL, filter, NULL, 0, NULL, NULL, NULL, 0, &res); - - if (rc) { - log_error(LOG_PROTOCOL, _("LDAP error (search): for attribute '%s': %d (%s)\n"), - attr, rc, ldaputil_get_error(ld)); - retVal = -2; - } - else { - e = ldap_first_entry(ld, res); - /* entry has this attribute */ - if (e) { - attribute = ldap_first_attribute( ld, e, &ber ); - if (attribute) { - if (value) { - if( ( vals = ldap_get_values_len( ld, e, attr ) ) != NULL ) { - for( i = 0; vals[i] != NULL; i++ ) { - debug_print("Compare: %s=%s\n", attr, vals[i]->bv_val); - /* attribute has same value */ - if (strcmp(vals[i]->bv_val, value) == 0) - retVal = -1; - /* attribute has new value */ - else - retVal = LDAP_MOD_REPLACE; - } - } - ldap_value_free_len(vals); - } - else - retVal = LDAP_MOD_DELETE; - } - if( ber != NULL ) { - ber_free( ber, 0 ); - } - ldap_memfree(attribute); - } - /* entry does not have this attribute */ - else { - /* Only add if this is a real attribute */ - if (value) - retVal = LDAP_MOD_ADD; - /* This is dummy value used to avoid ldap_compare error */ - else - retVal = -1; - } - } - } - else - retVal = -2; - g_free(filter); - return retVal; -} - -/** - * Deside which kind of operation is required to handle - * updating the specified attribute - * - * \param ld AddressBook resource - * \param server Reference to server - * \param dn dn for the entry - * \param attr Attribute - * \param value New value - * \return int, return will be LDAP_MOD_ADD, LDAP_MOD_REPLACE, or LDAP_MOD_DELETE - */ -int ldapsvr_deside_operation(LDAP *ld, LdapServer *server, char *dn, char *attr, char *value) { - int rc; - gboolean dummy = FALSE; - -#ifdef OPEN_LDAP_API_AT_LEAST_3000 - - struct berval val; - -#endif - - cm_return_val_if_fail(ld != NULL || server != NULL || dn != NULL || attr != NULL, -1); - if (value == NULL) - return -1; - /* value containing empty string cause invalid syntax. A bug in - * the LDAP library? Therefore we add a dummy value - */ - if (strcmp(value,"") == 0) { - value = g_strdup("thisisonlyadummy"); - dummy = TRUE; - } - -#ifdef OPEN_LDAP_API_AT_LEAST_3000 - - val.bv_val = value; - val.bv_len = strlen(value); - - rc = ldap_compare_ext_s(ld, dn, attr, &val, NULL, NULL); - -#else - - /* This is deprecated as of OpenLDAP-2.3.0 */ - rc = ldap_compare_s(ld, dn, attr, value); - -#endif - - debug_print("ldap_compare for (%s:%s)\" error_code[0x%x]: %s\n", - attr, value, rc, ldaputil_get_error(ld)); - switch (rc) { - case LDAP_COMPARE_FALSE: - if (dummy) - return LDAP_MOD_DELETE; - else - return LDAP_MOD_REPLACE; - case LDAP_COMPARE_TRUE: return -1; - case LDAP_NO_SUCH_ATTRIBUTE: return LDAP_MOD_ADD; - /* LDAP_INAPPROPRIATE_MATCHING needs extensive testing because I - * am not aware off the condition causing this return value! - */ - case LDAP_INAPPROPRIATE_MATCHING: - if (dummy) - value = NULL; - return ldapsvr_compare_manual_attr(ld, server, dn, attr, value); - case LDAP_UNDEFINED_TYPE: return -2; - case LDAP_INVALID_SYNTAX: return -2; - default: return -2; - } -} - -/** - * Check if attribute is part of the current search criteria - * - * \param list Array containing attributes in the current search criteria - * \param attr Attribute to check - * \result <i>TRUE</i> if attribute is found in the current search criteria - */ -gboolean ldapsvr_check_search_attributes(char **list, char *attr) { - while (*list) { - if (strcmp(*list++, attr) == 0) - return TRUE; - } - return FALSE; -} - -/** - * Deside which other attributes needs updating - * - * \param ld LDAP resource - * \param server AddressBook resource - * \param dn dn for the entry - * \param contact GHashTable with information for the current contact - */ -void ldapsvr_handle_other_attributes(LDAP *ld, LdapServer *server, char *dn, GHashTable *contact) { - GList *node; - gboolean CHECKED_ATTRIBUTE[ATTRIBUTE_SIZE + 1]; - LDAPMod *mods[ATTRIBUTE_SIZE + 1]; - LDAPMod modarr[ATTRIBUTE_SIZE]; - gint cnt = 0; - char *attr[ATTRIBUTE_SIZE + 1][2]; - int mod_op, rc, i; - - cm_return_if_fail(server != NULL || dn != NULL || contact != NULL); - for (i = 0; i <= ATTRIBUTE_SIZE; i++) { - CHECKED_ATTRIBUTE[i] = FALSE; - attr[i][0] = attr[i][1] = NULL; - } - node = g_hash_table_lookup(contact , "attribute"); - while (node) { - AttrKeyValue *item = node->data; - if (item) { - int index = get_attribute_index(item->key); - if (index >= 0) { - debug_print("Found other attribute: %s = %s\n", - item->key?item->key:"null", item->value?item->value:"null"); - mod_op = ldapsvr_deside_operation(ld, server, dn, item->key, item->value); - /* Only consider attributes which we no how to handle. - * Set to TRUE in CHECKED_ATTRIBUTE array to indicate no further action - */ - if (mod_op < 0) { - CHECKED_ATTRIBUTE[index] = TRUE; - node = g_list_next(node); - continue; - } - if (mod_op == LDAP_MOD_DELETE) { - /* Setting param to NULL instructs OpenLDAP to remove any - * value stored for this attribute and remove the attribute - * completely. Should multiple instances of an attribute be - * allowed in the future param is required to have the value - * store for the attribute which is going to be deleted - */ - item->value = NULL; - } - if (mod_op == LDAP_MOD_REPLACE && strcmp(item->value, "") == 0) { - /* Having an empty string is considered a syntax error in - * ldap. E.g attributes with empty strings are not allowed - * in which case we treate this as a request for deleting - * the attribute. - */ - mod_op = LDAP_MOD_DELETE; - item->value = NULL; - } - if (mod_op == LDAP_MOD_ADD && strcmp(item->value, "") == 0) { - /* Adding an empty string is considered a syntax error in - * ldap. E.g attributes with empty strings are not allowed - * in which case we silently refuse to add this entry - */ - } - else { - SETMOD(mods[cnt], modarr[cnt], mod_op, g_strdup(item->key), attr[cnt], g_strdup(item->value)); - cnt++; - CHECKED_ATTRIBUTE[index] = TRUE; - } - } - } - node = g_list_next(node); - } - char **attribs = ldapctl_full_attribute_array(server->control); - for (i = 0; i < ATTRIBUTE_SIZE; i++) { - /* Attributes which holds no information are to be removed */ - if (CHECKED_ATTRIBUTE[i] == FALSE) { - /* Only consider those attributes which is currently part of the search criteria. - * If attributes are not part of the search criteria they would seem to hold - * no information since their values will not be populated in the GUI - */ - if (!strcmp(ATTRIBUTE[i], "jpegPhoto")) { - debug_print("not updating jpegPhoto\n"); - continue; - } - if (ldapsvr_check_search_attributes(attribs, (char *) ATTRIBUTE[i])) { - mod_op = ldapsvr_deside_operation(ld, server, dn, (char *) ATTRIBUTE[i], ""); - if (mod_op == LDAP_MOD_DELETE) { - SETMOD(mods[cnt], modarr[cnt], LDAP_MOD_DELETE, g_strdup((char *) ATTRIBUTE[i]), attr[cnt], NULL); - cnt++; - } - } - } - } - ldapctl_free_attribute_array(attribs); - mods[cnt] = NULL; - if (debug_get_mode()) - ldapsvr_print_ldapmod(mods); - server->retVal = LDAPRC_SUCCESS; - rc = ldap_modify_ext_s(ld, dn, mods, NULL, NULL); - if (rc) { - switch (rc) { - case LDAP_ALREADY_EXISTS: - server->retVal = LDAPRC_ALREADY_EXIST; - break; - default: - log_error(LOG_PROTOCOL, _("LDAP error (modify): for DN '%s': %d (%s)\n"), - dn, rc, ldaputil_get_error(ld)); - if (rc == 0x8) - server->retVal = LDAPRC_STRONG_AUTH; - else - server->retVal = LDAPRC_NAMING_VIOLATION; - } - } - else { - char **attribs = ldapctl_full_attribute_array(server->control); - for (i = 0; i < ATTRIBUTE_SIZE; i++) { - if (!strcmp(ATTRIBUTE[i], "jpegPhoto")) { - debug_print("not updating jpegPhoto\n"); - continue; - } - if (ldapsvr_check_search_attributes(attribs, (char *) ATTRIBUTE[i])) { - if (CHECKED_ATTRIBUTE[i] == FALSE) { - AddrItemObject *aio = addrcache_get_object(server->addressCache, g_hash_table_lookup(contact , "uid")); - ItemPerson *person = (ItemPerson *) aio; - addritem_person_remove_attribute(person, (const gchar *) ATTRIBUTE[i]); - } - } - } - ldapctl_free_attribute_array(attribs); - } -} - -/** - * Add new contact to LDAP - * - * \param server AddressBook resource - * \param contact GHashTable with object to add - */ -void ldapsvr_add_contact(LdapServer *server, GHashTable *contact) { - gchar *email = NULL, *param = NULL; - LDAP *ld = NULL; - LDAPMod *mods[MODSIZE]; - LDAPMod modarr[7]; - gint cnt = 0; - char *cn[] = {NULL, NULL}; - char *displayName[] = {NULL, NULL}; - char *givenName[] = {NULL, NULL}; - char **mail = NULL; - char *sn[] = {NULL, NULL}; - char *org[] = {NULL, NULL}; - char *obj[] = {/*"top",*/ "person", "organizationalPerson", "inetOrgPerson", NULL}; - int rc=0; - GList *node; - AttrKeyValue *ou, *commonName; - ItemPerson *person; - gchar *base_dn; - GList *mailList; - - cm_return_if_fail(server != NULL || contact != NULL); - node = g_hash_table_lookup(contact , "mail"); - if (node) { - EmailKeyValue *newEmail = node->data; - email = g_strdup(newEmail->mail); - } - if (email == NULL) { - server->retVal = LDAPRC_NODN; - clean_up(ld, server, contact); - return; - } - base_dn = g_strdup_printf("mail=%s,%s", - email, server->control->baseDN?server->control->baseDN:"null"); - g_free(email); - person = - ldapsvr_get_contact(server, g_hash_table_lookup(contact , "uid")); - person->externalID = g_strdup(base_dn); - debug_print("dn: %s\n", base_dn); - ld = ldapsvr_connect(server->control); - if (ld == NULL) { - clean_up(ld, server, contact); - debug_print("no ldap found\n"); - return; - } - SETMODS(mods[cnt], modarr[cnt], LDAP_MOD_ADD, "objectClass", obj); - cnt++; - ou = get_ou(base_dn); - if (ou != NULL) { - SETMOD(mods[cnt], modarr[cnt], LDAP_MOD_ADD, g_strdup(ou->key), org, g_strdup(ou->value)); - cnt++; - attrkeyvalue_free(ou); - } - - commonName = get_cn(base_dn); - if (commonName == NULL) { - param = g_hash_table_lookup(contact , "cn"); - if (param) { - SETMOD(mods[cnt], modarr[cnt], LDAP_MOD_ADD, "cn", cn, param); - } - else { - clean_up(ld, server, contact); - debug_print("no CN found\n"); - return; - } - } - else { - SETMOD(mods[cnt], modarr[cnt], LDAP_MOD_ADD, g_strdup(commonName->key), cn, g_strdup(commonName->value)); - cnt++; - param = g_hash_table_lookup(contact , "cn"); - SETMOD(mods[cnt], modarr[cnt], LDAP_MOD_ADD, "displayName", displayName, param); - g_hash_table_insert(contact, "displayName", param); - attrkeyvalue_free(commonName); - } - cnt++; - param = g_hash_table_lookup(contact , "givenName"); - if (param) { - SETMOD(mods[cnt], modarr[cnt], LDAP_MOD_ADD, "givenName", givenName, param); - cnt++; - } - mailList = g_hash_table_lookup(contact , "mail"); - if (mailList) { - char **tmp; - tmp = g_malloc(sizeof(*tmp) * (g_list_length(mailList)+1)); - mail = tmp; - while (mailList) { - EmailKeyValue *item = mailList->data; - *tmp++ = g_strdup((gchar *) item->mail); - mailList = g_list_next(mailList); - } - *tmp = NULL; - SETMODS(mods[cnt], modarr[cnt], LDAP_MOD_ADD, "mail", mail); - cnt++; - } - param = g_hash_table_lookup(contact, "sn"); - if (param == NULL) - param = g_strdup(N_("Some SN")); - SETMOD(mods[cnt], modarr[cnt], LDAP_MOD_ADD, "sn", sn, param); - cnt++; - mods[cnt] = NULL; - if (debug_get_mode()) { - ldapsvr_print_ldapmod(mods); - } - server->retVal = LDAPRC_SUCCESS; - rc = ldap_add_ext_s(ld, base_dn, mods, NULL, NULL); - if (rc) { - switch (rc) { - case LDAP_ALREADY_EXISTS: - server->retVal = LDAPRC_ALREADY_EXIST; - break; - default: - log_error(LOG_PROTOCOL, _("LDAP error (modify): for DN '%s': %d (%s)\n"), - base_dn, rc, ldaputil_get_error(ld)); - if (rc == 0x8) - server->retVal = LDAPRC_STRONG_AUTH; - else - server->retVal = LDAPRC_NAMING_VIOLATION; - } - } - ldapsvr_handle_other_attributes(ld, server, base_dn, contact); - g_free(base_dn); - clean_up(ld, server, contact); -} - -/** - * Update contact to LDAP - * - * \param server AddressBook resource - * \param contact GHashTable with object to update - */ -void ldapsvr_update_contact(LdapServer *server, GHashTable *contact) { - LDAP *ld = NULL; - LDAPMod *mods[MODSIZE]; - LDAPMod modarr[4]; - gint cnt = 0; - gchar *param, *dn; - Rdn *NoRemove = NULL; - char *cn[] = {NULL, NULL}; - char *givenName[] = {NULL, NULL}; - char **mail = NULL; - char *sn[] = {NULL, NULL}; - GList *mailList; - int mod_op; - - cm_return_if_fail(server != NULL || contact != NULL); - ld = ldapsvr_connect(server->control); - if (ld == NULL) { - clean_up(ld, server, contact); - return; - } - dn = g_hash_table_lookup(contact, "dn"); - - if (dn == NULL) { - clean_up(ld, server, contact); - return; - } - NoRemove = ldapsvr_modify_dn(contact, dn); - if (NoRemove) { - /* We are trying to change RDN */ - gchar *newRdn = g_strdup_printf("%s=%s", NoRemove->attribute, NoRemove->value); - -#ifdef OPEN_LDAP_API_AT_LEAST_3000 - - int rc = ldap_rename_s(ld, dn, newRdn, NULL, 1, NULL, NULL); - -#else - - /* This is deprecated as of OpenLDAP-2.3.0 */ - int rc = ldap_modrdn2_s(ld, dn, newRdn, 1); - -#endif - - if(rc != LDAP_SUCCESS) { - if (rc == LDAP_ALREADY_EXISTS) { - /* We are messing with a contact with more than one listed email - * address and the email we are changing is not the one used for dn - */ - /* It needs to be able to handle renaming errors to an already defined - * dn. For now we just refuse the update. It will be caught later on as - * a LDAPRC_NAMING_VIOLATION error. - */ - } - else { - log_error(LOG_PROTOCOL, _("LDAP error (rename): from '%s' to '%s': %d (%s)\n"), - dn, newRdn, rc, ldaputil_get_error(ld)); - g_free(newRdn); - rdn_free(NoRemove); - clean_up(ld, server, contact); - return; - } - } - else { - ItemPerson *person = g_hash_table_lookup(contact, "person"); - g_free(newRdn); - dn = g_strdup(NoRemove->new_dn); - g_hash_table_replace(contact, "dn", dn); - if (person) { - g_free(person->externalID); - person->externalID = dn; - } - } - } - else { - server->retVal = LDAPRC_NODN; - clean_up(ld, server, contact); - return; - } - param = g_hash_table_lookup(contact , "cn"); - mod_op = ldapsvr_deside_operation(ld, server, dn, "displayName", param); - if (mod_op >= 0 && (strcmp(param, NoRemove->value) != 0 && strcmp("cn", NoRemove->attribute) != 0)) { - if (mod_op == LDAP_MOD_DELETE) { - /* Setting param to NULL instructs OpenLDAP to remove any - * value stored for this attribute and remove the attribute - * completely. Should multiple instances of an attribute be - * allowed in the future param is required to have the value - * store for the attribute which is going to be deleted - */ - param = NULL; - } - if (mod_op == LDAP_MOD_REPLACE && strcmp(param, "") == 0) { - /* Having an empty string is considered a syntax error in - * ldap. E.g attributes with empty strings are not allowed - * in which case we treate this as a request for deleting - * the attribute. - */ - mod_op = LDAP_MOD_DELETE; - param = NULL; - } - if (mod_op == LDAP_MOD_ADD && strcmp(param, "") == 0) { - /* Adding an empty string is considered a syntax error in - * ldap. E.g attributes with empty strings are not allowed - * in which case we silently refuse to add this entry - */ - } - else { - SETMOD(mods[cnt], modarr[cnt], mod_op, "displayName", cn, param); - cnt++; - g_hash_table_insert(contact, "displayName", param); - } - } - param = g_hash_table_lookup(contact , "givenName"); - mod_op = ldapsvr_deside_operation(ld, server, dn, "givenName", param); - if (mod_op >= 0 && (strcmp(param, NoRemove->value) != 0 && strcmp("givenName", NoRemove->attribute) != 0)) { - if (mod_op == LDAP_MOD_DELETE) { - /* Setting param to NULL instructs OpenLDAP to remove any - * value stored for this attribute and remove the attribute - * completely. Should multiple instances of an attribute be - * allowed in the future param is required to have the value - * store for the attribute which is going to be deleted - */ - param = NULL; - } - if (mod_op == LDAP_MOD_REPLACE && strcmp(param, "") == 0) { - /* Having an empty string is considered a syntax error in - * ldap. E.g attributes with empty strings are not allowed - * in which case we treate this as a request for deleting - * the attribute. - */ - mod_op = LDAP_MOD_DELETE; - param = NULL; - } - if (mod_op == LDAP_MOD_ADD && strcmp(param, "") == 0) { - /* Adding an empty string is considered a syntax error in - * ldap. E.g attributes with empty strings are not allowed - * in which case we silently refuse to add this entry - */ - } - else { - SETMOD(mods[cnt], modarr[cnt], mod_op, "givenName", givenName, param); - cnt++; - } - } - mailList = g_hash_table_lookup(contact , "mail"); - if (mailList) { - debug_print("# of mail: %d\n", g_list_length(mailList)); - if (!(strcmp("mail", NoRemove->attribute) == 0 && g_list_length(mailList) == 1)) { - char **tmp; - tmp = g_malloc(sizeof(*tmp) * (g_list_length(mailList)+1)); - mail = tmp; - while (mailList) { - EmailKeyValue *item = mailList->data; - *tmp++ = g_strdup((gchar *) item->mail); - mailList = g_list_next(mailList); - } - *tmp = NULL; - /* - * At least one email address is required - * in which case it will always be a replace - */ - SETMODS(mods[cnt], modarr[cnt], LDAP_MOD_REPLACE, "mail", mail); - cnt++; - } - } - else { - /* - * an error condition since at least one email adress - * is required. Should never occur though. - */ - } - param = g_hash_table_lookup(contact , "sn"); - mod_op = ldapsvr_deside_operation(ld, server, dn, "sn", param); - if (mod_op >= 0 && (strcmp(param, NoRemove->value) != 0 && strcmp("sn", NoRemove->attribute) != 0)) { - if (mod_op == LDAP_MOD_DELETE) { - /* Setting param to NULL instructs OpenLDAP to remove any - * value stored for this attribute and remove the attribute - * completely. Should multiple instances of an attribute be - * allowed in the future param is required to have the value - * store for the attribute which is going to be deleted - */ - param = NULL; - } - if (mod_op == LDAP_MOD_REPLACE && strcmp(param, "") == 0) { - /* Having an empty string is considered a syntax error in - * ldap. E.g attributes with empty strings are not allowed - * in which case we treate this as a request for deleting - * the attribute. - */ - mod_op = LDAP_MOD_DELETE; - param = NULL; - } - if (mod_op == LDAP_MOD_ADD && strcmp(param, "") == 0) { - /* Adding an empty string is considered a syntax error in - * ldap. E.g attributes with empty strings are not allowed - * in which case we silently refuse to add this entry - */ - } - else { - SETMOD(mods[cnt], modarr[cnt], mod_op, "sn", sn, param); - cnt++; - } - } - debug_print("newDN: %s\n", dn); - if (NoRemove) - rdn_free(NoRemove); - server->retVal = LDAPRC_SUCCESS; - if (cnt > 0) { - int rc; - mods[cnt] = NULL; - rc = ldap_modify_ext_s(ld, dn, mods, NULL, NULL); - if (rc) { - log_error(LOG_PROTOCOL, _("LDAP error (modify): for DN '%s': %d (%s)\n"), - dn, rc, ldaputil_get_error(ld)); - server->retVal = LDAPRC_NAMING_VIOLATION; - } - if (mail) - g_free(mail); - } - ldapsvr_handle_other_attributes(ld, server, dn, contact); - /* If we do not make changes persistent at this point then changes - * will be lost if the user makes new search on the same server since - * changes are only present in Claws' internal cache. This issue has to - * be solved in addressbook.c since this involves access to structures - * which are only accessible in addressbook.c */ - clean_up(ld, server, contact); -} - -/** - * Delete contact from LDAP - * - * \param server AddressBook resource - * \param contact GHashTable with object to delete - */ -void ldapsvr_delete_contact(LdapServer *server, GHashTable *contact) { - LDAP *ld = NULL; - gchar *dn; - int rc; - - cm_return_if_fail(server != NULL || contact != NULL); - ld = ldapsvr_connect(server->control); - if (ld == NULL) { - clean_up(ld, server, contact); - return; - } - dn = g_hash_table_lookup(contact, "dn"); - if (dn == NULL) { - clean_up(ld, server, contact); - return; - } - server->retVal = LDAPRC_SUCCESS; - rc = ldap_delete_ext_s(ld, dn, NULL, NULL); - if (rc) { - log_error(LOG_PROTOCOL, _("LDAP error (modify): for DN '%s': %d (%s)\n"), - dn, rc, ldaputil_get_error(ld)); - server->retVal = LDAPRC_NODN; - } - clean_up(ld, server, contact); -} - -/** - * Update any changes to the server. - * - * \param server AddressBook resource. - * \param person ItemPerson holding user input. - */ -void ldapsvr_update_book(LdapServer *server, ItemPerson *item) { - GList *node = NULL; - GHashTable *contact = NULL; - GList *contacts = NULL, *head = NULL; - - cm_return_if_fail(server != NULL); - debug_print("updating ldap addressbook\n"); - - contact = g_hash_table_new(g_str_hash, g_str_equal); - if (item) { - gboolean result = ldapsvr_retrieve_item_person(item, contact); - debug_print("Found contact to update: %s\n", result? "Yes" : "No"); - if (result) { - if (debug_get_mode()) { - addritem_print_item_person(item, stdout); - } - contacts = g_list_append(contacts, contact); - } - } - else { - ItemFolder *folder = server->addressCache->rootFolder; - node = folder->listFolder; - if (node) { - while (node) { - AddrItemObject *aio = node->data; - if (aio) { - if (aio->type == ITEMTYPE_FOLDER) { - ItemFolder *folder = (ItemFolder *) aio; - GList *persons = folder->listPerson; - while (persons) { - AddrItemObject *aio = persons->data; - if (aio) { - if (aio->type == ITEMTYPE_PERSON) { - ItemPerson *item = (ItemPerson *) aio; - gboolean result = ldapsvr_retrieve_item_person(item, contact); - debug_print("Found contact to update: %s\n", result? "Yes" : "No"); - if (result) { - if (debug_get_mode()) { - gchar *uid = g_hash_table_lookup(contact, "uid"); - item = ldapsvr_get_contact(server, uid); - addritem_print_item_person(item, stdout); - } - contacts = g_list_append(contacts, contact); - } - } - } - persons = g_list_next(persons); - } - } - } - else { - g_printerr("\t\tpid : ???\n"); - } - node = g_list_next(node); - } - } - } - head = contacts; - if (debug_get_mode()) { - if (contacts) - debug_print("Contacts which must be updated in LDAP:\n"); - while (contacts) { - debug_print("\tContact:\n"); - g_hash_table_foreach(contacts->data, - ldapsvr_print_contacts_hashtable, stderr); - contacts = g_list_next(contacts); - } - } - if (contacts == NULL) - contacts = head; - while (contacts) { - gchar *status; - contact = (GHashTable *) contacts->data; - status = (gchar *) g_hash_table_lookup(contact, "status"); - if (status == NULL) - status = g_strdup("NULL"); - if (g_ascii_strcasecmp(status, "new") == 0) { - ldapsvr_add_contact(server, contact); - } - else if (g_ascii_strcasecmp(status, "update") == 0) { - ldapsvr_update_contact(server, contact); - } - else if (g_ascii_strcasecmp(status, "delete") == 0) { - ldapsvr_delete_contact(server, contact); - } - else - g_critical("ldapsvr_update_book->Unknown status: %s\n", status); - contacts = g_list_next(contacts); - } - ldapsvr_free_hashtable(head); -} - -#endif /* USE_LDAP */ - -/* - * End of Source. - */ - diff --git a/src/ldapupdate.h b/src/ldapupdate.h @@ -1,39 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2003-2012 Michael Rasmussen and the Claws Mail team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -/* - * Definitions necessary to update LDAP servers. - */ - -#ifndef __LDAPUPDATE_H__ -#define __LDAPUPDATE_H__ - -#ifdef USE_LDAP - -#include <glib.h> - -#include "ldapserver.h" - -/* Function proto types */ -void ldapsvr_update_book(LdapServer *server, ItemPerson *item); - -#endif /* USE_LDAP */ - -#endif /* __LDAPUPDATE_H__ */ - diff --git a/src/ldaputil.c b/src/ldaputil.c @@ -1,350 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2003-2018 Match Grun and the Claws Mail team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * Some utility functions to access LDAP servers. - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#include "claws-features.h" -#endif - -#ifdef USE_LDAP - -#include <glib.h> -#include <glib/gi18n.h> -#include <string.h> -#include <sys/time.h> -#include <errno.h> -#include "common/utils.h" -#include "ldaputil.h" -#include "ldapserver.h" -#include "ldapctrl.h" -#include "log.h" - -#define SYLDAP_TEST_FILTER "(objectclass=*)" -#define SYLDAP_SEARCHBASE_V2 "cn=config" -#define SYLDAP_SEARCHBASE_V3 "" -#define SYLDAP_V2_TEST_ATTR "database" -#define SYLDAP_V3_TEST_ATTR "namingcontexts" - -/** - * Attempt to discover the base DN for a server using LDAP version 3. - * \param ld LDAP handle for a connected server. - * \param tov Timeout value (seconds), or 0 for none, default 30 secs. - * \return List of Base DN's, or NULL if could not read. List should be - * g_free() when done. - */ -static GList *ldaputil_test_v3( LDAP *ld, gint tov, gint *errcode ) { - GList *baseDN = NULL; - gint rc, i; - LDAPMessage *result = NULL, *e; - gchar *attribs[2]; - BerElement *ber; - gchar *attribute; - struct berval **vals; - struct timeval timeout; - - /* Set timeout */ - timeout.tv_usec = 0L; - if( tov > 0 ) { - timeout.tv_sec = tov; - } - else { - timeout.tv_sec = 30L; - } - - /* Test for LDAP version 3 */ - attribs[0] = SYLDAP_V3_TEST_ATTR; - attribs[1] = NULL; - rc = ldap_search_ext_s( - ld, SYLDAP_SEARCHBASE_V3, LDAP_SCOPE_BASE, SYLDAP_TEST_FILTER, - attribs, 0, NULL, NULL, &timeout, 0, &result ); - - if( rc == LDAP_SUCCESS ) { - log_print(LOG_PROTOCOL, _("LDAP (search): successful\n")); - /* Process entries */ - for( e = ldap_first_entry( ld, result ); - e != NULL; - e = ldap_next_entry( ld, e ) ) - { - /* Process attributes */ - for( attribute = ldap_first_attribute( ld, e, &ber ); - attribute != NULL; - attribute = ldap_next_attribute( ld, e, ber ) ) - { - if( strcasecmp( - attribute, SYLDAP_V3_TEST_ATTR ) == 0 ) - { - vals = ldap_get_values_len( ld, e, attribute ); - if( vals != NULL ) { - for( i = 0; vals[i] != NULL; i++ ) { - baseDN = g_list_append( - baseDN, g_strndup( vals[i]->bv_val, vals[i]->bv_len ) ); - } - } - ldap_value_free_len( vals ); - } - ldap_memfree( attribute ); - } - if( ber != NULL ) { - ber_free( ber, 0 ); - } - ber = NULL; - } - } else { - log_error(LOG_PROTOCOL, _("LDAP error (search): %d (%s)\n"), - rc, ldaputil_get_error(ld)); - debug_print("LDAP: Error %d (%s)\n", rc, ldaputil_get_error(ld)); - } - - if (errcode) - *errcode = rc; - if (result) - ldap_msgfree( result ); - return baseDN; -} - -/** - * Attempt to discover the base DN for a server using LDAP version 2. - * \param ld LDAP handle for a connected server. - * \param tov Timeout value (seconds), or 0 for none, default 30 secs. - * \return List of Base DN's, or NULL if could not read. List should be - * g_free() when done. - */ -static GList *ldaputil_test_v2( LDAP *ld, gint tov ) { - GList *baseDN = NULL; - gint rc, i; - LDAPMessage *result = NULL, *e; - gchar *attribs[1]; - BerElement *ber; - gchar *attribute; - struct berval **vals; - struct timeval timeout; - - /* Set timeout */ - timeout.tv_usec = 0L; - if( tov > 0 ) { - timeout.tv_sec = tov; - } - else { - timeout.tv_sec = 30L; - } - - attribs[0] = NULL; - rc = ldap_search_ext_s( - ld, SYLDAP_SEARCHBASE_V2, LDAP_SCOPE_BASE, SYLDAP_TEST_FILTER, - attribs, 0, NULL, NULL, &timeout, 0, &result ); - - if( rc == LDAP_SUCCESS ) { - log_print(LOG_PROTOCOL, _("LDAP (search): successful\n")); - /* Process entries */ - for( e = ldap_first_entry( ld, result ); - e != NULL; - e = ldap_next_entry( ld, e ) ) - { - /* Process attributes */ - for( attribute = ldap_first_attribute( ld, e, &ber ); - attribute != NULL; - attribute = ldap_next_attribute( ld, e, ber ) ) - { - if( strcasecmp( - attribute, - SYLDAP_V2_TEST_ATTR ) == 0 ) { - vals = ldap_get_values_len( ld, e, attribute ); - if( vals != NULL ) { - for( i = 0; vals[i] != NULL; i++ ) { - char *ch, *tmp; - /* - * Strip the 'ldb:' from the - * front of the value. - */ - tmp = g_strndup( vals[i]->bv_val, vals[i]->bv_len); - ch = ( char * ) strchr( tmp, ':' ); - if( ch ) { - gchar *bn = g_strdup( ++ch ); - g_strstrip( bn ); - baseDN = g_list_append( - baseDN, g_strdup( bn ) ); - g_free( bn ); - } - g_free(tmp); - } - } - ldap_value_free_len( vals ); - } - ldap_memfree( attribute ); - } - if( ber != NULL ) { - ber_free( ber, 0 ); - } - ber = NULL; - } - } else { - log_error(LOG_PROTOCOL, _("LDAP error (search): %d (%s)\n"), - rc, ldaputil_get_error(ld)); - debug_print("LDAP: Error %d (%s)\n", rc, ldaputil_get_error(ld)); - } - if (result) - ldap_msgfree( result ); - return baseDN; -} - -int claws_ldap_simple_bind_s( LDAP *ld, LDAP_CONST char *dn, LDAP_CONST char *passwd ) -{ - debug_print("binding: DN->%s\n", dn?dn:"null"); -#ifdef G_OS_UNIX - struct berval cred; - - if ( passwd != NULL ) { - cred.bv_val = (char *) passwd; - cred.bv_len = strlen( passwd ); - } else { - cred.bv_val = ""; - cred.bv_len = 0; - } - - return ldap_sasl_bind_s( ld, dn, LDAP_SASL_SIMPLE, &cred, - NULL, NULL, NULL ); -#else - return ldap_simple_bind_s(ld, (PCHAR)dn, (PCHAR)passwd); -#endif -} - -/** - * Attempt to discover the base DN for the server. - * \param host Host name. - * \param port Port number. - * \param bindDN Bind DN (optional). - * \param bindPW Bind PW (optional). - * \param tov Timeout value (seconds), or 0 for none, default 30 secs. - * \return List of Base DN's, or NULL if could not read. This list should be - * g_free() when done. - */ -GList *ldaputil_read_basedn( - const gchar *host, const gint port, const gchar *bindDN, - const gchar *bindPW, const gint tov, int ssl, int tls ) -{ - GList *baseDN = NULL; - LDAP *ld = NULL; - LdapControl *ctl; - gint rc; - - if( host == NULL ) - return NULL; - if( port < 1 ) - return NULL; - - ctl = ldapctl_create(); - ldapctl_set_tls(ctl, tls); - ldapctl_set_ssl(ctl, ssl); - ldapctl_set_port(ctl, port); - ldapctl_set_host(ctl, host); - ldapctl_set_timeout(ctl, tov); - ldapctl_set_bind_dn(ctl, bindDN); - - ld = ldapsvr_connect(ctl); - if (ld == NULL) { - ldapctl_free(ctl); - return NULL; - } - baseDN = ldaputil_test_v3( ld, tov, &rc ); - if (baseDN) - debug_print("Using LDAP v3\n"); - -#ifdef G_OS_UNIX - if( baseDN == NULL && !LDAP_API_ERROR(rc) ) { -#else - if( baseDN == NULL) { -#endif - baseDN = ldaputil_test_v2( ld, tov ); - if (baseDN) - debug_print("Using LDAP v2\n"); - } - if (ld) - ldapsvr_disconnect(ld); - - ldapctl_free(ctl); - - return baseDN; -} - -/** - * Attempt to connect to the server. - * Enter: - * \param host Host name. - * \param port Port number. - * \return <i>TRUE</i> if connected successfully. - */ -gboolean ldaputil_test_connect( const gchar *host, const gint port, int ssl, int tls, int secs ) { - gboolean retVal = FALSE; - LdapControl *ctl = ldapctl_create(); - LDAP *ld; - - ldapctl_set_tls(ctl, tls); - ldapctl_set_ssl(ctl, ssl); - ldapctl_set_port(ctl, port); - ldapctl_set_host(ctl, host); - ldapctl_set_timeout(ctl, secs); - - ld = ldapsvr_connect(ctl); - if( ld != NULL ) { - ldapsvr_disconnect(ld); - debug_print("ld != NULL\n"); - retVal = TRUE; - } - ldapctl_free(ctl); - - return retVal; -} - -/** - * Test whether LDAP libraries installed. - * Return: TRUE if library available. - */ -gboolean ldaputil_test_ldap_lib( void ) { - return TRUE; -} - -const gchar *ldaputil_get_error(LDAP *ld) -{ - gchar *ld_error = NULL; - static gchar error[512]; - - ldap_get_option( ld, LDAP_OPT_ERROR_STRING, &ld_error); - if (ld_error != NULL) - strncpy2(error, ld_error, sizeof(error)); - else - strncpy2(error, _("Unknown error"), sizeof(error)); -#ifndef G_OS_WIN32 - /* From https://msdn.microsoft.com/en-us/library/aa366594%28v=vs.85%29.aspx - * "LDAP_OPT_ERROR_STRING returns a pointer to an internal static - * string table, and ldap_memfree should not be called when using - * this session option." - */ - ldap_memfree(ld_error); -#endif - - return error; -} -#endif /* USE_LDAP */ - -/* - * End of Source. -*/ diff --git a/src/ldaputil.h b/src/ldaputil.h @@ -1,59 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2003-2012 Match Grun and the Claws Mail team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -/* - * Some utility functions to access LDAP servers. - */ - -#ifndef __LDAPUTIL_H__ -#define __LDAPUTIL_H__ - -#ifdef USE_LDAP - -#include <glib.h> -#ifdef G_OS_UNIX -#include <ldap.h> -#include <lber.h> -#else -#include <windows.h> -#include <winldap.h> -#define LDAP_CONST const -#define ldap_unbind_ext(ld,x,y) ldap_unbind_s(ld) -#define LDAP_ADMINLIMIT_EXCEEDED LDAP_ADMIN_LIMIT_EXCEEDED -#define timeval l_timeval -#ifndef LDAP_OPT_SUCCESS -# define LDAP_OPT_SUCCESS 0 -#endif -#endif -/* Function Prototypes */ -GList *ldaputil_read_basedn ( const gchar *host, const gint port, - const gchar *bindDN, const gchar *bindPW, - const gint tov, int ssl, int tls ); -gboolean ldaputil_test_connect ( const gchar *host, const gint port, int ssl, int tls, int secs); -gboolean ldaputil_test_ldap_lib ( void ); -int claws_ldap_simple_bind_s( LDAP *ld, LDAP_CONST char *dn, LDAP_CONST char *passwd ); -const gchar *ldaputil_get_error(LDAP *ld); - -#endif /* USE_LDAP */ - -#endif /* __LDAPUTIL_H__ */ - -/* - * End of Source. - */ diff --git a/src/ldif.c b/src/ldif.c @@ -1,1002 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2001-2015 Match Grun and the Claws Mail team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * Functions necessary to access LDIF files (LDAP Data Interchange Format - * files). - */ - -#include "config.h" - -#include <glib.h> -#include <glib/gi18n.h> -#include <string.h> -#include <sys/stat.h> - -#include "mgutils.h" -#include "ldif.h" -#include "addritem.h" -#include "addrcache.h" - -#include "utils.h" -#include "file-utils.h" - -#define LDIF_SEP_TAG ':' -#define LDIF_LANG_TAG ';' - -/** - * Create new object. - * \return Initialized LDIF file object. - */ -LdifFile *ldif_create() { - LdifFile *ldifFile; - ldifFile = g_new0( LdifFile, 1 ); - ldifFile->path = NULL; - ldifFile->file = NULL; - ldifFile->hashFields = g_hash_table_new( g_str_hash, g_str_equal ); - ldifFile->tempList = NULL; - ldifFile->dirtyFlag = TRUE; - ldifFile->accessFlag = FALSE; - ldifFile->retVal = MGU_SUCCESS; - ldifFile->cbProgress = NULL; - ldifFile->importCount = 0; - return ldifFile; -} - -/** - * Specify full file specification of LDIF file. - * \param ldifFile LDIF import control object. - * \param value Value of access flag. - */ -void ldif_set_file( LdifFile *ldifFile, const gchar *value ) { - cm_return_if_fail( ldifFile != NULL ); - - if( ldifFile->path ) { - if( strcmp( ldifFile->path, value ) != 0 ) - ldifFile->dirtyFlag = TRUE; - } - else { - ldifFile->dirtyFlag = TRUE; - } - ldifFile->path = mgu_replace_string( ldifFile->path, value ); - g_strstrip( ldifFile->path ); - ldifFile->importCount = 0; -} - -/** - * Set the file access indicator. - * \param ldifFile LDIF import control object. - * \param value File specification. - */ -void ldif_set_accessed( LdifFile *ldifFile, const gboolean value ) { - cm_return_if_fail( ldifFile != NULL ); - ldifFile->accessFlag = value; -} - -/** - * Create field record object. - * \return Initialized LDIF field object. - */ -static Ldif_FieldRec *ldif_create_fieldrec( const gchar *field ) { - Ldif_FieldRec *rec = g_new0( Ldif_FieldRec, 1 ); - rec->tagName = g_strdup( field ); - rec->userName = NULL; - rec->reserved = FALSE; - rec->selected = FALSE; - return rec; -} - -/** - * Free field record object. - * \param rec LDIF field object. - */ -static void ldif_free_fieldrec( Ldif_FieldRec *rec ) { - if( rec ) { - g_free( rec->tagName ); - g_free( rec->userName ); - rec->tagName = NULL; - rec->userName = NULL; - rec->reserved = FALSE; - rec->selected = FALSE; - g_free( rec ); - } -} - -/** - * Set user name for field record. - * \param rec LDIF field object. - * \param value User name to set. Note that reserved fields cannot be - * named. - */ -void ldif_field_set_name( Ldif_FieldRec *rec, const gchar *value ) { - cm_return_if_fail( rec != NULL ); - - if( ! rec->reserved ) { - rec->userName = mgu_replace_string( rec->userName, value ); - g_strstrip( rec->userName ); - } -} - -/** - * Specify selection for field record. - * \param rec LDIF field object. - * \param value Set to <i>TRUE</i> to select field. Note that reserved - * fields cannot be unselected. - */ -void ldif_field_set_selected( Ldif_FieldRec *rec, const gboolean value ) { - cm_return_if_fail( rec != NULL ); - - if( ! rec->reserved ) { - rec->selected = value; - } -} - -/** - * Toggle selection for field record. Note that reserved fields cannot be - * toggled. - * \param rec LDIF field object. - */ -void ldif_field_toggle( Ldif_FieldRec *rec ) { - cm_return_if_fail( rec != NULL ); - - if( ! rec->reserved ) { - rec->selected = !rec->selected; - } -} - -/** - * Free hash table entry visitor function. - * \param key Key. - * \param value Value (the LDIF field record). - * \param data User data. - * \return <code>-1</code>. -*/ -static gint ldif_hash_free_vis( gpointer key, gpointer value, gpointer data ) { - ldif_free_fieldrec( ( Ldif_FieldRec * ) value ); - return -1; -} - -/** - * Free up object by releasing internal memory. - * \param ldifFile LDIF import control object. - */ -void ldif_free( LdifFile *ldifFile ) { - cm_return_if_fail( ldifFile != NULL ); - - /* Close file */ - if( ldifFile->file ) claws_fclose( ldifFile->file ); - - /* Free internal stuff */ - g_free( ldifFile->path ); - - /* Free field list */ - g_hash_table_foreach_remove( ldifFile->hashFields, ldif_hash_free_vis, NULL ); - g_hash_table_destroy( ldifFile->hashFields ); - ldifFile->hashFields = NULL; - - /* Clear pointers */ - ldifFile->file = NULL; - ldifFile->path = NULL; - ldifFile->retVal = MGU_SUCCESS; - ldifFile->tempList = NULL; - ldifFile->dirtyFlag = FALSE; - ldifFile->accessFlag = FALSE; - ldifFile->cbProgress = NULL; - - /* Now release file object */ - g_free( ldifFile ); -} - -/** - * Open file for read. - * \param ldifFile LDIF import control object. - * \return <i>TRUE</i> if file opened successfully. - */ -static gint ldif_open_file( LdifFile* ldifFile ) { - /* g_print( "Opening file\n" ); */ - if( ldifFile->path ) { - ldifFile->file = claws_fopen( ldifFile->path, "rb" ); - if( ! ldifFile->file ) { - /* g_print( "can't open %s\n", ldifFile->path ); */ - ldifFile->retVal = MGU_OPEN_FILE; - return ldifFile->retVal; - } - } - else { - /* g_print( "file not specified\n" ); */ - ldifFile->retVal = MGU_NO_FILE; - return ldifFile->retVal; - } - - /* Setup a buffer area */ - ldifFile->retVal = MGU_SUCCESS; - return ldifFile->retVal; -} - -/** - * Close file. - * \param ldifFile LDIF import control object. - */ -static void ldif_close_file( LdifFile *ldifFile ) { - cm_return_if_fail( ldifFile != NULL ); - if( ldifFile->file ) claws_fclose( ldifFile->file ); - ldifFile->file = NULL; -} - -/** - * Read line of text from file. - * \param ldifFile LDIF import control object. - * \return ptr to buffer where line starts (must be freed by caller). - */ -static gchar *ldif_get_line( LdifFile *ldifFile ) { - gchar *buf = g_malloc(LDIFBUFSIZE); - gint ch; - int i = 0; - int cur_alloc = LDIFBUFSIZE; - - if( claws_feof( ldifFile->file ) ) { - g_free(buf); - return NULL; - } - - while( i < cur_alloc-1 ) { - ch = fgetc( ldifFile->file ); - if (claws_ferror( ldifFile->file )) - ldifFile->retVal = MGU_ERROR_READ; - if( ch == '\0' || ch == EOF ) { - if( i == 0 ) { - g_free(buf); - return NULL; - } - break; - } -#if HAVE_DOSISH_SYSTEM -#else - if( ch == '\r' ) - continue; -#endif - if( ch == '\n' ) - break; - buf[i] = ch; - i++; - if (i == cur_alloc-1 && cur_alloc < LDIFBUFSIZE * 32) { - cur_alloc += LDIFBUFSIZE; - buf = g_realloc(buf, cur_alloc); - } - } - buf[i] = '\0'; - - return buf; -} - -/** - * Parse tag name from line buffer. - * \param line Buffer. - * \param flag64 Base-64 encoder flag. - * \return Buffer containing the tag name, or NULL if no delimiter char found. - * If a double delimiter (::) is found, flag64 is set. - */ -static gchar *ldif_get_tagname( char* line, gboolean *flag64 ) { - gint len = 0; - gchar *tag = NULL; - gchar *lptr = line; - gchar *sptr = NULL; - - while( *lptr++ ) { - /* Check for language tag */ - if( *lptr == LDIF_LANG_TAG ) { - if( sptr == NULL ) sptr = lptr; - } - - /* Check for delimiter */ - if( *lptr == LDIF_SEP_TAG ) { - if( sptr ) { - len = sptr - line; - } - else { - len = lptr - line; - } - - /* Base-64 encoding? */ - if( * ++lptr == LDIF_SEP_TAG ) *flag64 = TRUE; - - tag = g_strndup( line, len+1 ); - tag[ len ] = '\0'; - return tag; - } - } - return tag; -} - -/** - * Parse tag value from line buffer. - * \param line Buffer. - * \return Buffer containing the tag value. Empty string is returned if - * no delimiter char found. - */ -static gchar *ldif_get_tagvalue( gchar* line ) { - gchar *value = NULL; - gchar *start = NULL; - gchar *lptr; - gint len = 0; - - for( lptr = line; *lptr; lptr++ ) { - if( *lptr == LDIF_SEP_TAG ) { - if( ! start ) - start = lptr + 1; - } - } - if( start ) { - if( *start == LDIF_SEP_TAG ) start++; - len = lptr - start; - value = g_strndup( start, len+1 ); - g_strstrip( value ); - } - else { - /* Ensure that we get an empty string */ - value = g_strndup( "", 1 ); - } - value[ len ] = '\0'; - return value; -} - -/** - * Parsed address data record. - */ -typedef struct _Ldif_ParsedRec_ Ldif_ParsedRec; -struct _Ldif_ParsedRec_ { - GSList *listCName; - GSList *listFName; - GSList *listLName; - GSList *listNName; - GSList *listAddress; - GSList *listID; - GSList *userAttr; -}; - -/** - * User attribute data record. - */ -typedef struct _Ldif_UserAttr_ Ldif_UserAttr; -struct _Ldif_UserAttr_ { - gchar *name; - gchar *value; -}; - -/** - * Build an address list entry and append to list of address items in the - * address cache. Name is formatted as "<first-name> <last-name>". - * \param ldifFile LDIF import control object. - * \param rec LDIF field object. - * \param cache Address cache to be populated with data. - */ -static void ldif_build_items( - LdifFile *ldifFile, Ldif_ParsedRec *rec, AddressCache *cache ) -{ - GSList *nodeFirst; - GSList *nodeAddress; - GSList *nodeAttr; - gchar *firstName = NULL, *lastName = NULL, *fullName = NULL; - gchar *nickName = NULL; - gint iLen = 0, iLenT = 0; - ItemPerson *person; - ItemEMail *email; - - nodeAddress = rec->listAddress; -// if( nodeAddress == NULL ) return; - - /* Find longest first name in list */ - nodeFirst = rec->listFName; - while( nodeFirst ) { - if( firstName == NULL ) { - firstName = nodeFirst->data; - iLen = strlen( firstName ); - } - else { - if( ( iLenT = strlen( nodeFirst->data ) ) > iLen ) { - firstName = nodeFirst->data; - iLen = iLenT; - } - } - nodeFirst = g_slist_next( nodeFirst ); - } - - /* Format name */ - if( rec->listLName ) { - lastName = rec->listLName->data; - } - - if( firstName ) { - if( lastName ) { - fullName = g_strdup_printf( - "%s %s", firstName, lastName ); - } - else { - fullName = g_strdup_printf( "%s", firstName ); - } - } - else { - if( lastName ) { - fullName = g_strdup_printf( "%s", lastName ); - } - } - - if (!fullName || strlen(fullName) == 0) { - g_free(fullName); - fullName = NULL; - if (rec->listCName) - fullName = g_strdup(rec->listCName->data); - } - - if( fullName ) { - g_strstrip( fullName ); - } - - if( rec->listNName ) { - nickName = rec->listNName->data; - } - - person = addritem_create_item_person(); - addritem_person_set_common_name( person, fullName ); - addritem_person_set_first_name( person, firstName ); - addritem_person_set_last_name( person, lastName ); - addritem_person_set_nick_name( person, nickName ); - addrcache_id_person( cache, person ); - addrcache_add_person( cache, person ); - ++ldifFile->importCount; - - /* Add address item */ - while( nodeAddress ) { - email = addritem_create_item_email(); - addritem_email_set_address( email, nodeAddress->data ); - addrcache_id_email( cache, email ); - addrcache_person_add_email( cache, person, email ); - nodeAddress = g_slist_next( nodeAddress ); - } - g_free( fullName ); - fullName = firstName = lastName = NULL; - - /* Add user attributes */ - nodeAttr = rec->userAttr; - while( nodeAttr ) { - Ldif_UserAttr *attr = nodeAttr->data; - UserAttribute *attrib = addritem_create_attribute(); - addritem_attrib_set_name( attrib, attr->name ); - addritem_attrib_set_value( attrib, attr->value ); - addritem_person_add_attribute( person, attrib ); - nodeAttr = g_slist_next( nodeAttr ); - } - nodeAttr = NULL; -} - -/** - * Add selected field as user attribute. - * \param rec LDIF field object. - * \param tagName LDIF tag name. - * \param tagValue Data value. - * \param hashField Hash table to populate. - */ -static void ldif_add_user_attr( - Ldif_ParsedRec *rec, gchar *tagName, gchar *tagValue, - GHashTable *hashField ) -{ - Ldif_FieldRec *fld = NULL; - Ldif_UserAttr *attr = NULL; - gchar *name; - - fld = g_hash_table_lookup( hashField, tagName ); - if( fld ) { - if( ! fld->selected ) return; - - name = fld->tagName; - if( fld->userName ) { - name = fld->userName; - } - attr = g_new0( Ldif_UserAttr, 1 ); - attr->name = g_strdup( name ); - attr->value = g_strdup( tagValue ); - rec->userAttr = g_slist_append( rec->userAttr, attr ); - } -} - -/** - * Add value to parsed data. - * \param rec LDIF field object. - * \param tagName LDIF tag name. - * \param tagValue Data value. - * \param hashField Hash table to populate. - */ -static void ldif_add_value( - Ldif_ParsedRec *rec, gchar *tagName, gchar *tagValue, - GHashTable *hashField ) -{ - gchar *nm, *val; - - nm = g_utf8_strdown( tagName, -1 ); - if( tagValue ) { - val = g_strdup( tagValue ); - } - else { - val = g_strdup( "" ); - } - g_strstrip( val ); - - if( g_utf8_collate( nm, g_utf8_strdown( LDIF_TAG_COMMONNAME, -1 ) ) == 0 ) { - rec->listCName = g_slist_append( rec->listCName, val ); - } - else if( g_utf8_collate( nm, g_utf8_strdown( LDIF_TAG_FIRSTNAME, -1 ) ) == 0 ) { - rec->listFName = g_slist_append( rec->listFName, val ); - } - else if( g_utf8_collate( nm, g_utf8_strdown( LDIF_TAG_LASTNAME, -1 ) ) == 0 ) { - rec->listLName = g_slist_append( rec->listLName, val ); - } - else if( g_utf8_collate( nm, g_utf8_strdown( LDIF_TAG_NICKNAME, -1 ) ) == 0 ) { - rec->listNName = g_slist_append( rec->listNName, val ); - } - else if( g_utf8_collate( nm, g_utf8_strdown( LDIF_TAG_EMAIL, -1 ) ) == 0 ) { - rec->listAddress = g_slist_append( rec->listAddress, val ); - } - else { - /* Add field as user attribute */ - ldif_add_user_attr( rec, tagName, tagValue, hashField ); - } - g_free( nm ); -} - -/** - * Clear parsed data record. - * \param rec LDIF field object. - */ -static void ldif_clear_rec( Ldif_ParsedRec *rec ) { - GSList *list; - - /* Free up user attributes */ - list = rec->userAttr; - while( list ) { - Ldif_UserAttr *attr = list->data; - g_free( attr->name ); - g_free( attr->value ); - g_free( attr ); - list = g_slist_next( list ); - } - g_slist_free( rec->userAttr ); - - g_slist_free( rec->listCName ); - g_slist_free( rec->listFName ); - g_slist_free( rec->listLName ); - g_slist_free( rec->listNName ); - g_slist_free( rec->listAddress ); - g_slist_free( rec->listID ); - - rec->userAttr = NULL; - rec->listCName = NULL; - rec->listFName = NULL; - rec->listLName = NULL; - rec->listNName = NULL; - rec->listAddress = NULL; - rec->listID = NULL; -} - -/** - * Read file data into address cache. - * Note that one LDIF record identifies one entity uniquely with the - * distinguished name (dn) tag. Each person can have multiple E-Mail - * addresses. Also, each person can have many common name (cn) tags. - * - * \param ldifFile LDIF import control object. - * \param cache Address cache to be populated with data. - */ -static void ldif_read_file( LdifFile *ldifFile, AddressCache *cache ) { - gchar *tagName = NULL, *tagValue = NULL; - gchar *lastTag = NULL, *fullValue = NULL; - GSList *listValue = NULL; - gboolean flagEOF = FALSE, flagEOR = FALSE; - gboolean flag64 = FALSE, last64 = FALSE; - Ldif_ParsedRec *rec; - long posEnd = 0L; - long posCur = 0L; - GHashTable *hashField; - gsize len; - - hashField = ldifFile->hashFields; - rec = g_new0( Ldif_ParsedRec, 1 ); - ldif_clear_rec( rec ); - - /* Find EOF for progress indicator */ - fseek( ldifFile->file, 0L, SEEK_END ); - posEnd = ftell( ldifFile->file ); - fseek( ldifFile->file, 0L, SEEK_SET ); - - while( ! flagEOF ) { - gchar *line = ldif_get_line( ldifFile ); - - posCur = ftell( ldifFile->file ); - if( ldifFile->cbProgress ) { - /* Call progress indicator */ - ( ldifFile->cbProgress ) ( ldifFile, & posEnd, & posCur ); - } - - flag64 = FALSE; - if( line == NULL ) { - flagEOF = flagEOR = TRUE; - } - else if( *line == '\0' ) { - flagEOR = TRUE; - } - - if( flagEOR ) { - /* EOR, Output address data */ - if( lastTag ) { - /* Save record */ - fullValue = mgu_list_coalesce( listValue ); - if (fullValue && last64) { - gchar *tmp = g_base64_decode_zero(fullValue, &len); - g_free(fullValue); - fullValue = tmp; - } - - ldif_add_value( rec, lastTag, fullValue, hashField ); - /* ldif_print_record( rec, stdout ); */ - ldif_build_items( ldifFile, rec, cache ); - ldif_clear_rec( rec ); - g_free( lastTag ); - g_slist_free_full( listValue, g_free ); - g_free(fullValue); - lastTag = NULL; - listValue = NULL; - last64 = FALSE; - } - } - if( line ) { - flagEOR = FALSE; - if( *line == ' ' ) { - /* Continuation line */ - listValue = g_slist_append( - listValue, g_strdup( line+1 ) ); - } - else if( *line == '=' ) { - /* Base-64 encoded continuation field */ - listValue = g_slist_append( - listValue, g_strdup( line ) ); - } - else { - /* Parse line */ - tagName = ldif_get_tagname( line, &flag64 ); - if( tagName ) { - tagValue = ldif_get_tagvalue( line ); - if( tagValue ) { - if( lastTag ) { - /* Save data */ - fullValue = - mgu_list_coalesce( listValue ); - if (fullValue && last64) { - gchar *tmp = g_base64_decode_zero(fullValue, &len); - g_free(fullValue); - fullValue = tmp; - } - /* Base-64 encoded data */ - /* - if( last64 ) { - ldif_dump_b64( fullValue ); - } - */ - - ldif_add_value( - rec, lastTag, fullValue, - hashField ); - g_free( lastTag ); - g_slist_free_full( listValue, g_free ); - lastTag = NULL; - listValue = NULL; - } - - lastTag = g_strdup( tagName ); - listValue = g_slist_append( - listValue, - g_strdup( tagValue ) ); - g_free( tagValue ); - last64 = flag64; - } - g_free( tagName ); - } - } - g_free( line ); - } - } - - /* Release data */ - ldif_clear_rec( rec ); - g_free( rec ); - g_free( lastTag ); - g_slist_free_full( listValue, g_free ); -} - -/** - * Add list of field names to hash table. - * \param table Hashtable. - * \param list List of fields. - */ -static void ldif_hash_add_list( GHashTable *table, GSList *list ) { - GSList *node = list; - - /* mgu_print_list( list, stdout ); */ - while( node ) { - gchar *tag = node->data; - if( ! g_hash_table_lookup( table, tag ) ) { - Ldif_FieldRec *rec = NULL; - gchar *key = g_utf8_strdown( tag, -1 ); - - rec = ldif_create_fieldrec( tag ); - if( g_utf8_collate( key, LDIF_TAG_DN ) == 0 ) { - rec->reserved = rec->selected = TRUE; - rec->userName = g_strdup( "dn" ); - } - else if( g_utf8_collate( key, g_utf8_strdown( LDIF_TAG_COMMONNAME, -1 ) ) == 0 ) { - rec->reserved = rec->selected = TRUE; - rec->userName = g_strdup( _( "Display Name" ) ); - } - else if( g_utf8_collate( key, g_utf8_strdown( LDIF_TAG_FIRSTNAME, -1 ) ) == 0 ) { - rec->reserved = rec->selected = TRUE; - rec->userName = g_strdup( _( "First Name" ) ); - } - else if( g_utf8_collate( key, g_utf8_strdown( LDIF_TAG_LASTNAME, -1 ) ) == 0 ) { - rec->reserved = rec->selected = TRUE; - rec->userName = g_strdup( _( "Last Name" ) ); - } - else if( g_utf8_collate( key, g_utf8_strdown( LDIF_TAG_NICKNAME, -1 ) ) == 0 ) { - rec->reserved = rec->selected = TRUE; - rec->userName = g_strdup( _( "Nick Name" ) ); - } - else if( g_utf8_collate( key, g_utf8_strdown( LDIF_TAG_EMAIL, -1 ) ) == 0 ) { - rec->reserved = rec->selected = TRUE; - rec->userName = g_strdup( _( "Email Address" ) ); - } - g_hash_table_insert( table, key, rec ); - } - node = g_slist_next( node ); - } -} - -/** - * Sorted list comparison function. - * \param ptr1 First field. - * \param ptr2 Second field. - * \return <code>-1, 0, +1</code> if first record less than, equal, - * greater than second. - */ -static gint ldif_field_compare( gconstpointer ptr1, gconstpointer ptr2 ) { - const Ldif_FieldRec *rec1 = ptr1; - const Ldif_FieldRec *rec2 = ptr2; - - if( rec1->reserved ) { - if( ! rec2->reserved ) { - return +1; - } - } - else { - if( rec2->reserved ) { - return -1; - } - } - return g_utf8_collate( rec1->tagName, rec2->tagName ); -} - -/* - * Append hash table entry to list - visitor function. - * \param key Key. - * \param value Data value. - * \param data User data (the LDIF import control object). - */ -static void ldif_hash2list_vis( gpointer key, gpointer value, gpointer data ) { - LdifFile *ldf = data; - ldf->tempList = - g_list_insert_sorted( ldf->tempList, value, ldif_field_compare ); -} - -/** - * Read tag names for file data. - * \param ldifFile LDIF import control object. - */ -static void ldif_read_tag_list( LdifFile *ldifFile ) { - gchar *tagName = NULL; - GSList *listTags = NULL; - gboolean flagEOF = FALSE, flagEOR = FALSE, flagMail = FALSE; - gboolean flag64 = FALSE; - long posEnd = 0L; - long posCur = 0L; - - /* Clear hash table */ - g_hash_table_foreach_remove( - ldifFile->hashFields, ldif_hash_free_vis, NULL ); - - /* Find EOF for progress indicator */ - fseek( ldifFile->file, 0L, SEEK_END ); - posEnd = ftell( ldifFile->file ); - fseek( ldifFile->file, 0L, SEEK_SET ); - - if (posEnd == 0) { - ldifFile->retVal = MGU_EOF; - return; - } - - /* Process file */ - while( ! flagEOF ) { - gchar *line = ldif_get_line( ldifFile ); - posCur = ftell( ldifFile->file ); - if( ldifFile->cbProgress ) { - /* Call progress indicator */ - ( ldifFile->cbProgress ) ( ldifFile, & posEnd, & posCur ); - } - - flag64 = FALSE; - if( line == NULL ) { - flagEOF = flagEOR = TRUE; - } - else if( *line == '\0' ) { - flagEOR = TRUE; - } - - if( flagEOR ) { - /* EOR, Output address data */ - /* Save field list to hash table */ - if( flagMail ) { - ldif_hash_add_list( - ldifFile->hashFields, listTags ); - } - g_slist_free_full( listTags, g_free ); - listTags = NULL; - flagMail = FALSE; - } - if( line ) { - flagEOR = FALSE; - if( *line == ' ' ) { - /* Continuation line */ - } - else if( *line == '=' ) { - /* Base-64 encoded continuation field */ - } - else { - /* Parse line */ - tagName = ldif_get_tagname( line, &flag64 ); - if( tagName ) { - /* Add tag to list */ - listTags = g_slist_append( listTags, tagName ); - - if( g_utf8_collate( - tagName, LDIF_TAG_EMAIL ) == 0 ) - { - flagMail = TRUE; - } - } else { - g_strstrip(line); - if (*line != '\0') { - debug_print("ldif: bad format: '%s'\n", line); - ldifFile->retVal = MGU_BAD_FORMAT; - } - } - } - g_free( line ); - } - } - - /* Release data */ - g_slist_free_full( listTags, g_free ); - listTags = NULL; -} - -/** - * Read file into list. Main entry point - * \param ldifFile LDIF import control object. - * \param cache Address cache to load. - * \return Status code. - */ -gint ldif_import_data( LdifFile *ldifFile, AddressCache *cache ) { - cm_return_val_if_fail( ldifFile != NULL, MGU_BAD_ARGS ); - ldifFile->retVal = MGU_SUCCESS; - addrcache_clear( cache ); - cache->dataRead = FALSE; - ldif_open_file( ldifFile ); - if( ldifFile->retVal == MGU_SUCCESS ) { - /* Read data into the cache */ - ldif_read_file( ldifFile, cache ); - ldif_close_file( ldifFile ); - - /* Mark cache */ - cache->modified = FALSE; - cache->dataRead = TRUE; - } - return ldifFile->retVal; -} - -/** - * Process entire file reading list of unique fields. List of fields may be - * accessed with the <code>ldif_get_fieldlist()</code> function. - * \param ldifFile LDIF import control object. - * \return Status code. - */ -gint ldif_read_tags( LdifFile *ldifFile ) { - cm_return_val_if_fail( ldifFile != NULL, MGU_BAD_ARGS ); - ldifFile->retVal = MGU_SUCCESS; - if( ldifFile->dirtyFlag ) { - ldif_open_file( ldifFile ); - if( ldifFile->retVal == MGU_SUCCESS ) { - /* Read data into the cache */ - ldif_read_tag_list( ldifFile ); - ldif_close_file( ldifFile ); - ldifFile->dirtyFlag = FALSE; - ldifFile->accessFlag = TRUE; - } - } - return ldifFile->retVal; -} - -/** - * Return list of fields for LDIF file. - * \param ldifFile LDIF import control object. - * \return Linked list of <code>Ldif_FieldRec</code> objects. This list may be - * <code>g_free()</code>. Note that the objects in the list should not - * be freed since they refer to objects inside the internal cache. - * These objects will be freed when LDIF file object is freed. - */ -GList *ldif_get_fieldlist( LdifFile *ldifFile ) { - GList *list = NULL; - - cm_return_val_if_fail( ldifFile != NULL, NULL ); - if( ldifFile->hashFields ) { - ldifFile->tempList = NULL; - g_hash_table_foreach( ldifFile->hashFields, ldif_hash2list_vis, ldifFile ); - list = ldifFile->tempList; - ldifFile->tempList = NULL; - } - return list; -} - -/** - * Output LDIF name-value pair to stream. Only non-empty names and values will - * be output to file. - * \param stream File output stream. - * \param name Name. - * \param value Data value. - * \return <i>TRUE</i> if data output. - */ -gboolean ldif_write_value( FILE *stream, const gchar *name, const gchar *value ) { - if( name == NULL ) return FALSE; - if( value == NULL ) return FALSE; - if( strlen( name ) < 1 ) return FALSE; - if( strlen( value ) < 1 ) return FALSE; - fprintf( stream, "%s: ", name ); - fprintf( stream, "%s\n", value ); - return TRUE; -} - -/** - * Output LDIF End of Record to stream. - * \param stream File output stream. - * \return <i>TRUE</i> if data output. - */ -void ldif_write_eor( FILE *stream ) { - /* Simple but caller should not need to know how to end record. */ - fprintf( stream, "\n" ); -} - -/* - * ============================================================================ - * End of Source. - * ============================================================================ - */ - diff --git a/src/ldif.h b/src/ldif.h @@ -1,125 +0,0 @@ -/* - * Claws Mail -- a GTK based, lightweight, and fast e-mail client - * Copyright (C) 2001-2012 Match Grun and the Claws Mail team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -/* - * Definitions necessary to access LDIF files (LDAP Data Interchange Format - * files). These files are used to load LDAP servers and to interchange data - * between servers. They are also used by several E-Mail client programs and - * other programs as a means of interchange address book data. - */ - -#ifndef __LDIF_H__ -#define __LDIF_H__ - -#include <stdio.h> -#include <glib.h> - -#include "addrcache.h" - -#define LDIFBUFSIZE 2048 - -/* Common tag names - for address book import/export */ -#define LDIF_TAG_DN "dn" -#define LDIF_TAG_COMMONNAME "cn" -#define LDIF_TAG_FIRSTNAME "givenName" -#define LDIF_TAG_LASTNAME "sn" -#define LDIF_TAG_NICKNAME "displayName" -#define LDIF_TAG_EMAIL "mail" -#define LDIF_TAG_OBJECTCLASS "objectClass" - -/* Object classes */ -#define LDIF_CLASS_PERSON "person" -#define LDIF_CLASS_INET_PERSON "inetOrgPerson" - -/* -* Typical LDIF entry (similar to that generated by Netscape): -* -* dn: uid=axel, dc=axel, dc=com -* cn: Axel Rose -* sn: Rose -* givenname: Arnold -* xmozillanickname: Axel -* mail: axel@axelrose.com -* mail: axelrose@aol.com -* mail: axel@netscape.net -* mail: axel@hotmail.com -* uid: axelrose -* o: The Company -* locality: Denver -* st: CO -* streetaddress: 777 Lexington Avenue -* postalcode: 80298 -* countryname: USA -* telephonenumber: 303-555-1234 -* homephone: 303-555-2345 -* cellphone: 303-555-3456 -* homeurl: http://www.axelrose.com -* objectclass: top -* objectclass: person -* -* Note that first entry is always dn. An empty line defines end of -* record. Note that attribute names are case insensitive. There may -* also be several occurrences of an attribute, for example, as -* illustrated for "mail" and "objectclass" attributes. LDIF files -* can also use binary data using base-64 encoding. -* -*/ - -/* LDIF file object */ -typedef struct _LdifFile LdifFile; -struct _LdifFile { - FILE *file; - gchar *path; - gchar *bufptr; - gint retVal; - GHashTable *hashFields; - GList *tempList; - gboolean dirtyFlag; - gboolean accessFlag; - void (*cbProgress)( void *, void *, void * ); - gint importCount; -}; - -/* LDIF field record structure */ -typedef struct _Ldif_FieldRec_ Ldif_FieldRec; -struct _Ldif_FieldRec_ { - gchar *tagName; - gchar *userName; - gboolean reserved; - gboolean selected; -}; - -/* Function prototypes */ -LdifFile *ldif_create ( void ); -void ldif_set_file ( LdifFile* ldifFile, const gchar *value ); -void ldif_set_accessed ( LdifFile* ldifFile, const gboolean value ); -void ldif_field_set_name ( Ldif_FieldRec *rec, const gchar *value ); -void ldif_field_set_selected ( Ldif_FieldRec *rec, const gboolean value ); -void ldif_field_toggle ( Ldif_FieldRec *rec ); -void ldif_free ( LdifFile *ldifFile ); -void ldif_print_file ( LdifFile *ldifFile, FILE *stream ); -gint ldif_import_data ( LdifFile *ldifFile, AddressCache *cache ); -gint ldif_read_tags ( LdifFile *ldifFile ); -GList *ldif_get_fieldlist ( LdifFile *ldifFile ); -gboolean ldif_write_value ( FILE *stream, const gchar *name, - const gchar *value ); -void ldif_write_eor ( FILE *stream ); - -#endif /* __LDIF_H__ */ - diff --git a/src/main.c b/src/main.c @@ -176,7 +176,7 @@ static SnDisplay *sn_display = NULL; static gint lock_socket = -1; static gint lock_socket_tag = 0; -typedef enum +typedef enum { ONLINE_MODE_DONT_CHANGE, ONLINE_MODE_ONLINE, @@ -218,7 +218,7 @@ static struct RemoteCmd { SessionStats session_stats; static void reset_statistics(void); - + static void parse_cmd_opt(int argc, char *argv[]); static gint prohibit_duplicate_launch (int *argc, @@ -313,7 +313,7 @@ static void startup_notification_complete(gboolean with_window) } #endif /* HAVE_STARTUP_NOTIFICATION */ -static void claws_gtk_idle(void) +static void claws_gtk_idle(void) { while(gtk_events_pending()) { gtk_main_iteration(); @@ -362,7 +362,7 @@ static gboolean defer_jump(void *data) defer_check_all(GINT_TO_POINTER(TRUE)); } else if (cmd.receive) { defer_check(NULL); - } + } mainwindow_jump_to(data, FALSE); if (sc_starting) { sc_starting = FALSE; @@ -405,7 +405,7 @@ static gboolean migrate_old_config(const gchar *old_cfg_dir, const gchar *new_cf "cached IMAP or News data, and will take some extra " "room on your disk.")); - g_signal_connect(G_OBJECT(keep_backup_chk), "toggled", + g_signal_connect(G_OBJECT(keep_backup_chk), "toggled", G_CALLBACK(chk_update_val), &backup); if (alertpanel_full(_("Migration of configuration"), message, @@ -413,7 +413,7 @@ static gboolean migrate_old_config(const gchar *old_cfg_dir, const gchar *new_cf FALSE, keep_backup_chk, ALERT_QUESTION) != G_ALERTALTERNATE) { return FALSE; } - + /* we can either do a fast migration requiring not any extra disk * space, or a slow one that copies the old configuration and leaves * it in place. */ @@ -421,10 +421,10 @@ static gboolean migrate_old_config(const gchar *old_cfg_dir, const gchar *new_cf backup_mode: window = label_window_create(_("Copying configuration... This may take a while...")); GTK_EVENTS_FLUSH(); - + r = copy_dir(old_cfg_dir, new_cfg_dir); label_window_destroy(window); - + /* if copy failed, we'll remove the partially copied * new directory */ if (r != 0) { @@ -439,10 +439,10 @@ backup_mode: } else { window = label_window_create(_("Migrating configuration...")); GTK_EVENTS_FLUSH(); - + r = g_rename(old_cfg_dir, new_cfg_dir); label_window_destroy(window); - + /* if g_rename failed, we'll try to copy */ if (r != 0) { FILE_OP_ERROR(new_cfg_dir, "g_rename"); @@ -468,10 +468,10 @@ static int migrate_common_rc(const gchar *old_rc, const gchar *new_rc) claws_fclose(oldfp); return -1; } - + plugin_path = g_strdup(get_plugin_dir()); new_plugin_path = g_strdup(plugin_path); - + if (strstr(plugin_path, "/claws-mail/")) { gchar *end = g_strdup(strstr(plugin_path, "/claws-mail/")+strlen("/claws-mail/")); *(strstr(plugin_path, "/claws-mail/")) = '\0'; @@ -497,7 +497,7 @@ static int migrate_common_rc(const gchar *old_rc, const gchar *new_rc) claws_fclose(oldfp); if (claws_safe_fclose(newfp) == EOF) err = TRUE; - + return (err ? -1:0); } @@ -628,8 +628,8 @@ static void sc_session_manager_connect(MainWindow *mainwin) sc_ice_installed_handler = NULL; IceAddConnectionWatch (new_ice_connection, NULL); - - + + callbacks.save_yourself.callback = sc_save_yourself_callback; callbacks.die.callback = sc_die_callback; callbacks.save_complete.callback = sc_save_complete_callback; @@ -838,7 +838,7 @@ static void win32_close_log(void) CloseHandle(win32_debug_log); win32_debug_log = NULL; } -} +} #endif static void main_dump_features_list(gboolean show_debug_only) @@ -863,7 +863,7 @@ static void main_dump_features_list(gboolean show_debug_only) g_print("buildtime GTK %d.%d.%d / GLib %d.%d.%d\n", GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION, GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION); - + if (show_debug_only) debug_print("Compiled-in features:\n"); else @@ -898,18 +898,6 @@ static void main_dump_features_list(gboolean show_debug_only) else g_print(" iconv\n"); #endif -#if USE_JPILOT - if (show_debug_only) - debug_print(" JPilot\n"); - else - g_print(" JPilot\n"); -#endif -#if USE_LDAP - if (show_debug_only) - debug_print(" LDAP\n"); - else - g_print(" LDAP\n"); -#endif #if HAVE_LIBETPAN if (show_debug_only) debug_print(" libetpan %d.%d\n", LIBETPAN_VERSION_MAJOR, LIBETPAN_VERSION_MINOR); @@ -1023,19 +1011,19 @@ int main(int argc, char *argv[]) install_basic_sighandlers(); if (cmd.status || cmd.status_full || cmd.search || - cmd.statistics || cmd.reset_statistics || + cmd.statistics || cmd.reset_statistics || cmd.cancel_receiving || cmd.cancel_sending || cmd.debug) { puts("0 Claws Mail not running."); lock_socket_remove(); return 0; } - + if (cmd.exit) return 0; reset_statistics(); - + gtk_init(&argc, &argv); #ifdef HAVE_NETWORKMANAGER_SUPPORT @@ -1076,13 +1064,13 @@ int main(int argc, char *argv[]) #else CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), 1); #endif - + /* no config dir exists. See if we can migrate an old config. */ if (!is_dir_exist(get_rc_dir())) { prefs_destroy_cache(); gboolean r = FALSE; - - /* if one of the old dirs exist, we'll ask if the user + + /* if one of the old dirs exist, we'll ask if the user * want to migrates, and r will be TRUE if he said yes * and migration succeeded, and FALSE otherwise. */ @@ -1102,9 +1090,9 @@ int main(int argc, char *argv[]) r = migrate_old_config(SYLPHEED_RC_DIR, get_rc_dir(), "Sylpheed"); asked_for_migration = TRUE; } - + /* If migration failed or the user didn't want to do it, - * we create a new one (and we'll hit wizard later). + * we create a new one (and we'll hit wizard later). */ if (r == FALSE && !is_dir_exist(get_rc_dir())) { #ifdef G_OS_UNIX @@ -1121,7 +1109,7 @@ int main(int argc, char *argv[]) #endif } } - + if (!is_file_exist(RC_DIR G_DIR_SEPARATOR_S COMMON_RC) && is_file_exist(RC_DIR G_DIR_SEPARATOR_S OLD_COMMON_RC)) { @@ -1299,7 +1287,7 @@ int main(int argc, char *argv[]) imap_main_init(prefs_common.skip_ssl_cert_check); imap_main_set_timeout(prefs_common.io_timeout_secs); nntp_main_init(prefs_common.skip_ssl_cert_check); -#endif +#endif /* If we can't read a folder list or don't have accounts, * it means the configuration's not done. Either this is * a brand new install, a failed/refused migration, @@ -1308,7 +1296,7 @@ int main(int argc, char *argv[]) if ((ret = folder_read_list()) < 0) { debug_print("Folderlist read failed (%d)\n", ret); prefs_destroy_cache(); - + if (ret == -2) { /* config_version update failed in folder_read_list(). We * do not want to run the wizard, just exit. */ @@ -1354,7 +1342,7 @@ int main(int argc, char *argv[]) never_ran = TRUE; } - + toolbar_main_set_sensitive(mainwin); main_window_set_menu_sensitive(mainwin); @@ -1425,7 +1413,7 @@ int main(int argc, char *argv[]) debug_print("new folders loaded, reloading processing rules\n"); prefs_matcher_read_config(); } - + if ((plug_list = plugin_get_unloaded_list()) != NULL) { GSList *cur; gchar *list = NULL; @@ -1448,8 +1436,8 @@ int main(int argc, char *argv[]) "for more information:\n%s", "The following plugins failed to load. " "Check the Plugins configuration " - "for more information:\n%s", - num_plugins), + "for more information:\n%s", + num_plugins), list); main_window_cursor_wait(mainwin); g_free(list); @@ -1500,7 +1488,7 @@ int main(int argc, char *argv[]) exit(1); } } - + static_mainwindow = mainwin; #ifdef HAVE_STARTUP_NOTIFICATION @@ -1557,14 +1545,14 @@ int main(int argc, char *argv[]) if (cmd.send) { send_queue(); } - + if (cmd.target) { start_done = FALSE; g_timeout_add(500, defer_jump, (gpointer)cmd.target); } prefs_destroy_cache(); - + compose_reopen_exit_drafts(); if (start_done) { @@ -1662,7 +1650,7 @@ static void exit_claws(MainWindow *mainwin) close_log_file(LOG_DEBUG_FILTERING); #ifdef HAVE_NETWORKMANAGER_SUPPORT - have_connectivity = networkmanager_is_online(NULL); + have_connectivity = networkmanager_is_online(NULL); #else have_connectivity = TRUE; #endif @@ -1683,7 +1671,7 @@ static void exit_claws(MainWindow *mainwin) #endif main_window_destroy_all(); - + plugin_unload_all("GTK3"); matcher_done(); @@ -1710,7 +1698,7 @@ static void exit_claws(MainWindow *mainwin) prefs_logging_done(); prefs_send_done(); tags_write_tags(); -#ifdef USE_ENCHANT +#ifdef USE_ENCHANT prefs_spelling_done(); gtkaspell_checkers_quit(); #endif @@ -1749,7 +1737,7 @@ static void parse_cmd_compose_from_file(const gchar *fn, GString *body) } while (claws_fgets(fb, sizeof(fb), fp)) { - gchar *tmp; + gchar *tmp; strretchomp(fb); if (*fb == '\0') break; @@ -1854,7 +1842,7 @@ static void parse_cmd_opt(int argc, char *argv[]) } else { parse_cmd_opt_error(_("Missing uri argument for option %s"), argv[i]); } - } else if (!strcmp(argv[i], "--attach") || + } else if (!strcmp(argv[i], "--attach") || !strcmp(argv[i], "--insert")) { if (i+1 < argc) { const gchar *p = argv[i+1]; @@ -1905,7 +1893,7 @@ static void parse_cmd_opt(int argc, char *argv[]) exit(0); } else if (!strcmp(argv[i], "--status-full")) { const gchar *p = (i+1 < argc)?argv[i+1]:NULL; - + cmd.status_full = TRUE; while (p && *p != '\0' && *p != '-') { if (!cmd.status_full_folders) { @@ -1919,7 +1907,7 @@ static void parse_cmd_opt(int argc, char *argv[]) } } else if (!strcmp(argv[i], "--status")) { const gchar *p = (i+1 < argc)?argv[i+1]:NULL; - + cmd.status = TRUE; while (p && *p != '\0' && *p != '-') { if (!cmd.status_folders) @@ -2008,7 +1996,7 @@ static void parse_cmd_opt(int argc, char *argv[]) " show the status of each folder")); g_print("%s\n", _(" --statistics show session statistics")); g_print("%s\n", _(" --reset-statistics reset session statistics")); - g_print("%s\n", _(" --select folder[/msg] jump to the specified folder/message\n" + g_print("%s\n", _(" --select folder[/msg] jump to the specified folder/message\n" " folder is a folder id like 'folder/subfolder', a file:// uri or an absolute path")); g_print("%s\n", _(" --import-mbox file import the specified mbox file\n")); g_print("%s\n", _(" --online switch to online mode")); @@ -2117,9 +2105,9 @@ static void initial_processing(FolderItem *item, gpointer data) gchar *buf; cm_return_if_fail(item); - buf = g_strdup_printf(_("Processing (%s)..."), - item->path - ? item->path + buf = g_strdup_printf(_("Processing (%s)..."), + item->path + ? item->path : _("top level folder")); g_free(buf); @@ -2135,7 +2123,7 @@ static void initial_processing(FolderItem *item, gpointer data) static gboolean draft_all_messages(void) { const GList *compose_list = NULL; - + compose_clear_exit_drafts(); compose_list = compose_get_compose_list(); while (compose_list != NULL) { @@ -2155,13 +2143,13 @@ gboolean clean_quit(gpointer data) } firstrun = FALSE; - /*!< Good idea to have the main window stored in a + /*!< Good idea to have the main window stored in a * static variable so we can check that variable * to see if we're really allowed to do things - * that actually the spawner is supposed to + * that actually the spawner is supposed to * do (like: sending mail, composing messages). * Because, really, if we're the spawnee, and - * we touch GTK stuff, we're hosed. See the + * we touch GTK stuff, we're hosed. See the * next fixme. */ /* FIXME: Use something else to signal that we're @@ -2170,7 +2158,7 @@ gboolean clean_quit(gpointer data) if (!static_mainwindow) { return FALSE; } - + draft_all_messages(); emergency_exit = TRUE; exit_claws(static_mainwindow); @@ -2182,7 +2170,7 @@ gboolean clean_quit(gpointer data) void app_will_exit(GtkWidget *widget, gpointer data) { MainWindow *mainwin = data; - + if (gtk_main_level() == 0) { debug_print("not even started\n"); return; @@ -2430,11 +2418,11 @@ static gint prohibit_duplicate_launch(int *argc, char ***argv) const gchar *command; GPtrArray *folders; gchar *folder; - + command = cmd.status_full ? "status-full\n" : "status\n"; folders = cmd.status_full ? cmd.status_full_folders : cmd.status_folders; - + CM_FD_WRITE_ALL(command); for (i = 0; folders && i < folders->len; ++i) { folder = g_ptr_array_index(folders, i); @@ -2630,7 +2618,7 @@ static void lock_socket_input_cb(gpointer data, files = g_list_append(files, ainfo); } open_compose_new(mailto, files); - + curr = g_list_first(files); while (curr != NULL) { ainfo = (AttachInfo *)curr->data; @@ -2657,7 +2645,7 @@ static void lock_socket_input_cb(gpointer data, !STRNCMP(buf, "status")) { gchar *status; GPtrArray *folders; - + folders = get_folder_item_list(sock); status = folder_get_status (folders, !STRNCMP(buf, "status-full")); @@ -2739,13 +2727,13 @@ static void lock_socket_input_cb(gpointer data, AdvancedSearch *search; gboolean recursive; AdvancedSearchType searchType = ADVANCED_SEARCH_EXTENDED; - + search = advsearch_new(); folder_name = g_strdup(buf+7); strretchomp(folder_name); - if (fd_gets(sock, buf, sizeof(buf) - 1) <= 0) + if (fd_gets(sock, buf, sizeof(buf) - 1) <= 0) goto search_exit; buf[sizeof(buf) - 1] = '\0'; @@ -2758,7 +2746,7 @@ static void lock_socket_input_cb(gpointer data, case 'E': searchType = ADVANCED_SEARCH_EXTENDED; break; } - if (fd_gets(sock, buf, sizeof(buf) - 1) <= 0) + if (fd_gets(sock, buf, sizeof(buf) - 1) <= 0) goto search_exit; buf[sizeof(buf) - 1] = '\0'; @@ -2847,7 +2835,7 @@ static void send_queue(void) if (res) { folder_item_scan(folder->queue); } - + if (res < 0) error = TRUE; } @@ -2898,10 +2886,10 @@ static void install_basic_sighandlers() #endif #ifdef SIGINT sigaction(SIGINT, &act, 0); -#endif +#endif #ifdef SIGHUP sigaction(SIGHUP, &act, 0); -#endif +#endif sigprocmask(SIG_UNBLOCK, &mask, 0); #endif /* !G_OS_WIN32 */ @@ -2918,7 +2906,7 @@ static void networkmanager_state_change_cb(DBusGProxy *proxy, gchar *dev, mainWin = static_mainwindow; else if (data) mainWin = (MainWindow*)data; - + if (!prefs_common.use_networkmanager) return; diff --git a/src/pixmaps/jpilot.xpm b/src/pixmaps/jpilot.xpm @@ -1,181 +0,0 @@ -/* XPM */ -static char * jpilot_xpm[] = { -"16 16 162 2", -" c None", -". c #030303", -"+ c #020202", -"@ c #454545", -"# c #BEBEBE", -"$ c #B3B3B3", -"% c #B1B1B1", -"& c #AFAFAF", -"* c #ADACAD", -"= c #AAAAAA", -"- c #A6A6A6", -"; c #A2A2A2", -"> c #999999", -", c #3D3D3D", -"' c #F2F2F2", -") c #969996", -"! c #7A807A", -"~ c #7C817C", -"{ c #777D77", -"] c #757B75", -"^ c #707570", -"/ c #8D8F8D", -"( c #B2B2B2", -"_ c #252525", -": c #3F3E3F", -"< c #DBDCDB", -"[ c #2A442A", -"} c #498749", -"| c #4D864D", -"1 c #4C864C", -"2 c #4B854B", -"3 c #498448", -"4 c #3E573E", -"5 c #9D9E9D", -"6 c #262626", -"7 c #3E3E3E", -"8 c #D7D9D7", -"9 c #324F32", -"0 c #7EBE7E", -"a c #88C189", -"b c #84BF84", -"c c #7EBC7E", -"d c #7ABB7A", -"e c #74BB74", -"f c #436343", -"g c #999B99", -"h c #262526", -"i c #D5D7D5", -"j c #304E30", -"k c #77B877", -"l c #7EBA7F", -"m c #73B273", -"n c #65AB65", -"o c #5FAA5F", -"p c #5FAE5F", -"q c #416241", -"r c #979997", -"s c #3C3C3C", -"t c #D1D3D1", -"u c #314E31", -"v c #71B571", -"w c #68AE68", -"x c #5AA45A", -"y c #51A051", -"z c #499F49", -"A c #4FA74F", -"B c #3E613F", -"C c #949694", -"D c #3B3B3B", -"E c #CCCECC", -"F c #2F4D2F", -"G c #61AD62", -"H c #50A250", -"I c #4B9F4A", -"J c #4DA14D", -"K c #479E47", -"L c #4EA74E", -"M c #3F6140", -"N c #929492", -"O c #252425", -"P c #3A3A3A", -"Q c #C8C9C8", -"R c #2B4B2B", -"S c #50A551", -"T c #499F4A", -"U c #4B9F4B", -"V c #4CA04C", -"W c #489E48", -"X c #52A852", -"Y c #8F918F", -"Z c #242424", -"` c #383838", -" . c #C2C4C2", -".. c #2A4B2A", -"+. c #4FA54F", -"@. c #4CA14C", -"#. c #4BA04B", -"$. c #58AC58", -"%. c #8C8E8C", -"&. c #373737", -"*. c #BCBEBC", -"=. c #55A955", -"-. c #52A652", -";. c #52A552", -">. c #51A551", -",. c #5EB15E", -"'. c #456445", -"). c #8A8C8A", -"!. c #242324", -"~. c #353535", -"{. c #B5B6B5", -"]. c #2A462A", -"^. c #59A059", -"/. c #5C9F5C", -"(. c #5B9F5B", -"_. c #65A965", -":. c #486248", -"<. c #898A89", -"[. c #232323", -"}. c #333333", -"|. c #BCBDBC", -"1. c #656A65", -"2. c #566056", -"3. c #565F56", -"4. c #535C53", -"5. c #535C52", -"6. c #545C50", -"7. c #50584D", -"8. c #707470", -"9. c #929292", -"0. c #2F2F2F", -"a. c #C2C2C2", -"b. c #A9A9A9", -"c. c #A6A5A6", -"d. c #9E9D9E", -"e. c #999797", -"f. c #7F8996", -"g. c #627A96", -"h. c #6D8095", -"i. c #909397", -"j. c #989898", -"k. c #202020", -"l. c #303030", -"m. c #545454", -"n. c #717171", -"o. c #727272", -"p. c #6D6D6D", -"q. c #696969", -"r. c #666768", -"s. c #636567", -"t. c #626465", -"u. c #5D5E5E", -"v. c #404040", -"w. c #4D4D4D", -"x. c #595959", -"y. c #5B5B5B", -"z. c #5A5A5A", -"A. c #565656", -"B. c #525252", -"C. c #515151", -"D. c #4A4A4A", -"E. c #393939", -" . . . . . . . . . + ", -" @ # $ % & * = - ; ; > , ", -" , ' ) ! ~ ! { ] ^ / ( _ ", -" : < [ } | 1 2 2 3 4 5 6 ", -" 7 8 9 0 a b c d e f g h ", -" 7 i j k l m n o p q r _ ", -" s t u v w x y z A B C _ ", -" D E F G H I J K L M N O ", -" P Q R S T U V W X q Y Z ", -" ` ...+.@.@.@.#.$.f %.Z ", -" &.*...=.-.;.;.>.,.'.).!. ", -" ~.{.].^./././.(._.:.<.[. ", -" }.|.1.2.3.4.5.6.7.8.9.[. ", -" 0.a.b.c.d.e.f.g.h.i.j.k. ", -" l.m.n.o.p.q.r.s.t.u.v.~. ", -" v.w.x.y.z.A.B.C.D.E. "}; diff --git a/src/pixmaps/ldap.xpm b/src/pixmaps/ldap.xpm @@ -1,82 +0,0 @@ -/* XPM */ -static char * ldap_xpm[] = { -"16 16 63 1", -" c None", -". c #000000", -"+ c #BDBDBD", -"@ c #FFFFFF", -"# c #A3A3A3", -"$ c #F8F8F8", -"% c #C9B49B", -"& c #8E7151", -"* c #876E51", -"= c #BAB1A5", -"- c #FCFCFC", -"; c #FBFBFB", -"> c #EAE8E3", -", c #F3F3F3", -"' c #A88D6E", -") c #DFD0BF", -"! c #5E432B", -"~ c #7E6C5B", -"{ c #313131", -"] c #575757", -"^ c #555555", -"/ c #EEDFCC", -"( c #F4EEE6", -"_ c #765E45", -": c #736251", -"< c #7590AE", -"[ c #C1665A", -"} c #445B71", -"| c #D7D6D3", -"1 c #ADADAD", -"2 c #9B9B9B", -"3 c #4C6A85", -"4 c #9DB8D2", -"5 c #486481", -"6 c #314E6C", -"7 c #667A8D", -"8 c #5E7B96", -"9 c #3B556D", -"0 c #344A60", -"a c #999999", -"b c #EDEDED", -"c c #C7C7C7", -"d c #5D5D5D", -"e c #787878", -"f c #E0DDD6", -"g c #CECECE", -"h c #1A1A1A", -"i c #918E85", -"j c #828282", -"k c #383838", -"l c #D6D6D6", -"m c #858585", -"n c #414141", -"o c #888888", -"p c #8E8E8E", -"q c #161616", -"r c #191919", -"s c #202020", -"t c #C9C9C9", -"u c #A9A9A9", -"v c #070707", -"w c #151515", -"x c #242424", -" .............. ", -".+@@@@@@@@@@@@#.", -".@$%&*=@-@;@@@>.", -".@,')!~@{]-^-@>.", -".@,/(_:@@@@@@@>.", -".@;<[}|@1@21@@>.", -".@34567@@@@@@@>.", -".@88390@a2bc@@>.", -".@@@@@@--@@@@@>.", -".@@d@d@e$2@c@@f.", -".#>>>>>gh>>>>fi.", -" ......jh...... ", -" hh ", -" jjjjjklmnopjjjj", -"qrrrrstupjvshqqw", -" xwwx "}; diff --git a/src/prefs_toolbar.c b/src/prefs_toolbar.c @@ -87,8 +87,6 @@ static const gint ToolbarIcons[] = STOCK_PIXMAP_GROUP, STOCK_PIXMAP_INSERT_FILE, STOCK_PIXMAP_INTERFACE, - STOCK_PIXMAP_JPILOT, - STOCK_PIXMAP_LDAP, STOCK_PIXMAP_LINEWRAP_CURRENT, STOCK_PIXMAP_LINEWRAP_ALL, STOCK_PIXMAP_MAIL_DRAFT, diff --git a/src/stock_pixmap.c b/src/stock_pixmap.c @@ -54,10 +54,8 @@ #include "pixmaps/group.xpm" #include "pixmaps/insert_file.xpm" #include "pixmaps/interface.xpm" -#include "pixmaps/jpilot.xpm" #include "pixmaps/key.xpm" #include "pixmaps/key_gpg_signed.xpm" -#include "pixmaps/ldap.xpm" #include "pixmaps/linewrap.xpm" #include "pixmaps/linewrapcurrent.xpm" #include "pixmaps/mark.xpm" @@ -336,10 +334,8 @@ static StockPixmapData pixmaps[] = {inbox_open_hrm_mark_xpm , NULL, NULL, "inbox_open_hrm_mark", NULL, NULL}, {insert_file_xpm , NULL, NULL, "insert_file", NULL, NULL}, {interface_xpm , NULL, NULL, "interface", NULL, NULL}, - {jpilot_xpm , NULL, NULL, "jpilot", NULL, NULL}, {key_xpm , NULL, NULL, "key", NULL, NULL}, {key_gpg_signed_xpm , NULL, NULL, "key_gpg_signed", NULL, NULL}, - {ldap_xpm , NULL, NULL, "ldap", NULL, NULL}, {linewrapcurrent_xpm , NULL, NULL, "linewrapcurrent", NULL, NULL}, {linewrap_xpm , NULL, NULL, "linewrap", NULL, NULL}, {locked_xpm , NULL, NULL, "locked", NULL, NULL}, diff --git a/src/stock_pixmap.h b/src/stock_pixmap.h @@ -77,10 +77,8 @@ typedef enum STOCK_PIXMAP_INBOX_OPEN_HRM_MARK, STOCK_PIXMAP_INSERT_FILE, STOCK_PIXMAP_INTERFACE, - STOCK_PIXMAP_JPILOT, STOCK_PIXMAP_KEY, STOCK_PIXMAP_KEY_SIGN, - STOCK_PIXMAP_LDAP, STOCK_PIXMAP_LINEWRAP_CURRENT, STOCK_PIXMAP_LINEWRAP_ALL, STOCK_PIXMAP_LOCKED, @@ -178,12 +176,12 @@ typedef enum STOCK_PIXMAP_CANCEL, STOCK_PIXMAP_TRASH, STOCK_PIXMAP_MAIL_COMPOSE_LOGO, - STOCK_PIXMAP_DIR_NOSELECT_CLOSE, - STOCK_PIXMAP_DIR_NOSELECT_CLOSE_MARK, - STOCK_PIXMAP_DIR_NOSELECT_OPEN, - STOCK_PIXMAP_DIR_SUBS_CLOSE_MARK, - STOCK_PIXMAP_DIR_SUBS_CLOSE, - STOCK_PIXMAP_DIR_SUBS_OPEN, + STOCK_PIXMAP_DIR_NOSELECT_CLOSE, + STOCK_PIXMAP_DIR_NOSELECT_CLOSE_MARK, + STOCK_PIXMAP_DIR_NOSELECT_OPEN, + STOCK_PIXMAP_DIR_SUBS_CLOSE_MARK, + STOCK_PIXMAP_DIR_SUBS_CLOSE, + STOCK_PIXMAP_DIR_SUBS_OPEN, STOCK_PIXMAP_SPAM, STOCK_PIXMAP_SPAM_BTN, STOCK_PIXMAP_HAM_BTN,