2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2002 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 * Export address book to HTML file.
34 #include "exporthtml.h"
37 #define DFL_DIR_SYLPHEED_OUT "sylpheed-out"
38 #define DFL_FILE_SYLPHEED_OUT "addressbook.html"
40 #define FMT_BUFSIZE 2048
41 #define HTML_SPACE " "
43 #define CELL_PADDING 2
44 #define CELL_SPACING 2
45 #define CHAR_ENCODING "ISO-8859-1"
47 /* Stylesheet names */
48 #define FILENAME_NONE ""
49 #define FILENAME_DEFAULT "sylpheed.css"
50 #define FILENAME_FULL "full.css"
51 #define FILENAME_CUSTOM "custom.css"
52 #define FILENAME_CUSTOM2 "custom2.css"
53 #define FILENAME_CUSTOM3 "custom3.css"
54 #define FILENAME_CUSTOM4 "custom4.css"
56 /* Settings - properties */
57 #define EXML_PROPFILE_NAME "exporthtml.xml"
58 #define EXMLPROP_DIRECTORY "directory"
59 #define EXMLPROP_FILE "file"
60 #define EXMLPROP_STYLESHEET "stylesheet"
61 #define EXMLPROP_FMT_NAME "format-full-name"
62 #define EXMLPROP_FMT_EMAIL "format-email-links"
63 #define EXMLPROP_FMT_ATTRIB "format-attributes"
64 #define EXMLPROP_BANDING "color-banding"
65 #define EXMLPROP_VALUE_YES "y"
66 #define EXMLPROP_VALUE_NO "n"
68 static gchar *_idTagRowEven_ = "tab-row0";
69 static gchar *_idTagRowOdd_ = "tab-row1";
74 typedef struct _StylesheetEntry StylesheetEntry;
75 struct _StylesheetEntry {
82 * Build stylesheet entry.
83 * Enter: ctl Export control data.
88 static void exporthtml_build_entry(
89 ExportHtmlCtl *ctl, const gchar *file, const gint id,
92 StylesheetEntry *entry;
94 entry = g_new0( StylesheetEntry, 1 );
95 entry->fileName = g_strdup( file );
97 entry->dflValue = dfl;
98 ctl->listStyle = g_list_append( ctl->listStyle, entry );
102 * Free up object by releasing internal memory.
103 * Enter: ctl Export control data.
105 ExportHtmlCtl *exporthtml_create( void ) {
106 ExportHtmlCtl *ctl = g_new0( ExportHtmlCtl, 1 );
109 ctl->dirOutput = NULL;
110 ctl->fileHtml = NULL;
111 ctl->encoding = NULL;
112 ctl->stylesheet = EXPORT_HTML_ID_NONE;
113 ctl->nameFormat = EXPORT_HTML_FIRST_LAST;
114 ctl->banding = FALSE;
115 ctl->linkEMail = FALSE;
116 ctl->showAttribs = FALSE;
117 ctl->retVal = MGU_SUCCESS;
118 ctl->listStyle = NULL;
120 ctl->settingsFile = g_strconcat(
121 get_rc_dir(), G_DIR_SEPARATOR_S, EXML_PROPFILE_NAME, NULL );
123 /* Build stylesheet list */
124 exporthtml_build_entry(
125 ctl, FILENAME_NONE, EXPORT_HTML_ID_NONE, FALSE );
126 exporthtml_build_entry(
127 ctl, FILENAME_DEFAULT, EXPORT_HTML_ID_DEFAULT, TRUE );
128 exporthtml_build_entry(
129 ctl, FILENAME_FULL, EXPORT_HTML_ID_FULL, FALSE );
130 exporthtml_build_entry(
131 ctl, FILENAME_CUSTOM, EXPORT_HTML_ID_CUSTOM, FALSE );
132 exporthtml_build_entry(
133 ctl, FILENAME_CUSTOM2, EXPORT_HTML_ID_CUSTOM2, FALSE );
134 exporthtml_build_entry(
135 ctl, FILENAME_CUSTOM3, EXPORT_HTML_ID_CUSTOM3, FALSE );
136 exporthtml_build_entry(
137 ctl, FILENAME_CUSTOM4, EXPORT_HTML_ID_CUSTOM4, FALSE );
143 * Free up object by releasing internal memory.
144 * Enter: ctl Export control data.
146 void exporthtml_free( ExportHtmlCtl *ctl ) {
148 StylesheetEntry *entry;
150 g_return_if_fail( ctl != NULL );
152 /* Free stylesheet list */
153 node = ctl->listStyle;
155 entry = ( StylesheetEntry * ) node->data;
156 g_free( entry->fileName );
157 entry->fileName = NULL;
159 entry->dflValue = FALSE;
162 node = g_list_next( node );
164 g_list_free( ctl->listStyle );
165 ctl->listStyle = NULL;
168 g_free( ctl->fileHtml );
169 g_free( ctl->encoding );
170 g_free( ctl->dirOutput );
171 g_free( ctl->settingsFile );
175 ctl->dirOutput = NULL;
176 ctl->fileHtml = NULL;
177 ctl->encoding = NULL;
178 ctl->stylesheet = EXPORT_HTML_ID_NONE;
179 ctl->nameFormat = EXPORT_HTML_FIRST_LAST;
180 ctl->banding = FALSE;
181 ctl->linkEMail = FALSE;
182 ctl->showAttribs = FALSE;
183 ctl->retVal = MGU_SUCCESS;
186 /* Now release object */
191 * Print control object.
192 * Enter: ctl Export control data.
193 * stream Output stream.
195 void exporthtml_print( ExportHtmlCtl *ctl, FILE *stream ) {
196 fprintf( stream, "ExportHtmlCtl:\n" );
197 fprintf( stream, " path: %s\n", ctl->path );
198 fprintf( stream, "directory: %s\n", ctl->dirOutput );
199 fprintf( stream, " file: %s\n", ctl->fileHtml );
200 fprintf( stream, " settings: %s\n", ctl->settingsFile );
201 fprintf( stream, " encoding: %s\n", ctl->encoding );
202 fprintf( stream, " css file: %d\n", ctl->stylesheet );
203 fprintf( stream, " name fmt: %d\n", ctl->nameFormat );
204 fprintf( stream, " banding: %d\n", ctl->banding );
205 fprintf( stream, "link mail: %d\n", ctl->linkEMail );
206 fprintf( stream, "show attr: %d\n", ctl->showAttribs );
211 * Enter: ctl Export control data.
212 * Return: Stylesheet object, or NULL if nothing found. If a default entry is
213 * found in list, it will be returned.
215 static StylesheetEntry *exporthtml_find_stylesheet( ExportHtmlCtl *ctl ) {
216 StylesheetEntry *retVal = NULL;
217 StylesheetEntry *entry;
220 node = ctl->listStyle;
222 entry = ( StylesheetEntry * ) node->data;
223 if( entry->id == ctl->stylesheet ) return entry;
224 if( entry->dflValue ) retVal = entry;
225 node = g_list_next( node );
234 * Specify path to folder where files are created.
235 * Enter: ctl Export control data.
236 * value Full directory path.
238 void exporthtml_set_output_dir( ExportHtmlCtl *ctl, const gchar *value ) {
239 g_return_if_fail( ctl != NULL );
240 ctl->dirOutput = mgu_replace_string( ctl->dirOutput, value );
241 g_strstrip( ctl->dirOutput );
243 void exporthtml_set_path( ExportHtmlCtl *ctl, const gchar *value ) {
244 g_return_if_fail( ctl != NULL );
245 ctl->path = mgu_replace_string( ctl->path, value );
246 g_strstrip( ctl->path );
248 void exporthtml_set_file_html( ExportHtmlCtl *ctl, const gchar *value ) {
249 g_return_if_fail( ctl != NULL );
250 ctl->fileHtml = mgu_replace_string( ctl->fileHtml, value );
251 g_strstrip( ctl->fileHtml );
253 void exporthtml_set_encoding( ExportHtmlCtl *ctl, const gchar *value ) {
254 g_return_if_fail( ctl != NULL );
255 ctl->encoding = mgu_replace_string( ctl->encoding, value );
256 g_strstrip( ctl->encoding );
258 void exporthtml_set_stylesheet( ExportHtmlCtl *ctl, const gint value ) {
259 g_return_if_fail( ctl != NULL );
260 ctl->stylesheet = value;
262 void exporthtml_set_name_format( ExportHtmlCtl *ctl, const gint value ) {
263 g_return_if_fail( ctl != NULL );
264 ctl->nameFormat = value;
266 void exporthtml_set_banding( ExportHtmlCtl *ctl, const gboolean value ) {
267 g_return_if_fail( ctl != NULL );
268 ctl->banding = value;
270 void exporthtml_set_link_email( ExportHtmlCtl *ctl, const gboolean value ) {
271 g_return_if_fail( ctl != NULL );
272 ctl->linkEMail = value;
274 void exporthtml_set_attributes( ExportHtmlCtl *ctl, const gboolean value ) {
275 g_return_if_fail( ctl != NULL );
276 ctl->showAttribs = value;
280 * Create default CSS file.
281 * Enter: fileSpec File to create.
282 * Return: Status code.
284 static gint exporthtml_create_css_dfl( const gchar *fileSpec ) {
287 cssFile = fopen( fileSpec, "rb" );
292 cssFile = fopen( fileSpec, "wb" );
294 return MGU_OPEN_FILE;
297 fprintf( cssFile, "body {\n\tbackground: #ffffe0;\n" );
298 fprintf( cssFile, "\tfont-family: lucida, helvetica, sans-serif;\n" );
299 fprintf( cssFile, "\tfont-size: 10pt;\n" );
300 fprintf( cssFile, "}\n" );
301 fprintf( cssFile, "h1 {\n" );
302 fprintf( cssFile, "\tcolor: #000000;\n" );
303 fprintf( cssFile, "\ttext-align: center;\n" );
304 fprintf( cssFile, "}\n" );
305 fprintf( cssFile, "th {\n" );
306 fprintf( cssFile, "\tfont-size: 10pt;\n" );
307 fprintf( cssFile, "}\n" );
308 fprintf( cssFile, "td {\n" );
309 fprintf( cssFile, "\tfont-size: 10pt;\n" );
310 fprintf( cssFile, "}\n" );
311 fprintf( cssFile, ".fmt-folder {\n" );
312 fprintf( cssFile, "\tcolor: #0000ff;\n" );
313 fprintf( cssFile, "\tfont-size: 18pt;\n" );
314 fprintf( cssFile, "\tfont-weight: bold;\n" );
315 fprintf( cssFile, "}\n" );
316 fprintf( cssFile, ".tab-head {\n" );
317 fprintf( cssFile, "\tbackground: #80c0f0;\n" );
318 fprintf( cssFile, "}\n" );
319 fprintf( cssFile, ".tab-dn {\n" );
320 fprintf( cssFile, "}\n" );
321 fprintf( cssFile, ".tab-addr {\n" );
322 fprintf( cssFile, "\tfont-style: italic;\n" );
323 fprintf( cssFile, "}\n" );
324 fprintf( cssFile, ".tab-email {\n" );
325 fprintf( cssFile, "\tfont-weight: bold;\n" );
326 fprintf( cssFile, "\tfont-style: italic;\n" );
327 fprintf( cssFile, "}\n" );
328 fprintf( cssFile, ".tab-fn {\n" );
329 fprintf( cssFile, "}\n" );
330 fprintf( cssFile, ".tab-attr {\n" );
331 fprintf( cssFile, "}\n" );
338 * Create full CSS file.
339 * Enter: fileSpec File to create.
340 * Return: Status code.
342 static gint exporthtml_create_css_full( const gchar *fileSpec ) {
345 cssFile = fopen( fileSpec, "rb" );
350 cssFile = fopen( fileSpec, "wb" );
352 return MGU_OPEN_FILE;
355 fprintf( cssFile, "body {\n\tbackground: #ffffe0;\n" );
356 fprintf( cssFile, "\tfont-family: lucida, helvetica, sans-serif;\n" );
357 fprintf( cssFile, "\tfont-size: 10pt;\n" );
358 fprintf( cssFile, "}\n" );
359 fprintf( cssFile, "h1 {\n" );
360 fprintf( cssFile, "\tcolor: #000000;\n" );
361 fprintf( cssFile, "\ttext-align: center;\n" );
362 fprintf( cssFile, "}\n" );
363 fprintf( cssFile, "th {\n" );
364 fprintf( cssFile, "\tfont-size: 10pt;\n" );
365 fprintf( cssFile, "}\n" );
366 fprintf( cssFile, "td {\n" );
367 fprintf( cssFile, "\tfont-size: 10pt;\n" );
368 fprintf( cssFile, "}\n" );
369 fprintf( cssFile, ".fmt-folder {\n" );
370 fprintf( cssFile, "\tcolor: #0000ff;\n" );
371 fprintf( cssFile, "\tfont-size: 18pt;\n" );
372 fprintf( cssFile, "\tfont-weight: bold;\n" );
373 fprintf( cssFile, "}\n" );
374 fprintf( cssFile, ".tab-head {\n" );
375 fprintf( cssFile, "\tbackground: #80c0f0;\n" );
376 fprintf( cssFile, "}\n" );
377 fprintf( cssFile, ".tab-row0 {\n" );
378 fprintf( cssFile, "\tbackground: #f0f0f0;\n" );
379 fprintf( cssFile, "}\n" );
380 fprintf( cssFile, ".tab-row1 {\n" );
381 fprintf( cssFile, "\tbackground: #d0d0d0;\n" );
382 fprintf( cssFile, "}\n" );
383 fprintf( cssFile, ".tab-dn {\n" );
384 fprintf( cssFile, "}\n" );
385 fprintf( cssFile, ".tab-addr {\n" );
386 fprintf( cssFile, "\tfont-style: italic;\n" );
387 fprintf( cssFile, "}\n" );
388 fprintf( cssFile, ".tab-email {\n" );
389 fprintf( cssFile, "\tfont-weight: bold;\n" );
390 fprintf( cssFile, "\tfont-style: italic;\n" );
391 fprintf( cssFile, "}\n" );
392 fprintf( cssFile, ".tab-fn {\n" );
393 fprintf( cssFile, "}\n" );
394 fprintf( cssFile, ".tab-attr {\n" );
395 fprintf( cssFile, "}\n" );
402 * Create stylesheet files.
403 * Enter: ctl Export control data.
405 static void exporthtml_create_css_files( ExportHtmlCtl *ctl ) {
409 node = ctl->listStyle;
411 StylesheetEntry *entry = node->data;
412 node = g_list_next( node );
413 if( strlen( entry->fileName ) ) {
414 fileSpec = g_strconcat(
415 ctl->dirOutput, G_DIR_SEPARATOR_S,
416 entry->fileName, NULL );
417 if( entry->id == EXPORT_HTML_ID_DEFAULT ) {
418 exporthtml_create_css_dfl( fileSpec );
420 else if( entry->id != EXPORT_HTML_ID_NONE ) {
421 exporthtml_create_css_full( fileSpec );
429 * Comparison using linked list elements.
431 static gint exporthtml_compare_name(
432 gconstpointer ptr1, gconstpointer ptr2 )
434 const AddrItemObject *item1 = ptr1;
435 const AddrItemObject *item2 = ptr2;
436 const gchar *name1 = NULL, *name2 = NULL;
437 if( item1 ) name1 = ADDRITEM_NAME( item1 );
438 if( item2 ) name2 = ADDRITEM_NAME( item2 );
439 if( ! name1 ) return ( name2 != NULL );
440 if( ! name2 ) return -1;
441 return strcasecmp( name1, name2 );
445 * Comparison using linked list elements.
447 static gint exporthtml_compare_email(
448 gconstpointer ptr1, gconstpointer ptr2 )
450 const ItemEMail *email1 = ptr1;
451 const ItemEMail *email2 = ptr2;
452 const gchar *name1 = NULL, *name2 = NULL;
453 if( email1 ) name1 = email1->address;
454 if( email2 ) name2 = email2->address;
455 if( ! name1 ) return ( name2 != NULL );
456 if( ! name2 ) return -1;
457 return strcasecmp( name1, name2 );
461 * Comparison using linked list elements.
463 static gint exporthtml_compare_attrib(
464 gconstpointer ptr1, gconstpointer ptr2 )
466 const UserAttribute *attr1 = ptr1;
467 const UserAttribute *attr2 = ptr2;
468 const gchar *name1 = NULL, *name2 = NULL;
469 if( attr1 ) name1 = attr1->name;
470 if( attr2 ) name2 = attr2->name;
471 if( ! name1 ) return ( name2 != NULL );
472 if( ! name2 ) return -1;
473 return strcasecmp( name1, name2 );
477 * Build sorted list of named items.
478 * Enter: list List of items to sorted.
479 * Return: Sorted list.
480 * Note: List should freed after use. Items referenced by list should not be
481 * freed since they are managed by the address cache.
483 static GList *exporthtml_sort_name( const GList *list ) {
485 GList *sorted = NULL;
489 sorted = g_list_insert_sorted(
490 sorted, node->data, exporthtml_compare_name );
491 node = g_list_next( node );
497 * Build sorted list of email items.
498 * Enter: list List of E-Mail items to sorted.
499 * Return: Sorted list.
500 * Note: List should freed after use. Items referenced by list should not be
501 * freed since they are managed by the address cache.
503 static GList *exporthtml_sort_email( const GList *list ) {
505 GList *sorted = NULL;
509 sorted = g_list_insert_sorted(
510 sorted, node->data, exporthtml_compare_email );
511 node = g_list_next( node );
517 * Build sorted list of attributes.
518 * Enter: list List of items to sorted.
519 * Return: Sorted list.
520 * Note: List should freed after use. Items referenced by list should not be
521 * freed since they are managed by the address cache.
523 static GList *exporthtml_sort_attrib( const GList *list ) {
525 GList *sorted = NULL;
530 sorted = g_list_insert_sorted(
531 sorted, node->data, exporthtml_compare_attrib );
532 node = g_list_next( node );
538 * Format a list of E-Mail addresses.
539 * Enter: ctl Export control data.
540 * stream Output stream.
541 * listEMail List of addresses.
542 * sortFlag Set to TRUE if address list should be sorted.
544 static void exporthtml_fmt_email(
545 ExportHtmlCtl *ctl, FILE *stream, const GList *listEMail,
552 if( listEMail == NULL ) {
553 fprintf( stream, HTML_SPACE );
559 node = list = exporthtml_sort_email( listEMail );
566 ItemEMail *email = ( ItemEMail * ) node->data;
567 node = g_list_next( node );
569 name = ADDRITEM_NAME( email );
571 fprintf( stream, "%s ", name );
573 if( ctl->linkEMail ) {
574 fprintf( stream, "<a href=\"mailto:%s\">",
577 fprintf( stream, "<span class=\"tab-email\">" );
578 fprintf( stream, "%s", email->address );
579 fprintf( stream, "</span>" );
580 if( ctl->linkEMail ) {
581 fprintf( stream, "</a>" );
583 if( email->remarks ) {
584 if( strlen( email->remarks ) ) {
585 fprintf( stream, " (%s)", email->remarks );
588 fprintf( stream, "<br>\n" );
594 * Format groups in an address book folder.
595 * Enter: ctl Export control data.
596 * stream Output stream.
598 * prevFlag If FALSE, list of persons were output.
599 * Return: TRUE if no groups were formatted.
601 static gboolean exporthtml_fmt_group(
602 ExportHtmlCtl *ctl, FILE *stream, const ItemFolder *folder,
605 gboolean retVal, band;
607 const gchar *tagName;
610 if( folder->listGroup == NULL ) return retVal;
612 /* Write separator */
614 fprintf( stream, "<br>\n" );
617 /* Write table headers */
618 fprintf( stream, "<table" );
619 fprintf( stream, " border=\"%d\"", BORDER_SIZE );
620 fprintf( stream, " cellpadding=\"%d\"", CELL_PADDING );
621 fprintf( stream, " cellspacing=\"%d\"", CELL_SPACING );
622 fprintf( stream, ">\n" );
624 fprintf( stream, "<tr class=\"tab-head\">\n" );
625 fprintf( stream, " <th width=\"200\">" );
626 fprintf( stream, "%s", _( "Group Name" ) );
627 fprintf( stream, "</th>\n" );
628 fprintf( stream, " <th width=\"300\">" );
629 fprintf( stream, "%s", _( "E-Mail Address" ) );
630 fprintf( stream, "</th>\n" );
631 fprintf( stream, "</tr>\n" );
632 list = exporthtml_sort_name( folder->listGroup );
637 AddrItemObject *aio = node->data;
638 if( aio && aio->type == ITEMTYPE_GROUP ) {
639 ItemGroup *group = ( ItemGroup * ) aio;
641 fprintf( stream, "<tr valign=\"top\"" );
644 tagName = _idTagRowOdd_;
647 tagName = _idTagRowEven_;
649 fprintf( stream, " class=\"%s\"", tagName );
652 fprintf( stream, "\">\n" );
654 fprintf( stream, " <td class=\"tab-dn\">" );
655 fprintf( stream, "%s", ADDRITEM_NAME( group ) );
656 fprintf( stream, "</td>\n" );
657 fprintf( stream, " <td class=\"tab-addr\">" );
658 exporthtml_fmt_email( ctl, stream, group->listEMail, TRUE );
659 fprintf( stream, "</td>\n" );
660 fprintf( stream, "</tr>\n" );
663 node = g_list_next( node );
667 fprintf( stream, "</table>\n" );
672 * Format a list of E-Mail addresses.
673 * Enter: ctl Export control data.
674 * stream Output stream.
675 * listAttr List of attributes.
677 static void exporthtml_fmt_attribs(
678 ExportHtmlCtl *ctl, FILE *stream, const GList *listAttr )
683 if( listAttr == NULL ) {
684 fprintf( stream, HTML_SPACE );
688 fprintf( stream, "<table border=\"0\">\n" );
689 node = list = exporthtml_sort_attrib( listAttr );
691 UserAttribute *attr = ( UserAttribute * ) node->data;
692 node = g_list_next( node );
693 fprintf( stream, "<tr valign=\"top\">" );
694 fprintf( stream, "<td align=\"right\">%s:</td>", attr->name );
695 fprintf( stream, "<td>%s</td>", attr->value );
696 fprintf( stream, "</tr>\n" );
700 fprintf( stream, "</table>" );
705 * Enter: ctl Export control data.
707 * person Person to format.
709 static void exporthtml_fmt_fullname(
710 ExportHtmlCtl *ctl, gchar *buf, const ItemPerson *person )
714 if( ctl->nameFormat == EXPORT_HTML_LAST_FIRST ) {
716 if( person->lastName ) {
717 if( *person->lastName ) {
719 strcat( buf, person->lastName );
723 if( person->firstName ) {
724 if( *person->firstName ) {
728 strcat( buf, person->firstName );
733 if( person->firstName ) {
734 if( *person->firstName ) {
735 strcat( buf, person->firstName );
738 if( person->lastName ) {
739 if( *person->lastName ) {
741 strcat( buf, person->lastName );
748 if( *buf ) flag = TRUE;
749 if( person->nickName ) {
750 if( strlen( person->nickName ) ) {
754 strcat( buf, person->nickName );
764 * Format persons in an address book folder.
765 * Enter: ctl Export control data.
766 * stream Output stream.
768 * Return: TRUE if no persons were formatted.
770 static gboolean exporthtml_fmt_person(
771 ExportHtmlCtl *ctl, FILE *stream, const ItemFolder *folder )
773 gboolean retVal, band;
775 gchar buf[ FMT_BUFSIZE ];
776 const gchar *tagName;
779 if( folder->listPerson == NULL ) return retVal;
781 /* Write table headers */
782 fprintf( stream, "<table" );
783 fprintf( stream, " border=\"%d\"", BORDER_SIZE );
784 fprintf( stream, " cellpadding=\"%d\"", CELL_PADDING );
785 fprintf( stream, " cellspacing=\"%d\"", CELL_SPACING );
786 fprintf( stream, ">\n" );
788 fprintf( stream, "<tr class=\"tab-head\">\n" );
789 fprintf( stream, " <th width=\"200\">" );
790 fprintf( stream, "%s", _( "Display Name" ) );
791 fprintf( stream, "</th>\n" );
792 fprintf( stream, " <th width=\"300\">" );
793 fprintf( stream, "%s", _( "E-Mail Address" ) );
794 fprintf( stream, "</th>\n" );
795 fprintf( stream, " <th width=\"200\">" );
796 fprintf( stream, "%s", _( "Full Name" ) );
797 fprintf( stream, "</th>\n" );
798 if( ctl->showAttribs ) {
799 fprintf( stream, " <th width=\"250\">" );
800 fprintf( stream, "%s", _( "Attributes" ) );
801 fprintf( stream, "</th>\n" );
803 fprintf( stream, "</tr>\n" );
806 node = list = exporthtml_sort_name( folder->listPerson );
808 AddrItemObject *aio = node->data;
809 if( aio && aio->type == ITEMTYPE_PERSON ) {
810 ItemPerson *person = ( ItemPerson * ) aio;
812 /* Format first/last/nick name */
814 exporthtml_fmt_fullname( ctl, buf,person );
816 fprintf( stream, "<tr valign=\"top\"" );
819 tagName = _idTagRowOdd_;
822 tagName = _idTagRowEven_;
824 fprintf( stream, " class=\"%s\"", tagName );
827 fprintf( stream, ">\n" );
829 fprintf( stream, " <td class=\"tab-dn\">" );
830 fprintf( stream, "%s", ADDRITEM_NAME( person ) );
831 fprintf( stream, "</td>\n" );
833 fprintf( stream, " <td class=\"tab-addr\">" );
834 exporthtml_fmt_email( ctl, stream, person->listEMail, FALSE );
835 fprintf( stream, "</td>\n" );
837 fprintf( stream, " <td class=\"tab-fn\">" );
839 fprintf( stream, "%s", buf );
842 fprintf( stream, "%s", HTML_SPACE );
844 fprintf( stream, "</td>\n" );
846 if( ctl->showAttribs ) {
847 fprintf( stream, " <td class=\"tab-attr\">" );
848 exporthtml_fmt_attribs(
849 ctl, stream, person->listAttrib );
850 fprintf( stream, "</td>\n" );
852 fprintf( stream, "</tr>\n" );
856 node = g_list_next( node );
860 fprintf( stream, "</table>\n" );
865 * Format folder heirarchy.
866 * Enter: stream Output stream.
867 * list Heirarchy list.
869 static void exporthtml_fmt_folderhead( FILE *stream, const GList *list ) {
877 AddrItemObject *aio = node->data;
878 if( aio && aio->type == ITEMTYPE_FOLDER ) {
879 ItemFolder *folder = ( ItemFolder * ) aio;
881 name = ADDRITEM_NAME( folder );
884 fprintf( stream, " > " );
886 fprintf( stream, "%s", name );
890 node = g_list_next( node );
895 * Format an address book folder.
896 * Enter: ctl Export control data.
897 * stream Output stream.
900 static void exporthtml_fmt_folder(
901 ExportHtmlCtl *ctl, FILE *stream, const ItemFolder *folder )
904 GList *listHeir, *list;
908 name = ADDRITEM_NAME( folder );
910 listHeir = addritem_folder_path( folder, TRUE );
912 fprintf( stream, "<p class=\"fmt-folder\">" );
913 fprintf( stream, "%s: ", _( "Folder" ) );
914 exporthtml_fmt_folderhead( stream, listHeir );
915 fprintf( stream, "</p>\n" );
916 g_list_free( listHeir );
920 ret1 = exporthtml_fmt_person( ctl, stream, folder );
921 ret2 = exporthtml_fmt_group( ctl, stream, folder, ret1 );
923 node = list = exporthtml_sort_name( folder->listFolder );
925 AddrItemObject *aio = node->data;
926 if( aio && aio->type == ITEMTYPE_FOLDER ) {
927 ItemFolder *subFolder = ( ItemFolder * ) aio;
928 exporthtml_fmt_folder( ctl, stream, subFolder );
930 node = g_list_next( node );
938 * Format header block.
939 * Enter: ctl Export control data.
940 * stream Output stream.
943 static void exporthtml_fmt_header(
944 ExportHtmlCtl *ctl, FILE *stream, gchar *title )
946 StylesheetEntry *entry;
948 entry = exporthtml_find_stylesheet( ctl );
951 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">\n" );
952 fprintf( stream, "<html>\n" );
953 fprintf( stream, "<head>\n" );
955 if( ctl->encoding && strlen( ctl->encoding ) > 0 ) {
956 fprintf( stream, "<meta " );
957 fprintf( stream, "http-equiv=\"Content-Type\" " );
958 fprintf( stream, "content=\"text/html; charset=%s\">\n",
962 fprintf( stream, "<title>%s</title>\n", title );
964 if( entry != NULL ) {
965 if( entry->fileName && strlen( entry->fileName ) > 0 ) {
966 fprintf( stream, "<link " );
967 fprintf( stream, "rel=\"stylesheet\" " );
968 fprintf( stream, "type=\"text/css\" " );
969 fprintf( stream, "href=\"%s\" >\n", entry->fileName );
972 fprintf( stream, "<body>\n" );
973 fprintf( stream, "</head>\n" );
977 * ============================================================================
978 * Export address book to HTML file.
979 * Enter: ctl Export control data.
980 * cache Address book/data source cache.
982 * ============================================================================
984 void exporthtml_process(
985 ExportHtmlCtl *ctl, AddressCache *cache )
987 ItemFolder *rootFolder;
993 htmlFile = fopen( ctl->path, "wb" );
995 /* Cannot open file */
996 printf( "Cannot open file for write\n" );
997 ctl->retVal = MGU_OPEN_FILE;
1001 title = _( "Sylpheed Address Book" );
1002 rootFolder = cache->rootFolder;
1003 dsName = cache->name;
1005 exporthtml_fmt_header( ctl, htmlFile, title );
1007 fprintf( htmlFile, "<body>\n" );
1008 fprintf( htmlFile, "<h1>%s</h1>\n", title );
1010 fprintf( htmlFile, "<p class=\"fmt-folder\">" );
1011 fprintf( htmlFile, "%s: ", _( "Address Book" ) );
1012 fprintf( htmlFile, "%s", dsName );
1013 fprintf( htmlFile, "</p>\n" );
1015 exporthtml_fmt_folder( ctl, htmlFile, rootFolder );
1018 fprintf( htmlFile, "<p>%s</p>\n", ctime( &tt ) );
1019 fprintf( htmlFile, "<hr width=\"100%%\"></hr>\n" );
1021 fprintf( htmlFile, "</body>\n" );
1022 fprintf( htmlFile, "</html>\n" );
1025 ctl->retVal = MGU_SUCCESS;
1027 /* Create stylesheet files */
1028 exporthtml_create_css_files( ctl );
1033 * Build full export file specification.
1034 * Enter: ctl Export control data.
1036 static void exporthtml_build_filespec( ExportHtmlCtl *ctl ) {
1039 fileSpec = g_strconcat(
1040 ctl->dirOutput, G_DIR_SEPARATOR_S, ctl->fileHtml, NULL );
1041 ctl->path = mgu_replace_string( ctl->path, fileSpec );
1046 * ============================================================================
1047 * Parse directory and filename from full export file specification.
1048 * Enter: ctl Export control data.
1049 * fileSpec File spec.
1050 * ============================================================================
1052 void exporthtml_parse_filespec( ExportHtmlCtl *ctl, gchar *fileSpec ) {
1056 mgu_replace_string( ctl->fileHtml, g_basename( fileSpec ) );
1057 t = g_dirname( fileSpec );
1058 ctl->dirOutput = mgu_replace_string( ctl->dirOutput, t );
1060 ctl->path = mgu_replace_string( ctl->path, fileSpec );
1064 * ============================================================================
1065 * Test whether directory exists.
1066 * Enter: ctl Export control data.
1067 * Return: TRUE if exists.
1068 * ============================================================================
1070 gboolean exporthtml_test_dir( ExportHtmlCtl *ctl ) {
1075 if((dp = opendir( ctl->dirOutput )) != NULL) {
1083 * ============================================================================
1084 * Create output directory.
1085 * Enter: ctl Export control data.
1086 * Return: TRUE if directory created.
1087 * ============================================================================
1089 gboolean exporthtml_create_dir( ExportHtmlCtl *ctl ) {
1090 gboolean retVal = FALSE;
1093 if( mkdir( ctl->dirOutput, S_IRWXU ) == 0 ) {
1097 ctl->rcCreate = errno;
1103 * ============================================================================
1104 * Retrieve create directory error message.
1105 * Enter: ctl Export control data.
1107 * ============================================================================
1109 gchar *exporthtml_get_create_msg( ExportHtmlCtl *ctl ) {
1112 if( ctl->rcCreate == EEXIST ) {
1113 msg = _( "Name already exists but is not a directory." );
1115 else if( ctl->rcCreate == EACCES ) {
1116 msg = _( "No permissions to create directory." );
1118 else if( ctl->rcCreate == ENAMETOOLONG ) {
1119 msg = _( "Name is too long." );
1122 msg = _( "Not specified." );
1128 * Set default values.
1129 * Enter: ctl Export control data.
1131 static void exporthtml_default_values( ExportHtmlCtl *ctl ) {
1135 g_get_home_dir(), G_DIR_SEPARATOR_S,
1136 DFL_DIR_SYLPHEED_OUT, NULL );
1138 ctl->dirOutput = mgu_replace_string( ctl->dirOutput, str );
1142 mgu_replace_string( ctl->fileHtml, DFL_FILE_SYLPHEED_OUT );
1143 ctl->encoding = NULL;
1144 ctl->stylesheet = EXPORT_HTML_ID_DEFAULT;
1145 ctl->nameFormat = EXPORT_HTML_FIRST_LAST;
1146 ctl->banding = TRUE;
1147 ctl->linkEMail = TRUE;
1148 ctl->showAttribs = TRUE;
1149 ctl->retVal = MGU_SUCCESS;
1153 * ============================================================================
1154 * Load settings from XML properties file.
1155 * Enter: ctl Export control data.
1156 * ============================================================================
1158 void exporthtml_load_settings( ExportHtmlCtl *ctl ) {
1164 props = xmlprops_create();
1165 xmlprops_set_path( props, ctl->settingsFile );
1166 rc = xmlprops_load_file( props );
1169 xmlprops_get_property_s( props, EXMLPROP_DIRECTORY, buf );
1170 ctl->dirOutput = mgu_replace_string( ctl->dirOutput, buf );
1172 xmlprops_get_property_s( props, EXMLPROP_FILE, buf );
1173 ctl->fileHtml = mgu_replace_string( ctl->fileHtml, buf );
1176 xmlprops_get_property_i( props, EXMLPROP_STYLESHEET );
1178 xmlprops_get_property_i( props, EXMLPROP_FMT_NAME );
1180 xmlprops_get_property_b( props, EXMLPROP_BANDING );
1182 xmlprops_get_property_b( props, EXMLPROP_FMT_EMAIL );
1184 xmlprops_get_property_b( props, EXMLPROP_FMT_ATTRIB );
1187 /* Set default values */
1188 exporthtml_default_values( ctl );
1190 exporthtml_build_filespec( ctl );
1191 /* exporthtml_print( ctl, stdout ); */
1193 xmlprops_free( props );
1197 * ============================================================================
1198 * Save settings to XML properties file.
1199 * Enter: ctl Export control data.
1200 * ============================================================================
1202 void exporthtml_save_settings( ExportHtmlCtl *ctl ) {
1205 props = xmlprops_create();
1206 xmlprops_set_path( props, ctl->settingsFile );
1208 xmlprops_set_property( props, EXMLPROP_DIRECTORY, ctl->dirOutput );
1209 xmlprops_set_property( props, EXMLPROP_FILE, ctl->fileHtml );
1210 xmlprops_set_property_i( props, EXMLPROP_STYLESHEET, ctl->stylesheet );
1211 xmlprops_set_property_i( props, EXMLPROP_FMT_NAME, ctl->nameFormat );
1212 xmlprops_set_property_b( props, EXMLPROP_BANDING, ctl->banding );
1213 xmlprops_set_property_b( props, EXMLPROP_FMT_EMAIL, ctl->linkEMail );
1214 xmlprops_set_property_b( props, EXMLPROP_FMT_ATTRIB, ctl->showAttribs );
1215 xmlprops_save_file( props );
1216 xmlprops_free( props );
1220 * ============================================================================
1222 * ============================================================================