2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2002-2007 Match Grun and the Claws Mail team
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * Export address book to HTML file.
34 #include <glib/gi18n.h>
38 #include "exporthtml.h"
41 #ifdef MKDIR_TAKES_ONE_ARG
43 #define mkdir(a,b) mkdir(a)
46 #define DFL_DIR_CLAWS_OUT "claws-mail-out"
47 #define DFL_FILE_CLAWS_OUT "addressbook.html"
49 #define FMT_BUFSIZE 2048
50 #define SC_HTML_SPACE " "
52 #define CELL_PADDING 2
53 #define CELL_SPACING 2
54 #define CHAR_ENCODING "ISO-8859-1"
56 /* Stylesheet names */
57 #define FILENAME_NONE ""
58 #define FILENAME_DEFAULT "claws-mail.css"
59 #define FILENAME_FULL "full.css"
60 #define FILENAME_CUSTOM "custom.css"
61 #define FILENAME_CUSTOM2 "custom2.css"
62 #define FILENAME_CUSTOM3 "custom3.css"
63 #define FILENAME_CUSTOM4 "custom4.css"
65 /* Settings - properties */
66 #define EXML_PROPFILE_NAME "exporthtml.xml"
67 #define EXMLPROP_DIRECTORY "directory"
68 #define EXMLPROP_FILE "file"
69 #define EXMLPROP_STYLESHEET "stylesheet"
70 #define EXMLPROP_FMT_NAME "format-full-name"
71 #define EXMLPROP_FMT_EMAIL "format-email-links"
72 #define EXMLPROP_FMT_ATTRIB "format-attributes"
73 #define EXMLPROP_BANDING "color-banding"
74 #define EXMLPROP_VALUE_YES "y"
75 #define EXMLPROP_VALUE_NO "n"
77 static gchar *_idTagRowEven_ = "tab-row0";
78 static gchar *_idTagRowOdd_ = "tab-row1";
83 typedef struct _StylesheetEntry StylesheetEntry;
84 struct _StylesheetEntry {
91 * Build stylesheet entry.
92 * Enter: ctl Export control data.
97 static void exporthtml_build_entry(
98 ExportHtmlCtl *ctl, const gchar *file, const gint id,
101 StylesheetEntry *entry;
103 entry = g_new0( StylesheetEntry, 1 );
104 entry->fileName = g_strdup( file );
106 entry->dflValue = dfl;
107 ctl->listStyle = g_list_append( ctl->listStyle, entry );
111 * Free up object by releasing internal memory.
112 * Enter: ctl Export control data.
114 ExportHtmlCtl *exporthtml_create( void ) {
115 ExportHtmlCtl *ctl = g_new0( ExportHtmlCtl, 1 );
118 ctl->dirOutput = NULL;
119 ctl->fileHtml = NULL;
120 ctl->encoding = NULL;
121 ctl->stylesheet = EXPORT_HTML_ID_NONE;
122 ctl->nameFormat = EXPORT_HTML_FIRST_LAST;
123 ctl->banding = FALSE;
124 ctl->linkEMail = FALSE;
125 ctl->showAttribs = FALSE;
126 ctl->retVal = MGU_SUCCESS;
127 ctl->listStyle = NULL;
129 ctl->settingsFile = g_strconcat(
130 get_rc_dir(), G_DIR_SEPARATOR_S, EXML_PROPFILE_NAME, NULL );
132 /* Build stylesheet list */
133 exporthtml_build_entry(
134 ctl, FILENAME_NONE, EXPORT_HTML_ID_NONE, FALSE );
135 exporthtml_build_entry(
136 ctl, FILENAME_DEFAULT, EXPORT_HTML_ID_DEFAULT, TRUE );
137 exporthtml_build_entry(
138 ctl, FILENAME_FULL, EXPORT_HTML_ID_FULL, FALSE );
139 exporthtml_build_entry(
140 ctl, FILENAME_CUSTOM, EXPORT_HTML_ID_CUSTOM, FALSE );
141 exporthtml_build_entry(
142 ctl, FILENAME_CUSTOM2, EXPORT_HTML_ID_CUSTOM2, FALSE );
143 exporthtml_build_entry(
144 ctl, FILENAME_CUSTOM3, EXPORT_HTML_ID_CUSTOM3, FALSE );
145 exporthtml_build_entry(
146 ctl, FILENAME_CUSTOM4, EXPORT_HTML_ID_CUSTOM4, FALSE );
152 * Free up object by releasing internal memory.
153 * Enter: ctl Export control data.
155 void exporthtml_free( ExportHtmlCtl *ctl ) {
157 StylesheetEntry *entry;
159 g_return_if_fail( ctl != NULL );
161 /* Free stylesheet list */
162 node = ctl->listStyle;
164 entry = ( StylesheetEntry * ) node->data;
165 g_free( entry->fileName );
166 entry->fileName = NULL;
168 entry->dflValue = FALSE;
171 node = g_list_next( node );
173 g_list_free( ctl->listStyle );
174 ctl->listStyle = NULL;
177 g_free( ctl->fileHtml );
178 g_free( ctl->encoding );
179 g_free( ctl->dirOutput );
180 g_free( ctl->settingsFile );
184 ctl->dirOutput = NULL;
185 ctl->fileHtml = NULL;
186 ctl->encoding = NULL;
187 ctl->stylesheet = EXPORT_HTML_ID_NONE;
188 ctl->nameFormat = EXPORT_HTML_FIRST_LAST;
189 ctl->banding = FALSE;
190 ctl->linkEMail = FALSE;
191 ctl->showAttribs = FALSE;
192 ctl->retVal = MGU_SUCCESS;
195 /* Now release object */
201 * Enter: ctl Export control data.
202 * Return: Stylesheet object, or NULL if nothing found. If a default entry is
203 * found in list, it will be returned.
205 static StylesheetEntry *exporthtml_find_stylesheet( ExportHtmlCtl *ctl ) {
206 StylesheetEntry *retVal = NULL;
207 StylesheetEntry *entry;
210 node = ctl->listStyle;
212 entry = ( StylesheetEntry * ) node->data;
213 if( entry->id == ctl->stylesheet ) return entry;
214 if( entry->dflValue ) retVal = entry;
215 node = g_list_next( node );
220 void exporthtml_set_path( ExportHtmlCtl *ctl, const gchar *value ) {
221 g_return_if_fail( ctl != NULL );
222 ctl->path = mgu_replace_string( ctl->path, value );
223 g_strstrip( ctl->path );
225 void exporthtml_set_file_html( ExportHtmlCtl *ctl, const gchar *value ) {
226 g_return_if_fail( ctl != NULL );
227 ctl->fileHtml = mgu_replace_string( ctl->fileHtml, value );
228 g_strstrip( ctl->fileHtml );
230 void exporthtml_set_encoding( ExportHtmlCtl *ctl, const gchar *value ) {
231 g_return_if_fail( ctl != NULL );
232 ctl->encoding = mgu_replace_string( ctl->encoding, value );
233 g_strstrip( ctl->encoding );
235 void exporthtml_set_stylesheet( ExportHtmlCtl *ctl, const gint value ) {
236 g_return_if_fail( ctl != NULL );
237 ctl->stylesheet = value;
239 void exporthtml_set_name_format( ExportHtmlCtl *ctl, const gint value ) {
240 g_return_if_fail( ctl != NULL );
241 ctl->nameFormat = value;
243 void exporthtml_set_banding( ExportHtmlCtl *ctl, const gboolean value ) {
244 g_return_if_fail( ctl != NULL );
245 ctl->banding = value;
247 void exporthtml_set_link_email( ExportHtmlCtl *ctl, const gboolean value ) {
248 g_return_if_fail( ctl != NULL );
249 ctl->linkEMail = value;
251 void exporthtml_set_attributes( ExportHtmlCtl *ctl, const gboolean value ) {
252 g_return_if_fail( ctl != NULL );
253 ctl->showAttribs = value;
257 * Create default CSS file.
258 * Enter: fileSpec File to create.
259 * Return: Status code.
261 static gint exporthtml_create_css_dfl( const gchar *fileSpec ) {
264 cssFile = g_fopen( fileSpec, "rb" );
269 cssFile = g_fopen( fileSpec, "wb" );
271 return MGU_OPEN_FILE;
274 fprintf( cssFile, "body {\n\tbackground: #ffffe0;\n" );
275 fprintf( cssFile, "\tfont-family: lucida, helvetica, sans-serif;\n" );
276 fprintf( cssFile, "\tfont-size: 10pt;\n" );
277 fprintf( cssFile, "}\n" );
278 fprintf( cssFile, "h1 {\n" );
279 fprintf( cssFile, "\tcolor: #000000;\n" );
280 fprintf( cssFile, "\ttext-align: center;\n" );
281 fprintf( cssFile, "}\n" );
282 fprintf( cssFile, "th {\n" );
283 fprintf( cssFile, "\tfont-size: 10pt;\n" );
284 fprintf( cssFile, "}\n" );
285 fprintf( cssFile, "td {\n" );
286 fprintf( cssFile, "\tfont-size: 10pt;\n" );
287 fprintf( cssFile, "}\n" );
288 fprintf( cssFile, ".fmt-folder {\n" );
289 fprintf( cssFile, "\tcolor: #0000ff;\n" );
290 fprintf( cssFile, "\tfont-size: 18pt;\n" );
291 fprintf( cssFile, "\tfont-weight: bold;\n" );
292 fprintf( cssFile, "}\n" );
293 fprintf( cssFile, ".tab-head {\n" );
294 fprintf( cssFile, "\tbackground: #80c0f0;\n" );
295 fprintf( cssFile, "}\n" );
296 fprintf( cssFile, ".tab-dn {\n" );
297 fprintf( cssFile, "}\n" );
298 fprintf( cssFile, ".tab-addr {\n" );
299 fprintf( cssFile, "\tfont-style: italic;\n" );
300 fprintf( cssFile, "}\n" );
301 fprintf( cssFile, ".tab-email {\n" );
302 fprintf( cssFile, "\tfont-weight: bold;\n" );
303 fprintf( cssFile, "\tfont-style: italic;\n" );
304 fprintf( cssFile, "}\n" );
305 fprintf( cssFile, ".tab-fn {\n" );
306 fprintf( cssFile, "}\n" );
307 fprintf( cssFile, ".tab-attr {\n" );
308 fprintf( cssFile, "}\n" );
315 * Create full CSS file.
316 * Enter: fileSpec File to create.
317 * Return: Status code.
319 static gint exporthtml_create_css_full( const gchar *fileSpec ) {
322 cssFile = g_fopen( fileSpec, "rb" );
327 cssFile = g_fopen( fileSpec, "wb" );
329 return MGU_OPEN_FILE;
332 fprintf( cssFile, "body {\n\tbackground: #ffffe0;\n" );
333 fprintf( cssFile, "\tfont-family: lucida, helvetica, sans-serif;\n" );
334 fprintf( cssFile, "\tfont-size: 10pt;\n" );
335 fprintf( cssFile, "}\n" );
336 fprintf( cssFile, "h1 {\n" );
337 fprintf( cssFile, "\tcolor: #000000;\n" );
338 fprintf( cssFile, "\ttext-align: center;\n" );
339 fprintf( cssFile, "}\n" );
340 fprintf( cssFile, "th {\n" );
341 fprintf( cssFile, "\tfont-size: 10pt;\n" );
342 fprintf( cssFile, "}\n" );
343 fprintf( cssFile, "td {\n" );
344 fprintf( cssFile, "\tfont-size: 10pt;\n" );
345 fprintf( cssFile, "}\n" );
346 fprintf( cssFile, ".fmt-folder {\n" );
347 fprintf( cssFile, "\tcolor: #0000ff;\n" );
348 fprintf( cssFile, "\tfont-size: 18pt;\n" );
349 fprintf( cssFile, "\tfont-weight: bold;\n" );
350 fprintf( cssFile, "}\n" );
351 fprintf( cssFile, ".tab-head {\n" );
352 fprintf( cssFile, "\tbackground: #80c0f0;\n" );
353 fprintf( cssFile, "}\n" );
354 fprintf( cssFile, ".tab-row0 {\n" );
355 fprintf( cssFile, "\tbackground: #f0f0f0;\n" );
356 fprintf( cssFile, "}\n" );
357 fprintf( cssFile, ".tab-row1 {\n" );
358 fprintf( cssFile, "\tbackground: #d0d0d0;\n" );
359 fprintf( cssFile, "}\n" );
360 fprintf( cssFile, ".tab-dn {\n" );
361 fprintf( cssFile, "}\n" );
362 fprintf( cssFile, ".tab-addr {\n" );
363 fprintf( cssFile, "\tfont-style: italic;\n" );
364 fprintf( cssFile, "}\n" );
365 fprintf( cssFile, ".tab-email {\n" );
366 fprintf( cssFile, "\tfont-weight: bold;\n" );
367 fprintf( cssFile, "\tfont-style: italic;\n" );
368 fprintf( cssFile, "}\n" );
369 fprintf( cssFile, ".tab-fn {\n" );
370 fprintf( cssFile, "}\n" );
371 fprintf( cssFile, ".tab-attr {\n" );
372 fprintf( cssFile, "}\n" );
379 * Create stylesheet files.
380 * Enter: ctl Export control data.
382 static void exporthtml_create_css_files( ExportHtmlCtl *ctl ) {
386 node = ctl->listStyle;
388 StylesheetEntry *entry = node->data;
389 node = g_list_next( node );
390 if( strlen( entry->fileName ) ) {
391 fileSpec = g_strconcat(
392 ctl->dirOutput, G_DIR_SEPARATOR_S,
393 entry->fileName, NULL );
394 if( entry->id == EXPORT_HTML_ID_DEFAULT ) {
395 exporthtml_create_css_dfl( fileSpec );
397 else if( entry->id != EXPORT_HTML_ID_NONE ) {
398 exporthtml_create_css_full( fileSpec );
406 * Comparison using linked list elements.
408 static gint exporthtml_compare_name(
409 gconstpointer ptr1, gconstpointer ptr2 )
411 const AddrItemObject *item1 = ptr1;
412 const AddrItemObject *item2 = ptr2;
413 const gchar *name1 = NULL, *name2 = NULL;
414 if( item1 ) name1 = ADDRITEM_NAME( item1 );
415 if( item2 ) name2 = ADDRITEM_NAME( item2 );
416 if( ! name1 ) return ( name2 != NULL );
417 if( ! name2 ) return -1;
418 return g_utf8_collate( name1, name2 );
422 * Comparison using linked list elements.
424 static gint exporthtml_compare_email(
425 gconstpointer ptr1, gconstpointer ptr2 )
427 const ItemEMail *email1 = ptr1;
428 const ItemEMail *email2 = ptr2;
429 const gchar *name1 = NULL, *name2 = NULL;
430 if( email1 ) name1 = email1->address;
431 if( email2 ) name2 = email2->address;
432 if( ! name1 ) return ( name2 != NULL );
433 if( ! name2 ) return -1;
434 return g_utf8_collate( name1, name2 );
438 * Comparison using linked list elements.
440 static gint exporthtml_compare_attrib(
441 gconstpointer ptr1, gconstpointer ptr2 )
443 const UserAttribute *attr1 = ptr1;
444 const UserAttribute *attr2 = ptr2;
445 const gchar *name1 = NULL, *name2 = NULL;
446 if( attr1 ) name1 = attr1->name;
447 if( attr2 ) name2 = attr2->name;
448 if( ! name1 ) return ( name2 != NULL );
449 if( ! name2 ) return -1;
450 return g_utf8_collate( name1, name2 );
454 * Build sorted list of named items.
455 * Enter: list List of items to sorted.
456 * Return: Sorted list.
457 * Note: List should freed after use. Items referenced by list should not be
458 * freed since they are managed by the address cache.
460 static GList *exporthtml_sort_name( const GList *list ) {
462 GList *sorted = NULL;
466 sorted = g_list_insert_sorted(
467 sorted, node->data, exporthtml_compare_name );
468 node = g_list_next( node );
474 * Build sorted list of email items.
475 * Enter: list List of E-Mail items to sorted.
476 * Return: Sorted list.
477 * Note: List should freed after use. Items referenced by list should not be
478 * freed since they are managed by the address cache.
480 static GList *exporthtml_sort_email( const GList *list ) {
482 GList *sorted = NULL;
486 sorted = g_list_insert_sorted(
487 sorted, node->data, exporthtml_compare_email );
488 node = g_list_next( node );
494 * Build sorted list of attributes.
495 * Enter: list List of items to sorted.
496 * Return: Sorted list.
497 * Note: List should freed after use. Items referenced by list should not be
498 * freed since they are managed by the address cache.
500 static GList *exporthtml_sort_attrib( const GList *list ) {
502 GList *sorted = NULL;
507 sorted = g_list_insert_sorted(
508 sorted, node->data, exporthtml_compare_attrib );
509 node = g_list_next( node );
515 * Format a list of E-Mail addresses.
516 * Enter: ctl Export control data.
517 * stream Output stream.
518 * listEMail List of addresses.
519 * sortFlag Set to TRUE if address list should be sorted.
521 static void exporthtml_fmt_email(
522 ExportHtmlCtl *ctl, FILE *stream, const GList *listEMail,
529 if( listEMail == NULL ) {
530 fprintf( stream, SC_HTML_SPACE );
536 node = list = exporthtml_sort_email( listEMail );
543 ItemEMail *email = ( ItemEMail * ) node->data;
544 node = g_list_next( node );
546 name = ADDRITEM_NAME( email );
548 fprintf( stream, "%s ", name );
550 if( ctl->linkEMail ) {
551 fprintf( stream, "<a href=\"mailto:%s\">",
554 fprintf( stream, "<span class=\"tab-email\">" );
555 fprintf( stream, "%s", email->address );
556 fprintf( stream, "</span>" );
557 if( ctl->linkEMail ) {
558 fprintf( stream, "</a>" );
560 if( email->remarks ) {
561 if( strlen( email->remarks ) ) {
562 fprintf( stream, " (%s)", email->remarks );
565 fprintf( stream, "<br>\n" );
571 * Format groups in an address book folder.
572 * Enter: ctl Export control data.
573 * stream Output stream.
575 * prevFlag If FALSE, list of persons were output.
576 * Return: TRUE if no groups were formatted.
578 static gboolean exporthtml_fmt_group(
579 ExportHtmlCtl *ctl, FILE *stream, const ItemFolder *folder,
582 gboolean retVal, band;
584 const gchar *tagName;
587 if( folder->listGroup == NULL ) return retVal;
589 /* Write separator */
591 fprintf( stream, "<br>\n" );
594 /* Write table headers */
595 fprintf( stream, "<table" );
596 fprintf( stream, " border=\"%d\"", BORDER_SIZE );
597 fprintf( stream, " cellpadding=\"%d\"", CELL_PADDING );
598 fprintf( stream, " cellspacing=\"%d\"", CELL_SPACING );
599 fprintf( stream, ">\n" );
601 fprintf( stream, "<tr class=\"tab-head\">\n" );
602 fprintf( stream, " <th width=\"200\">" );
603 fprintf( stream, "%s", _( "Group Name" ) );
604 fprintf( stream, "</th>\n" );
605 fprintf( stream, " <th width=\"300\">" );
606 fprintf( stream, "%s", _( "Email Address" ) );
607 fprintf( stream, "</th>\n" );
608 fprintf( stream, "</tr>\n" );
609 list = exporthtml_sort_name( folder->listGroup );
614 AddrItemObject *aio = node->data;
615 if( aio && aio->type == ITEMTYPE_GROUP ) {
616 ItemGroup *group = ( ItemGroup * ) aio;
618 fprintf( stream, "<tr valign=\"top\"" );
621 tagName = _idTagRowOdd_;
624 tagName = _idTagRowEven_;
626 fprintf( stream, " class=\"%s\"", tagName );
629 fprintf( stream, "\">\n" );
631 fprintf( stream, " <td class=\"tab-dn\">" );
632 fprintf( stream, "%s", ADDRITEM_NAME( group ) );
633 fprintf( stream, "</td>\n" );
634 fprintf( stream, " <td class=\"tab-addr\">" );
635 exporthtml_fmt_email( ctl, stream, group->listEMail, TRUE );
636 fprintf( stream, "</td>\n" );
637 fprintf( stream, "</tr>\n" );
640 node = g_list_next( node );
644 fprintf( stream, "</table>\n" );
649 * Format a list of E-Mail addresses.
650 * Enter: ctl Export control data.
651 * stream Output stream.
652 * listAttr List of attributes.
654 static void exporthtml_fmt_attribs(
655 ExportHtmlCtl *ctl, FILE *stream, const GList *listAttr )
660 if( listAttr == NULL ) {
661 fprintf( stream, SC_HTML_SPACE );
665 fprintf( stream, "<table border=\"0\">\n" );
666 node = list = exporthtml_sort_attrib( listAttr );
668 UserAttribute *attr = ( UserAttribute * ) node->data;
669 node = g_list_next( node );
670 fprintf( stream, "<tr valign=\"top\">" );
671 fprintf( stream, "<td align=\"right\">%s:</td>", attr->name );
672 fprintf( stream, "<td>%s</td>", attr->value );
673 fprintf( stream, "</tr>\n" );
677 fprintf( stream, "</table>" );
682 * Enter: ctl Export control data.
684 * person Person to format.
686 static void exporthtml_fmt_fullname(
687 ExportHtmlCtl *ctl, gchar *buf, const ItemPerson *person )
691 if( ctl->nameFormat == EXPORT_HTML_LAST_FIRST ) {
693 if( person->lastName ) {
694 if( *person->lastName ) {
696 strcat( buf, person->lastName );
700 if( person->firstName ) {
701 if( *person->firstName ) {
705 strcat( buf, person->firstName );
710 if( person->firstName ) {
711 if( *person->firstName ) {
712 strcat( buf, person->firstName );
715 if( person->lastName ) {
716 if( *person->lastName ) {
718 strcat( buf, person->lastName );
725 if( *buf ) flag = TRUE;
726 if( person->nickName ) {
727 if( strlen( person->nickName ) ) {
731 strcat( buf, person->nickName );
741 * Format persons in an address book folder.
742 * Enter: ctl Export control data.
743 * stream Output stream.
745 * Return: TRUE if no persons were formatted.
747 static gboolean exporthtml_fmt_person(
748 ExportHtmlCtl *ctl, FILE *stream, const ItemFolder *folder )
750 gboolean retVal, band;
752 gchar buf[ FMT_BUFSIZE ];
753 const gchar *tagName;
756 if( folder->listPerson == NULL ) return retVal;
758 /* Write table headers */
759 fprintf( stream, "<table" );
760 fprintf( stream, " border=\"%d\"", BORDER_SIZE );
761 fprintf( stream, " cellpadding=\"%d\"", CELL_PADDING );
762 fprintf( stream, " cellspacing=\"%d\"", CELL_SPACING );
763 fprintf( stream, ">\n" );
765 fprintf( stream, "<tr class=\"tab-head\">\n" );
766 fprintf( stream, " <th width=\"200\">" );
767 fprintf( stream, "%s", _( "Display Name" ) );
768 fprintf( stream, "</th>\n" );
769 fprintf( stream, " <th width=\"300\">" );
770 fprintf( stream, "%s", _( "Email Address" ) );
771 fprintf( stream, "</th>\n" );
772 fprintf( stream, " <th width=\"200\">" );
773 fprintf( stream, "%s", _( "Full Name" ) );
774 fprintf( stream, "</th>\n" );
775 if( ctl->showAttribs ) {
776 fprintf( stream, " <th width=\"250\">" );
777 fprintf( stream, "%s", _( "Attributes" ) );
778 fprintf( stream, "</th>\n" );
780 fprintf( stream, "</tr>\n" );
783 node = list = exporthtml_sort_name( folder->listPerson );
785 AddrItemObject *aio = node->data;
786 if( aio && aio->type == ITEMTYPE_PERSON ) {
787 ItemPerson *person = ( ItemPerson * ) aio;
789 /* Format first/last/nick name */
791 exporthtml_fmt_fullname( ctl, buf,person );
793 fprintf( stream, "<tr valign=\"top\"" );
796 tagName = _idTagRowOdd_;
799 tagName = _idTagRowEven_;
801 fprintf( stream, " class=\"%s\"", tagName );
804 fprintf( stream, ">\n" );
806 fprintf( stream, " <td class=\"tab-dn\">" );
807 fprintf( stream, "%s", ADDRITEM_NAME( person ) );
808 fprintf( stream, "</td>\n" );
810 fprintf( stream, " <td class=\"tab-addr\">" );
811 exporthtml_fmt_email( ctl, stream, person->listEMail, FALSE );
812 fprintf( stream, "</td>\n" );
814 fprintf( stream, " <td class=\"tab-fn\">" );
816 fprintf( stream, "%s", buf );
819 fprintf( stream, "%s", SC_HTML_SPACE );
821 fprintf( stream, "</td>\n" );
823 if( ctl->showAttribs ) {
824 fprintf( stream, " <td class=\"tab-attr\">" );
825 exporthtml_fmt_attribs(
826 ctl, stream, person->listAttrib );
827 fprintf( stream, "</td>\n" );
829 fprintf( stream, "</tr>\n" );
833 node = g_list_next( node );
837 fprintf( stream, "</table>\n" );
842 * Format folder heirarchy.
843 * Enter: stream Output stream.
844 * list Heirarchy list.
846 static void exporthtml_fmt_folderhead( FILE *stream, const GList *list ) {
854 AddrItemObject *aio = node->data;
855 if( aio && aio->type == ITEMTYPE_FOLDER ) {
856 ItemFolder *folder = ( ItemFolder * ) aio;
858 name = ADDRITEM_NAME( folder );
861 fprintf( stream, " > " );
863 fprintf( stream, "%s", name );
867 node = g_list_next( node );
872 * Format an address book folder.
873 * Enter: ctl Export control data.
874 * stream Output stream.
877 static void exporthtml_fmt_folder(
878 ExportHtmlCtl *ctl, FILE *stream, const ItemFolder *folder )
881 GList *listHeir, *list;
885 name = ADDRITEM_NAME( folder );
887 listHeir = addritem_folder_path( folder, TRUE );
889 fprintf( stream, "<p class=\"fmt-folder\">" );
890 fprintf( stream, "%s: ", _( "Folder" ) );
891 exporthtml_fmt_folderhead( stream, listHeir );
892 fprintf( stream, "</p>\n" );
893 g_list_free( listHeir );
897 ret1 = exporthtml_fmt_person( ctl, stream, folder );
898 ret2 = exporthtml_fmt_group( ctl, stream, folder, ret1 );
900 node = list = exporthtml_sort_name( folder->listFolder );
902 AddrItemObject *aio = node->data;
903 if( aio && aio->type == ITEMTYPE_FOLDER ) {
904 ItemFolder *subFolder = ( ItemFolder * ) aio;
905 exporthtml_fmt_folder( ctl, stream, subFolder );
907 node = g_list_next( node );
915 * Format header block.
916 * Enter: ctl Export control data.
917 * stream Output stream.
920 static void exporthtml_fmt_header(
921 ExportHtmlCtl *ctl, FILE *stream, gchar *title )
923 StylesheetEntry *entry;
925 entry = exporthtml_find_stylesheet( ctl );
928 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">\n" );
929 fprintf( stream, "<html>\n" );
930 fprintf( stream, "<head>\n" );
932 if( ctl->encoding && strlen( ctl->encoding ) > 0 ) {
933 fprintf( stream, "<meta " );
934 fprintf( stream, "http-equiv=\"Content-Type\" " );
935 fprintf( stream, "content=\"text/html; charset=%s\">\n",
939 fprintf( stream, "<title>%s</title>\n", title );
941 if( entry != NULL ) {
942 if( entry->fileName && strlen( entry->fileName ) > 0 ) {
943 fprintf( stream, "<link " );
944 fprintf( stream, "rel=\"stylesheet\" " );
945 fprintf( stream, "type=\"text/css\" " );
946 fprintf( stream, "href=\"%s\" >\n", entry->fileName );
949 fprintf( stream, "<body>\n" );
950 fprintf( stream, "</head>\n" );
954 * ============================================================================
955 * Export address book to HTML file.
956 * Enter: ctl Export control data.
957 * cache Address book/data source cache.
959 * ============================================================================
961 void exporthtml_process(
962 ExportHtmlCtl *ctl, AddressCache *cache )
964 ItemFolder *rootFolder;
970 htmlFile = g_fopen( ctl->path, "wb" );
972 /* Cannot open file */
973 printf( "Cannot open file for write\n" );
974 ctl->retVal = MGU_OPEN_FILE;
978 title = _( "Claws Mail Address Book" );
979 rootFolder = cache->rootFolder;
980 dsName = cache->name;
982 exporthtml_fmt_header( ctl, htmlFile, title );
984 fprintf( htmlFile, "<body>\n" );
985 fprintf( htmlFile, "<h1>%s</h1>\n", title );
987 fprintf( htmlFile, "<p class=\"fmt-folder\">" );
988 fprintf( htmlFile, "%s: ", _( "Address Book" ) );
989 fprintf( htmlFile, "%s", dsName );
990 fprintf( htmlFile, "</p>\n" );
992 exporthtml_fmt_folder( ctl, htmlFile, rootFolder );
995 fprintf( htmlFile, "<p>%s</p>\n", ctime( &tt ) );
996 fprintf( htmlFile, "<hr width=\"100%%\"></hr>\n" );
998 fprintf( htmlFile, "</body>\n" );
999 fprintf( htmlFile, "</html>\n" );
1002 ctl->retVal = MGU_SUCCESS;
1004 /* Create stylesheet files */
1005 exporthtml_create_css_files( ctl );
1010 * Build full export file specification.
1011 * Enter: ctl Export control data.
1013 static void exporthtml_build_filespec( ExportHtmlCtl *ctl ) {
1016 fileSpec = g_strconcat(
1017 ctl->dirOutput, G_DIR_SEPARATOR_S, ctl->fileHtml, NULL );
1018 ctl->path = mgu_replace_string( ctl->path, fileSpec );
1023 * ============================================================================
1024 * Parse directory and filename from full export file specification.
1025 * Enter: ctl Export control data.
1026 * fileSpec File spec.
1027 * ============================================================================
1029 void exporthtml_parse_filespec( ExportHtmlCtl *ctl, gchar *fileSpec ) {
1031 gchar *base = g_path_get_basename(fileSpec);
1034 mgu_replace_string( ctl->fileHtml, base );
1036 t = g_path_get_dirname( fileSpec );
1037 ctl->dirOutput = mgu_replace_string( ctl->dirOutput, t );
1039 ctl->path = mgu_replace_string( ctl->path, fileSpec );
1043 * ============================================================================
1044 * Test whether directory exists.
1045 * Enter: ctl Export control data.
1046 * Return: TRUE if exists.
1047 * ============================================================================
1049 gboolean exporthtml_test_dir( ExportHtmlCtl *ctl ) {
1054 if((dp = opendir( ctl->dirOutput )) != NULL) {
1062 * ============================================================================
1063 * Create output directory.
1064 * Enter: ctl Export control data.
1065 * Return: TRUE if directory created.
1066 * ============================================================================
1068 gboolean exporthtml_create_dir( ExportHtmlCtl *ctl ) {
1069 gboolean retVal = FALSE;
1072 if( mkdir( ctl->dirOutput, S_IRWXU ) == 0 ) {
1076 ctl->rcCreate = errno;
1082 * ============================================================================
1083 * Retrieve create directory error message.
1084 * Enter: ctl Export control data.
1086 * ============================================================================
1088 gchar *exporthtml_get_create_msg( ExportHtmlCtl *ctl ) {
1091 if( ctl->rcCreate == EEXIST ) {
1092 msg = _( "Name already exists but is not a directory." );
1094 else if( ctl->rcCreate == EACCES ) {
1095 msg = _( "No permissions to create directory." );
1097 else if( ctl->rcCreate == ENAMETOOLONG ) {
1098 msg = _( "Name is too long." );
1101 msg = _( "Not specified." );
1107 * Set default values.
1108 * Enter: ctl Export control data.
1110 static void exporthtml_default_values( ExportHtmlCtl *ctl ) {
1114 get_home_dir(), G_DIR_SEPARATOR_S,
1115 DFL_DIR_CLAWS_OUT, NULL );
1117 ctl->dirOutput = mgu_replace_string( ctl->dirOutput, str );
1121 mgu_replace_string( ctl->fileHtml, DFL_FILE_CLAWS_OUT );
1122 ctl->encoding = NULL;
1123 ctl->stylesheet = EXPORT_HTML_ID_DEFAULT;
1124 ctl->nameFormat = EXPORT_HTML_FIRST_LAST;
1125 ctl->banding = TRUE;
1126 ctl->linkEMail = TRUE;
1127 ctl->showAttribs = TRUE;
1128 ctl->retVal = MGU_SUCCESS;
1132 * ============================================================================
1133 * Load settings from XML properties file.
1134 * Enter: ctl Export control data.
1135 * ============================================================================
1137 void exporthtml_load_settings( ExportHtmlCtl *ctl ) {
1143 props = xmlprops_create();
1144 xmlprops_set_path( props, ctl->settingsFile );
1145 rc = xmlprops_load_file( props );
1148 xmlprops_get_property_s( props, EXMLPROP_DIRECTORY, buf );
1149 ctl->dirOutput = mgu_replace_string( ctl->dirOutput, buf );
1151 xmlprops_get_property_s( props, EXMLPROP_FILE, buf );
1152 ctl->fileHtml = mgu_replace_string( ctl->fileHtml, buf );
1155 xmlprops_get_property_i( props, EXMLPROP_STYLESHEET );
1157 xmlprops_get_property_i( props, EXMLPROP_FMT_NAME );
1159 xmlprops_get_property_b( props, EXMLPROP_BANDING );
1161 xmlprops_get_property_b( props, EXMLPROP_FMT_EMAIL );
1163 xmlprops_get_property_b( props, EXMLPROP_FMT_ATTRIB );
1166 /* Set default values */
1167 exporthtml_default_values( ctl );
1169 exporthtml_build_filespec( ctl );
1170 /* exporthtml_print( ctl, stdout ); */
1172 xmlprops_free( props );
1176 * ============================================================================
1177 * Save settings to XML properties file.
1178 * Enter: ctl Export control data.
1179 * ============================================================================
1181 void exporthtml_save_settings( ExportHtmlCtl *ctl ) {
1184 props = xmlprops_create();
1185 xmlprops_set_path( props, ctl->settingsFile );
1187 xmlprops_set_property( props, EXMLPROP_DIRECTORY, ctl->dirOutput );
1188 xmlprops_set_property( props, EXMLPROP_FILE, ctl->fileHtml );
1189 xmlprops_set_property_i( props, EXMLPROP_STYLESHEET, ctl->stylesheet );
1190 xmlprops_set_property_i( props, EXMLPROP_FMT_NAME, ctl->nameFormat );
1191 xmlprops_set_property_b( props, EXMLPROP_BANDING, ctl->banding );
1192 xmlprops_set_property_b( props, EXMLPROP_FMT_EMAIL, ctl->linkEMail );
1193 xmlprops_set_property_b( props, EXMLPROP_FMT_ATTRIB, ctl->showAttribs );
1194 xmlprops_save_file( props );
1195 xmlprops_free( props );
1199 * ============================================================================
1201 * ============================================================================