/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2002-2006 Match Grun and the Sylpheed-Claws team
+ * Copyright (C) 2002-2011 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 "addrharvest.h"
#include "codeconv.h"
#include "addritem.h"
+#ifdef USE_NEW_ADDRBOOK
+ #include "addressbook-dbus.h"
+#endif
/* Mail header names of interest */
static gchar *_headerFrom_ = HEADER_FROM;
#define DFL_FOLDER_SIZE 20
/* Noise strings included by some other E-Mail clients */
-#define REM_NAME_STRING "(E-mail)"
-#define REM_NAME_STRING2 "(E-mail 2)"
+#define REM_NAME_STRING "(Email)"
+#define REM_NAME_STRING2 "(Email 2)"
/* Directories to ignore */
-#define DIR_IGNORE ".\t..\t.sylpheed_mark\t.sylpheed_cache"
+#define DIR_IGNORE ".\t..\t.sylpheed_mark\t.sylpheed_claws_cache"
/*
* Header entry.
gint count;
};
+#ifdef USE_NEW_ADDRBOOK
+typedef enum {
+ FIRST = 0,
+ LAST,
+} Namepart;
+
+#endif
+
/*
* Build header table entry.
* Enter: harvester Harvester object.
* value Full directory path.
*/
void addrharvest_set_path( AddressHarvester* harvester, const gchar *value ) {
- g_return_if_fail( harvester != NULL );
+ cm_return_if_fail( harvester != NULL );
harvester->path = mgu_replace_string( harvester->path, value );
g_strstrip( harvester->path );
}
void addrharvest_set_folder_size(
AddressHarvester* harvester, const gint value )
{
- g_return_if_fail( harvester != NULL );
+ cm_return_if_fail( harvester != NULL );
if( value > 0 ) {
harvester->folderSize = value;
}
void addrharvest_set_recurse(
AddressHarvester* harvester, const gboolean value )
{
- g_return_if_fail( harvester != NULL );
+ cm_return_if_fail( harvester != NULL );
harvester->folderRecurse = value;
}
{
HeaderEntry *entry;
- g_return_if_fail( harvester != NULL );
+ cm_return_if_fail( harvester != NULL );
entry = addrharvest_find( harvester, name );
if( entry != NULL ) {
entry->selected = value;
gint count;
count = -1;
- g_return_val_if_fail( harvester != NULL, count );
+ cm_return_val_if_fail( harvester != NULL, count );
entry = addrharvest_find( harvester, name );
if( entry != NULL ) {
count = entry->count;
* Enter: harvester Harvester.
*/
void addrharvest_free( AddressHarvester *harvester ) {
- g_return_if_fail( harvester != NULL );
+ cm_return_if_fail( harvester != NULL );
/* Free internal stuff */
addrharvest_free_table( harvester );
g_free( harvester );
}
-/*
-* Display object to specified stream.
-* Enter: harvester Harvester.
-* stream Output stream.
-*/
-void addrharvest_print( AddressHarvester *harvester, FILE *stream ) {
- GList *node;
- HeaderEntry *entry;
-
- g_return_if_fail( harvester != NULL );
- fprintf( stream, "Address Harvester:\n" );
- fprintf( stream, " file path: '%s'\n", harvester->path );
- fprintf( stream, "max folder: %d'\n", harvester->folderSize );
-
- node = harvester->headerTable;
- while( node ) {
- entry = node->data;
- fprintf( stream, " header: %s", entry->header );
- fprintf( stream, "\t: %s", entry->selected ? "yes" : "no" );
- fprintf( stream, "\t: %d\n", entry->count );
- node = g_list_next( node );
- }
- fprintf( stream, " ret val: %d\n", harvester->retVal );
+#ifdef USE_NEW_ADDRBOOK
+static gchar* get_namepart(const gchar* name, Namepart namepart) {
+ gchar *pos, *part = NULL;
+ gchar *token = g_strdup(name);
+
+ pos = g_strrstr(token, " ");
+ if (namepart == FIRST) {
+ if (pos) {
+ *pos = '\0';
+ part = g_strdup(token);
+ *pos = ' ';
+ }
+ }
+ else {
+ if (! pos)
+ part = g_strdup(token);
+ else {
+ pos +=1;
+ part = g_strdup(pos);
+ }
+ }
+ g_free(token);
+ return part;
}
+#endif
/*
* Insert address into cache.
AddressCache *cache, const gchar *name,
const gchar *address )
{
+#ifndef USE_NEW_ADDRBOOK
ItemPerson *person;
ItemFolder *folder;
gchar *folderName;
if( entry->count % harvester->folderSize == 0 ) {
newFolder = TRUE; /* Folder is full */
}
+#else
+ ContactEntry* person;
+ gchar* key;
+#endif
/* Insert address */
- key = g_strdup( address );
- g_strdown( key );
+ key = g_utf8_strdown( address, -1 );
person = g_hash_table_lookup( harvester->dupTable, key );
+#ifndef USE_NEW_ADDRBOOK
if( person ) {
/* Update existing person to use longest name */
value = ADDRITEM_NAME(person);
entry->count++;
}
addritem_parse_first_last( person );
+#else
+ if (! person) {
+ person = g_new0(ContactEntry, 1);
+ person->first_name = get_namepart(name, FIRST);
+ person->last_name = get_namepart(name, LAST);
+ person->email = g_strdup(address);
+ g_hash_table_insert(harvester->dupTable, key, person);
+ entry->count++;
+ }
+#endif
}
/*
/* Copy into buffer */
bufLen = ( size_t ) ( ep - bp );
- if( bufLen > ADDR_BUFFSIZE ) {
- bufLen = ADDR_BUFFSIZE;
+ if( bufLen > ADDR_BUFFSIZE -1 ) {
+ bufLen = ADDR_BUFFSIZE - 1;
}
strncpy( buffer, bp, bufLen );
buffer[ bufLen ] = '\0';
}
else {
name = buffer;
- name = conv_unmime_header(buffer, NULL);
+ name = conv_unmime_header(buffer, NULL, TRUE);
}
/* Insert into address book */
+#ifndef USE_NEW_ADDRBOOK
addrharvest_insert_cache(
harvester, entry, cache, name, email );
+#else
+ addrharvest_insert_cache(
+ harvester, entry, NULL, name, email);
+#endif
g_free( email );
g_free( name );
}
struct dirent *d;
struct stat s;
gint num;
+ int r;
if( ( dp = opendir( dir ) ) == NULL ) {
return;
}
/* Process directory */
- chdir( dir );
- while( ( d = readdir( dp ) ) != NULL ) {
- stat( d->d_name, &s );
+ r = chdir( dir );
+ while( r == 0 && ( d = readdir( dp ) ) != NULL ) {
+ g_stat( d->d_name, &s );
if( S_ISDIR( s.st_mode ) ) {
if( harvester->folderRecurse ) {
if( strstr( DIR_IGNORE, d->d_name ) != NULL )
}
}
}
- chdir( ".." );
+ r = chdir( ".." );
closedir( dp );
}
gint num;
GList *node;
gchar msgNum[ MSGNUM_BUFFSIZE ];
+ int r;
if( ( dp = opendir( harvester->path ) ) == NULL ) {
return;
}
/* Process message list */
- chdir( harvester->path );
+ r = chdir( harvester->path );
node = msgList;
while( node ) {
num = GPOINTER_TO_UINT( node->data );
GList *listHdr;
retVal = MGU_BAD_ARGS;
- g_return_val_if_fail( harvester != NULL, retVal );
- g_return_val_if_fail( cache != NULL, retVal );
- g_return_val_if_fail( harvester->path != NULL, retVal );
+ cm_return_val_if_fail( harvester != NULL, retVal );
+#ifndef USE_NEW_ADDRBOOK
+ cm_return_val_if_fail( cache != NULL, retVal );
+#endif
+ cm_return_val_if_fail( harvester->path != NULL, retVal );
+#ifndef USE_NEW_ADDRBOOK
/* Clear cache */
addrcache_clear( cache );
cache->dataRead = FALSE;
-
+#endif
/* Build list of headers of interest */
listHdr = NULL;
node = harvester->headerTable;
if( entry->selected ) {
gchar *p;
- p = g_strdup( entry->header );
- g_strdown( p );
+ p = g_utf8_strdown( entry->header, -1 );
listHdr = g_list_append( listHdr, p );
}
node = g_list_next( node );
}
mgu_free_dlist( listHdr );
+#ifndef USE_NEW_ADDRBOOK
/* Mark cache */
cache->modified = FALSE;
cache->dataRead = TRUE;
-
+#endif
return retVal;
}
GList *node;
retVal = FALSE;
- g_return_val_if_fail( harvester != NULL, retVal );
+ cm_return_val_if_fail( harvester != NULL, retVal );
node = harvester->headerTable;
while( node ) {