2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2001 Match Grun
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 * General functions for create common address book entries.
30 * Dump linked list of character strings (for debug).
32 void mgu_print_list( GSList *list, FILE *stream ) {
35 fprintf( stream, "\t- >%s<\n", node->data );
36 node = g_slist_next( node );
41 * Dump linked list of character strings (for debug).
43 void mgu_print_dlist( GList *list, FILE *stream ) {
46 fprintf( stream, "\t- >%s<\n", node->data );
47 node = g_list_next( node );
52 * Free linked list of character strings.
54 void mgu_free_list( GSList *list ) {
59 node = g_slist_next( node );
65 * Free linked list of character strings.
67 void mgu_free_dlist( GList *list ) {
72 node = g_list_next( node );
78 * Coalesce linked list of characaters into one long string.
80 gchar *mgu_list_coalesce( GSList *list ) {
87 if( ! list ) return NULL;
89 // Calculate maximum length of text
94 len += 1 + strlen( str );
95 node = g_slist_next( node );
99 buf = g_new0( gchar, len+1 );
105 strcpy( start, str );
107 node = g_slist_next( node );
112 struct mgu_error_entry {
117 static const struct mgu_error_entry mgu_error_list[] = {
118 { MGU_SUCCESS, "Success" },
119 { MGU_BAD_ARGS, "Bad arguments" },
120 { MGU_NO_FILE, "File not specified" },
121 { MGU_OPEN_FILE, "Error opening file" },
122 { MGU_ERROR_READ, "Error reading file" },
123 { MGU_EOF, "End of file encountered" },
124 { MGU_OO_MEMORY, "Error allocating memory" },
125 { MGU_BAD_FORMAT, "Bad file format" },
126 { MGU_LDAP_CONNECT, "Error connecting to LDAP server" },
127 { MGU_LDAP_INIT, "Error initializing LDAP" },
128 { MGU_LDAP_BIND, "Error binding to LDAP server" },
129 { MGU_LDAP_SEARCH, "Error searching LDAP database" },
130 { MGU_LDAP_TIMEOUT, "Timeout performing LDAP operation" },
131 { MGU_LDAP_CRITERIA, "Error in LDAP search criteria" },
132 { MGU_LDAP_CRITERIA, "Error in LDAP search criteria" },
133 { MGU_LDAP_NOENTRIES, "No LDAP entries found for search criteria" },
134 { MGU_ERROR_WRITE, "Error writing to file" },
135 { MGU_OPEN_DIRECTORY, "Error opening directory" },
136 { MGU_NO_PATH, "No path specified" },
140 static const struct mgu_error_entry *mgu_error_find( gint err ) {
142 for ( i = 0; mgu_error_list[i].e_code != -999; i++ ) {
143 if ( err == mgu_error_list[i].e_code )
144 return & mgu_error_list[i];
150 * Return error message for specified error code.
152 gchar *mgu_error2string( gint err ) {
153 const struct mgu_error_entry *e;
154 e = mgu_error_find( err );
155 return ( e != NULL ) ? e->e_reason : "Unknown error";
159 * Replace existing string with new string.
161 gchar *mgu_replace_string( gchar *str, const gchar *value ) {
162 if( str ) g_free( str );
164 str = g_strdup( value );
174 * Clear a linked list by setting node data pointers to NULL. Note that
175 * items are not freed.
177 void mgu_clear_slist( GSList *list ) {
181 node = g_slist_next( node );
186 * Clear a linked list by setting node data pointers to NULL. Note that
187 * items are not freed.
189 void mgu_clear_list( GList *list ) {
193 node = g_list_next( node );
198 * Test and reformat an email address.
200 * Return: Address, or NULL if address is empty.
201 * Note: Leading and trailing white space is removed.
203 gchar *mgu_email_check_empty( gchar *address ) {
204 gchar *retVal = NULL;
206 retVal = g_strdup( address );
207 retVal = g_strchug( retVal );
208 retVal = g_strchomp( retVal );
209 if( *retVal == '\0' ) {