/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2001-2006 Match Grun and the Sylpheed-Claws team
+ * Copyright (C) 2001-2007 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 2 of the License, or
+ * 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,
* 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, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
*/
/*
#include "addritem.h"
#include "addrcache.h"
#include "addrbook.h"
+#include "addressbook.h"
#include "addrindex.h"
#include "xml.h"
#include "addrquery.h"
#include "addr_compl.h"
#include "utils.h"
+#include "alertpanel.h"
#ifndef DEV_STANDALONE
#include "prefs_gtk.h"
#include "ldapserver.h"
#include "ldapctrl.h"
#include "ldapquery.h"
+#include "ldapupdate.h"
#include "ldaputil.h"
#endif
#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"
gchar *value;
};
+static AddressDataSource *addrindex_create_datasource ( AddressIfType ifType );
+
+static GList *addrindex_ds_get_all_persons ( AddressDataSource *ds );
+static GList *addrindex_ds_get_all_groups ( AddressDataSource *ds );
+static AddressDataSource *addrindex_get_datasource ( AddressIndex *addrIndex,
+ const gchar *cacheID );
+static AddressInterface *addrindex_get_interface ( AddressIndex *addrIndex,
+ AddressIfType ifType );
+static gint addrindex_write_to ( AddressIndex *addrIndex,
+ const gchar *newFile );
+
/*
* Define DOM fragment.
*/
iface->getListFolder = ( void * ) addrbook_get_list_folder;
iface->getListPerson = ( void * ) addrbook_get_list_person;
iface->getAllPersons = ( void * ) addrbook_get_all_persons;
+ iface->getAllGroups = ( void * ) addrbook_get_all_groups;
iface->getName = ( void * ) addrbook_get_name;
iface->setAccessFlag = ( void * ) addrbook_set_accessed;
iface->searchOrder = 0;
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->getModifyFlag = ( void * ) ldapsvr_get_modified;
iface->getAccessFlag = ( void * ) ldapsvr_get_accessed;
- /* iface->getReadFlag = ( void * ) ldapsvr_get_read_flag; */
+ iface->getReadFlag = ( void * ) ldapsvr_get_read_flag;
iface->getStatusCode = ( void * ) ldapsvr_get_status;
- /* iface->getReadData = ( void * ) ldapsvr_read_data; */
+ 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;
* \param cacheID ID.
* \return Data source, or NULL if not found.
*/
-AddressDataSource *addrindex_get_datasource(
+static AddressDataSource *addrindex_get_datasource(
AddressIndex *addrIndex, const gchar *cacheID )
{
g_return_val_if_fail( addrIndex != NULL, NULL );
return _addressIndex_;
}
-/**
- * Return reference to address index.
- * \return Address index object.
- */
-AddressIndex *addrindex_get_object( void ) {
- return _addressIndex_;
-}
-
/**
* Property - Specify file path to address index file.
* \param addrIndex Address index.
addrIndex->fileName = mgu_replace_string( addrIndex->fileName, value );
}
-/**
- * Property - Specify file path to be used.
- * \param addrIndex Address index.
- * \param value Path to JPilot file.
- */
-void addrindex_set_dirty( AddressIndex *addrIndex, const gboolean value ) {
- g_return_if_fail( addrIndex != NULL );
- addrIndex->dirtyFlag = value;
-}
-
-/**
- * Property - get loaded flag. Note that this flag is set after reading data
- * from the address books.
- * \param addrIndex Address index.
- * \return <i>TRUE</i> if address index data was loaded.
- */
-gboolean addrindex_get_loaded( AddressIndex *addrIndex ) {
- g_return_val_if_fail( addrIndex != NULL, FALSE );
- return addrIndex->loadedFlag;
-}
-
/**
* Return list of address interfaces.
* \param addrIndex Address index.
* \param ifType Interface type.
* \return Address interface, or NULL if not found.
*/
-AddressInterface *addrindex_get_interface(
+static AddressInterface *addrindex_get_interface(
AddressIndex *addrIndex, AddressIfType ifType )
{
AddressInterface *retVal = NULL;
guint prevLevel;
gint rc;
- /* printf( "addrindex_read_fragment\n" ); */
+ /* g_print( "addrindex_read_fragment\n" ); */
prevLevel = file->level;
gchar *serverName = NULL;
gchar *criteria = NULL;
gboolean bDynSearch;
- gboolean bTLS;
+ gboolean bTLS, bSSL;
gint iMatch;
- /* printf( "addrindex_parse_ldap\n" ); */
+ /* 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 );
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 );
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 );
}
ldapsvr_set_name( server, serverName );
ldapsvr_set_search_flag( server, bDynSearch );
ldapctl_set_matching_option( ctl, iMatch );
+#ifdef USE_LDAP_TLS
ldapctl_set_tls( ctl, bTLS );
+ ldapctl_set_ssl( ctl, bSSL );
+#endif
g_free( serverName );
ldapsvr_set_control( server, ctl );
ds->rawDataSource = server;
addrindex_write_attr( fp, ATTAG_LDAP_ENABLE_TLS,
ctl->enableTLS ?
ATVAL_BOOLEAN_YES : ATVAL_BOOLEAN_NO );
+ addrindex_write_attr( fp, ATTAG_LDAP_ENABLE_SSL,
+ ctl->enableSSL ?
+ ATVAL_BOOLEAN_YES : ATVAL_BOOLEAN_NO );
fputs(" >\n", fp);
if( file == NULL ) {
/*
- fprintf( stdout, " file '%s' does not exist.\n", addrIndex->fileName );
+ g_print( " file '%s' does not exist.\n", addrIndex->fileName );
*/
return addrIndex->retVal;
}
* return: Status code, from addrIndex->retVal.
* Note: File will be created in directory specified by addrIndex.
*/
-gint addrindex_write_to( AddressIndex *addrIndex, const gchar *newFile ) {
+static gint addrindex_write_to( AddressIndex *addrIndex, const gchar *newFile ) {
FILE *fp;
gchar *fileSpec;
#ifndef DEV_STANDALONE
* return: Status code, from addrIndex->retVal.
*/
gint addrindex_save_data( AddressIndex *addrIndex ) {
+#ifdef USE_LDAP
+ GList *nodeIf;
+ GList *nodeDS;
+#endif
+
g_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."),
+ GTK_STOCK_CLOSE, NULL, NULL );
+ }
+ 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;
node->list = g_list_append( node->list, newNode );
}
else {
- /* printf( "invalid: !!! \n" ); */
+ /* g_print( "invalid: !!! \n" ); */
attr = xml_get_current_tag_attr( file );
}
}
if (file->level < prev_level) return;
xtag = xml_get_current_tag( file );
- /* printf( "tag : %s\n", xtag->tag ); */
+ /* g_print( "tag : %s\n", xtag->tag ); */
element = xml_get_element( file );
attr = xml_get_current_tag_attr( file );
/* show_attribs( attr ); */
- /* printf( "\ttag value : %s :\n", element ); */
+ /* g_print( "\ttag value : %s :\n", element ); */
addrindex_consume_tree( file );
}
}
if (file->level < prev_level) return;
xtag = xml_get_current_tag( file );
- /* printf( "tag : %d : %s\n", prev_level, xtag->tag ); */
+ /* g_print( "tag : %d : %s\n", prev_level, xtag->tag ); */
if( strcmp( xtag->tag, TAG_IF_OLD_COMMON ) == 0 ) {
if( addrindex_process_book( addrIndex, file, DISP_OLD_COMMON ) ) {
addrIndex->needsConversion = FALSE;
element = xml_get_element( file );
attr = xml_get_current_tag_attr( file );
/* show_attribs( attr ); */
- /* printf( "\ttag value : %s :\n", element ); */
+ /* g_print( "\ttag value : %s :\n", element ); */
addrindex_consume_tree( file );
}
}
g_free( fileSpec );
if( file == NULL ) {
- /* fprintf( stdout, " file '%s' does not exist.\n", addrIndex->fileName ); */
+ /* g_print( " file '%s' does not exist.\n", addrIndex->fileName ); */
return addrIndex->retVal;
}
if( iface->getReadData ) {
/*
gchar *name = ( iface->getName ) ( ds->rawDataSource );
- printf( "addrindex_ds_read_data...reading:::%s:::\n", name );
+ g_print( "addrindex_ds_read_data...reading:::%s:::\n", name );
*/
retVal = ( iface->getReadData ) ( ds->rawDataSource );
}
return retVal;
}
-/*
- * Return list of folders for specified data source.
- */
-GList *addrindex_ds_get_list_folder( AddressDataSource *ds ) {
- GList *retVal = FALSE;
- AddressInterface *iface;
-
- if( ds == NULL ) return retVal;
- iface = ds->interface;
- if( iface == NULL ) return retVal;
- if( iface->getListFolder ) {
- retVal = ( iface->getListFolder ) ( ds->rawDataSource );
- }
- return retVal;
-}
-
-/*
- * Return list of persons in root folder for specified data source.
- */
-GList *addrindex_ds_get_list_person( AddressDataSource *ds ) {
- GList *retVal = FALSE;
- AddressInterface *iface;
-
- if( ds == NULL ) return retVal;
- iface = ds->interface;
- if( iface == NULL ) return retVal;
- if( iface->getListPerson ) {
- retVal = ( iface->getListPerson ) ( ds->rawDataSource );
- }
- return retVal;
-}
-
/*
* Return name for specified data source.
*/
/*
* Return list of all persons for specified data source.
*/
-GList *addrindex_ds_get_all_persons( AddressDataSource *ds ) {
+static GList *addrindex_ds_get_all_persons( AddressDataSource *ds ) {
GList *retVal = NULL;
AddressInterface *iface;
/*
* Return list of all groups for specified data source.
*/
-GList *addrindex_ds_get_all_groups( AddressDataSource *ds ) {
+static GList *addrindex_ds_get_all_groups( AddressDataSource *ds ) {
GList *retVal = NULL;
AddressInterface *iface;
queryID = req->queryID;
qryreq_set_search_type( req, ADDRSEARCH_DYNAMIC );
- /* printf( "***> query ID ::%d::\n", queryID ); */
+ /* g_print( "***> query ID ::%d::\n", queryID ); */
return queryID;
}
GList *nodeDS;
gint type;
- /* printf( "addrindex_start_dynamic::%d::\n", req->queryID ); */
+ /* g_print( "addrindex_start_dynamic::%d::\n", req->queryID ); */
nodeIf = _addressIndex_->searchOrder;
while( nodeIf ) {
iface = nodeIf->data;
AddrQueryObject *aqo;
GList *node;
- /* printf( "addrindex_stop_search/queryID=%d\n", queryID ); */
+ /* g_print( "addrindex_stop_search/queryID=%d\n", queryID ); */
/* If query ID does not match, search has not been setup */
req = qrymgr_find_request( queryID );
if( req == NULL ) {
AddrSearchType searchType;
retVal = FALSE;
- /* printf( "addrindex_start_search/queryID=%d\n", queryID ); */
+ /* g_print( "addrindex_start_search/queryID=%d\n", queryID ); */
req = qrymgr_find_request( queryID );
if( req == NULL ) {
return retVal;
AddressCache *cache;
gint queryID = 0;
- /* printf( "addrindex_remove_results/start\n" ); */
+ /* g_print( "addrindex_remove_results/start\n" ); */
/* Test for folder */
if( folder->folderType != ADDRFOLDER_QUERY_RESULTS ) return;
- /* printf( "folder name ::%s::\n", ADDRITEM_NAME(folder) ); */
+ /* g_print( "folder name ::%s::\n", ADDRITEM_NAME(folder) ); */
adbase = ( AddrBookBase * ) ds->rawDataSource;
if( adbase == NULL ) return;
cache = adbase->addressCache;
qry = ( LdapQuery * ) folder->folderData;
queryID = ADDRQUERY_ID(qry);
- /* printf( "calling ldapquery_remove_results...queryID=%d\n", queryID ); */
+ /* g_print( "calling ldapquery_remove_results...queryID=%d\n", queryID ); */
delFlag = ldapquery_remove_results( qry );
if (delFlag) {
ldapqry_free( qry );
}
- /* printf( "calling ldapquery_remove_results...done\n" ); */
+ /* g_print( "calling ldapquery_remove_results...done\n" ); */
/*
if( delFlag ) {
- printf( "delFlag IS-TRUE\n" );
+ g_print( "delFlag IS-TRUE\n" );
}
else {
- printf( "delFlag IS-FALSE\n" );
- addressbook_clear_idler( queryID );
+ g_print( "delFlag IS-FALSE\n" );
}
*/
#endif
}
- /* printf( "addrindex_remove_results/end\n" ); */
+ /* g_print( "addrindex_remove_results/end\n" ); */
/* Delete query request */
if( queryID > 0 ) {
* ***********************************************************************
*/
+static void addrindex_load_completion_load_persons(
+ gint (*callBackFunc) ( const gchar *, const gchar *,
+ const gchar *, const gchar *, GList * ),
+ AddressDataSource *ds)
+{
+ GList *listP, *nodeP;
+ GList *nodeM;
+ gchar *sName;
+
+ /* Read address book */
+ if( addrindex_ds_get_modify_flag( ds ) ) {
+ addrindex_ds_read_data( ds );
+ }
+
+ if( ! addrindex_ds_get_read_flag( ds ) ) {
+ addrindex_ds_read_data( ds );
+ }
+
+ /* Get all groups */
+ listP = addrindex_ds_get_all_groups( ds );
+ nodeP = listP;
+ while( nodeP ) {
+ ItemGroup *group = nodeP->data;
+ GList *emails = NULL;
+ for (nodeM = group->listEMail; nodeM; nodeM = g_list_next(nodeM)) {
+ ItemEMail *email = nodeM->data;
+ if (email->address)
+ emails = g_list_append(emails, email);
+ }
+ callBackFunc( ((AddrItemObject *)group)->name, NULL,
+ NULL, NULL, emails );
+ nodeP = g_list_next( nodeP );
+ }
+
+ /* Free up the list */
+ g_list_free( listP );
+ /* Get all persons */
+ listP = addrindex_ds_get_all_persons( ds );
+ nodeP = listP;
+ while( nodeP ) {
+ ItemPerson *person = nodeP->data;
+ nodeM = person->listEMail;
+
+ /* Figure out name to use */
+ sName = ADDRITEM_NAME(person);
+ if( sName == NULL || *sName == '\0' ) {
+ sName = person->nickName;
+ }
+
+ /* Process each E-Mail address */
+ while( nodeM ) {
+ ItemEMail *email = nodeM->data;
+
+ callBackFunc( sName, email->address, person->nickName,
+ ADDRITEM_NAME(email), NULL );
+
+ nodeM = g_list_next( nodeM );
+ }
+ nodeP = g_list_next( nodeP );
+ }
+
+ /* Free up the list */
+ g_list_free( listP );
+}
+
/**
* This function is used by the address completion function to load
* addresses for all non-external address book interfaces.
*
* \param callBackFunc Function to be called when an address is
* to be loaded.
+ * \param folderpath Addressbook's Book/folder path to restrict to (if NULL or ""
+ * or "Any", assume the whole addressbook
* \return <i>TRUE</i> if data loaded, <i>FALSE</i> if address index not loaded.
*/
+
gboolean addrindex_load_completion(
gint (*callBackFunc) ( const gchar *, const gchar *,
- const gchar *, const gchar * ) )
+ const gchar *, const gchar *, GList * ),
+ gchar *folderpath )
{
- AddressDataSource *ds;
GList *nodeIf, *nodeDS;
- GList *listP, *nodeP;
- GList *nodeM;
- gchar *sName;
- nodeIf = addrindex_get_interface_list( _addressIndex_ );
- while( nodeIf ) {
- AddressInterface *iface = nodeIf->data;
+ if( folderpath != NULL ) {
+ AddressDataSource *book;
+ ItemFolder* folder;
- nodeIf = g_list_next( nodeIf );
- if( ! iface->useInterface ) {
- continue;
- }
- if( iface->externalQuery ) {
- continue;
+ /* split the folder path we've received, we'll try to match this path, subpath by
+ 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\n", folderpath);
+ return FALSE;
}
- nodeDS = iface->listSource;
- while( nodeDS ) {
- ds = nodeDS->data;
- /* Read address book */
- if( addrindex_ds_get_modify_flag( ds ) ) {
- addrindex_ds_read_data( ds );
- }
+ if( folder != NULL ) {
- if( ! addrindex_ds_get_read_flag( ds ) ) {
- addrindex_ds_read_data( ds );
- }
+ GList *items;
+ GList *nodeM;
+ gchar *sName;
+ ItemPerson *person;
- /* Get all persons */
- listP = addrindex_ds_get_all_persons( ds );
- nodeP = listP;
- while( nodeP ) {
- ItemPerson *person = nodeP->data;
+ debug_print("addrindex_load_completion: folder %p '%s'\n", folder, folder->obj.name);
+
+ /* Load email addresses */
+ items = addritem_folder_get_person_list( folder );
+ for( ; items != NULL; items = g_list_next( items ) ) {
+ person = items->data;
nodeM = person->listEMail;
/* Figure out name to use */
/* Process each E-Mail address */
while( nodeM ) {
ItemEMail *email = nodeM->data;
-
+
callBackFunc( sName, email->address, person->nickName,
- ADDRITEM_NAME(email) );
-
+ ADDRITEM_NAME(email), NULL );
+
nodeM = g_list_next( nodeM );
}
- nodeP = g_list_next( nodeP );
}
/* Free up the list */
- g_list_free( listP );
+ mgu_clear_list( items );
+ g_list_free( items );
+
+ return TRUE;
+
+ } else {
+
+ if( book != NULL ) {
+
+ AddressBookFile *abf = book->rawDataSource;
+
+ debug_print("addrindex_load_completion: book %p '%s'\n", book, abf?abf->fileName:"(null)");
+
+ addrindex_load_completion_load_persons( callBackFunc, book );
+ return TRUE;
+
+ } else {
+ g_warning("addrindex_load_completion: book/folder path is valid but got no pointer\n");
+ }
+ }
+ return FALSE;
+
+ } else {
+
+ nodeIf = addrindex_get_interface_list( _addressIndex_ );
+ while( nodeIf ) {
+ AddressInterface *iface = nodeIf->data;
+
+ nodeIf = g_list_next( nodeIf );
+
+ if( ! iface->useInterface || iface->externalQuery )
+ continue;
+
+ nodeDS = iface->listSource;
+ while( nodeDS ) {
+ addrindex_load_completion_load_persons( callBackFunc, nodeDS->data );
nodeDS = g_list_next( nodeDS );
}
}
+ }
return TRUE;
}
AddressInterface *iface = nodeIf->data;
nodeIf = g_list_next( nodeIf );
- if( ! iface->useInterface ) {
- continue;
- }
- if( iface->externalQuery ) {
+
+ if( ! iface->useInterface || iface->externalQuery )
continue;
- }
+
nodeDS = iface->listSource;
while( nodeDS ) {
ds = nodeDS->data;