2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 2002-2024 the Claws Mail team and 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 3 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, see <http://www.gnu.org/licenses/>.
20 * Export address book to HTML file.
25 #include "claws-features.h"
37 #include <glib/gi18n.h>
41 #include "exporthtml.h"
43 #include "file-utils.h"
45 #define DFL_DIR_CLAWS_OUT "claws-mail-out"
46 #define DFL_FILE_CLAWS_OUT "addressbook.html"
48 #define FMT_BUFSIZE 2048
49 #define SC_HTML_SPACE " "
51 #define CELL_PADDING 2
52 #define CELL_SPACING 2
53 #define CHAR_ENCODING "UTF-8"
55 /* Stylesheet names */
56 #define FILENAME_NONE ""
57 #define FILENAME_DEFAULT "claws-mail.css"
58 #define FILENAME_FULL "full.css"
59 #define FILENAME_CUSTOM "custom.css"
60 #define FILENAME_CUSTOM2 "custom2.css"
61 #define FILENAME_CUSTOM3 "custom3.css"
62 #define FILENAME_CUSTOM4 "custom4.css"
64 /* Settings - properties */
65 #define EXML_PROPFILE_NAME "exporthtml.xml"
66 #define EXMLPROP_DIRECTORY "directory"
67 #define EXMLPROP_FILE "file"
68 #define EXMLPROP_STYLESHEET "stylesheet"
69 #define EXMLPROP_FMT_NAME "format-full-name"
70 #define EXMLPROP_FMT_EMAIL "format-email-links"
71 #define EXMLPROP_FMT_ATTRIB "format-attributes"
72 #define EXMLPROP_BANDING "color-banding"
73 #define EXMLPROP_VALUE_YES "y"
74 #define EXMLPROP_VALUE_NO "n"
76 static gchar
*_idTagRowEven_
= "tab-row0";
77 static gchar
*_idTagRowOdd_
= "tab-row1";
82 typedef struct _StylesheetEntry StylesheetEntry
;
83 struct _StylesheetEntry
{
90 * Build stylesheet entry.
91 * Enter: ctl Export control data.
96 static void exporthtml_build_entry(
97 ExportHtmlCtl
*ctl
, const gchar
*file
, const gint id
,
100 StylesheetEntry
*entry
;
102 entry
= g_new0( StylesheetEntry
, 1 );
103 entry
->fileName
= g_strdup( file
);
105 entry
->dflValue
= dfl
;
106 ctl
->listStyle
= g_list_append( ctl
->listStyle
, entry
);
110 * Free up object by releasing internal memory.
111 * Enter: ctl Export control data.
113 ExportHtmlCtl
*exporthtml_create( void ) {
114 ExportHtmlCtl
*ctl
= g_new0( ExportHtmlCtl
, 1 );
117 ctl
->dirOutput
= NULL
;
118 ctl
->fileHtml
= NULL
;
119 ctl
->encoding
= g_strconcat(CHAR_ENCODING
, NULL
);
120 ctl
->stylesheet
= EXPORT_HTML_ID_NONE
;
121 ctl
->nameFormat
= EXPORT_HTML_FIRST_LAST
;
122 ctl
->banding
= FALSE
;
123 ctl
->linkEMail
= FALSE
;
124 ctl
->showAttribs
= FALSE
;
125 ctl
->retVal
= MGU_SUCCESS
;
126 ctl
->listStyle
= NULL
;
128 ctl
->settingsFile
= g_strconcat(
129 get_rc_dir(), G_DIR_SEPARATOR_S
, EXML_PROPFILE_NAME
, NULL
);
131 /* Build stylesheet list */
132 exporthtml_build_entry(
133 ctl
, FILENAME_NONE
, EXPORT_HTML_ID_NONE
, FALSE
);
134 exporthtml_build_entry(
135 ctl
, FILENAME_DEFAULT
, EXPORT_HTML_ID_DEFAULT
, TRUE
);
136 exporthtml_build_entry(
137 ctl
, FILENAME_FULL
, EXPORT_HTML_ID_FULL
, FALSE
);
138 exporthtml_build_entry(
139 ctl
, FILENAME_CUSTOM
, EXPORT_HTML_ID_CUSTOM
, FALSE
);
140 exporthtml_build_entry(
141 ctl
, FILENAME_CUSTOM2
, EXPORT_HTML_ID_CUSTOM2
, FALSE
);
142 exporthtml_build_entry(
143 ctl
, FILENAME_CUSTOM3
, EXPORT_HTML_ID_CUSTOM3
, FALSE
);
144 exporthtml_build_entry(
145 ctl
, FILENAME_CUSTOM4
, EXPORT_HTML_ID_CUSTOM4
, FALSE
);
151 * Free up object by releasing internal memory.
152 * Enter: ctl Export control data.
154 void exporthtml_free( ExportHtmlCtl
*ctl
) {
156 StylesheetEntry
*entry
;
158 cm_return_if_fail( ctl
!= NULL
);
160 /* Free stylesheet list */
161 node
= ctl
->listStyle
;
163 entry
= ( StylesheetEntry
* ) node
->data
;
164 g_free( entry
->fileName
);
165 entry
->fileName
= NULL
;
167 entry
->dflValue
= FALSE
;
170 node
= g_list_next( node
);
172 g_list_free( ctl
->listStyle
);
173 ctl
->listStyle
= NULL
;
176 g_free( ctl
->fileHtml
);
177 g_free( ctl
->encoding
);
178 g_free( ctl
->dirOutput
);
179 g_free( ctl
->settingsFile
);
183 ctl
->dirOutput
= NULL
;
184 ctl
->fileHtml
= NULL
;
185 ctl
->encoding
= NULL
;
186 ctl
->stylesheet
= EXPORT_HTML_ID_NONE
;
187 ctl
->nameFormat
= EXPORT_HTML_FIRST_LAST
;
188 ctl
->banding
= FALSE
;
189 ctl
->linkEMail
= FALSE
;
190 ctl
->showAttribs
= FALSE
;
191 ctl
->retVal
= MGU_SUCCESS
;
194 /* Now release object */
200 * Enter: ctl Export control data.
201 * Return: Stylesheet object, or NULL if nothing found. If a default entry is
202 * found in list, it will be returned.
204 static StylesheetEntry
*exporthtml_find_stylesheet( ExportHtmlCtl
*ctl
) {
205 StylesheetEntry
*retVal
= NULL
;
206 StylesheetEntry
*entry
;
209 node
= ctl
->listStyle
;
211 entry
= ( StylesheetEntry
* ) node
->data
;
212 if( entry
->id
== ctl
->stylesheet
) return entry
;
213 if( entry
->dflValue
) retVal
= entry
;
214 node
= g_list_next( node
);
219 void exporthtml_set_stylesheet( ExportHtmlCtl
*ctl
, const gint value
) {
220 cm_return_if_fail( ctl
!= NULL
);
221 ctl
->stylesheet
= value
;
223 void exporthtml_set_name_format( ExportHtmlCtl
*ctl
, const gint value
) {
224 cm_return_if_fail( ctl
!= NULL
);
225 ctl
->nameFormat
= value
;
227 void exporthtml_set_banding( ExportHtmlCtl
*ctl
, const gboolean value
) {
228 cm_return_if_fail( ctl
!= NULL
);
229 ctl
->banding
= value
;
231 void exporthtml_set_link_email( ExportHtmlCtl
*ctl
, const gboolean value
) {
232 cm_return_if_fail( ctl
!= NULL
);
233 ctl
->linkEMail
= value
;
235 void exporthtml_set_attributes( ExportHtmlCtl
*ctl
, const gboolean value
) {
236 cm_return_if_fail( ctl
!= NULL
);
237 ctl
->showAttribs
= value
;
241 * Create default CSS file.
242 * Enter: fileSpec File to create.
243 * Return: Status code.
245 static gint
exporthtml_create_css_dfl( const gchar
*fileSpec
) {
248 cssFile
= claws_fopen( fileSpec
, "rb" );
250 claws_fclose( cssFile
);
253 cssFile
= claws_fopen( fileSpec
, "wb" );
255 return MGU_OPEN_FILE
;
258 fprintf( cssFile
, "body {\n\tbackground: #ffffe0;\n" );
259 fprintf( cssFile
, "\tfont-family: lucida, helvetica, sans-serif;\n" );
260 fprintf( cssFile
, "\tfont-size: 10pt;\n" );
261 fprintf( cssFile
, "}\n" );
262 fprintf( cssFile
, "h1 {\n" );
263 fprintf( cssFile
, "\tcolor: #000000;\n" );
264 fprintf( cssFile
, "\ttext-align: center;\n" );
265 fprintf( cssFile
, "}\n" );
266 fprintf( cssFile
, "th {\n" );
267 fprintf( cssFile
, "\tfont-size: 10pt;\n" );
268 fprintf( cssFile
, "}\n" );
269 fprintf( cssFile
, "td {\n" );
270 fprintf( cssFile
, "\tfont-size: 10pt;\n" );
271 fprintf( cssFile
, "}\n" );
272 fprintf( cssFile
, ".fmt-folder {\n" );
273 fprintf( cssFile
, "\tcolor: #0000ff;\n" );
274 fprintf( cssFile
, "\tfont-size: 18pt;\n" );
275 fprintf( cssFile
, "\tfont-weight: bold;\n" );
276 fprintf( cssFile
, "}\n" );
277 fprintf( cssFile
, ".tab-head {\n" );
278 fprintf( cssFile
, "\tbackground: #80c0f0;\n" );
279 fprintf( cssFile
, "}\n" );
280 fprintf( cssFile
, ".tab-dn {\n" );
281 fprintf( cssFile
, "}\n" );
282 fprintf( cssFile
, ".tab-addr {\n" );
283 fprintf( cssFile
, "\tfont-style: italic;\n" );
284 fprintf( cssFile
, "}\n" );
285 fprintf( cssFile
, ".tab-email {\n" );
286 fprintf( cssFile
, "\tfont-weight: bold;\n" );
287 fprintf( cssFile
, "\tfont-style: italic;\n" );
288 fprintf( cssFile
, "}\n" );
289 fprintf( cssFile
, ".tab-fn {\n" );
290 fprintf( cssFile
, "}\n" );
291 fprintf( cssFile
, ".tab-attr {\n" );
292 fprintf( cssFile
, "}\n" );
294 claws_safe_fclose( cssFile
);
299 * Create full CSS file.
300 * Enter: fileSpec File to create.
301 * Return: Status code.
303 static gint
exporthtml_create_css_full( const gchar
*fileSpec
) {
306 cssFile
= claws_fopen( fileSpec
, "rb" );
308 claws_fclose( cssFile
);
311 cssFile
= claws_fopen( fileSpec
, "wb" );
313 return MGU_OPEN_FILE
;
316 fprintf( cssFile
, "body {\n\tbackground: #ffffe0;\n" );
317 fprintf( cssFile
, "\tfont-family: lucida, helvetica, sans-serif;\n" );
318 fprintf( cssFile
, "\tfont-size: 10pt;\n" );
319 fprintf( cssFile
, "}\n" );
320 fprintf( cssFile
, "h1 {\n" );
321 fprintf( cssFile
, "\tcolor: #000000;\n" );
322 fprintf( cssFile
, "\ttext-align: center;\n" );
323 fprintf( cssFile
, "}\n" );
324 fprintf( cssFile
, "th {\n" );
325 fprintf( cssFile
, "\tfont-size: 10pt;\n" );
326 fprintf( cssFile
, "}\n" );
327 fprintf( cssFile
, "td {\n" );
328 fprintf( cssFile
, "\tfont-size: 10pt;\n" );
329 fprintf( cssFile
, "}\n" );
330 fprintf( cssFile
, ".fmt-folder {\n" );
331 fprintf( cssFile
, "\tcolor: #0000ff;\n" );
332 fprintf( cssFile
, "\tfont-size: 18pt;\n" );
333 fprintf( cssFile
, "\tfont-weight: bold;\n" );
334 fprintf( cssFile
, "}\n" );
335 fprintf( cssFile
, ".tab-head {\n" );
336 fprintf( cssFile
, "\tbackground: #80c0f0;\n" );
337 fprintf( cssFile
, "}\n" );
338 fprintf( cssFile
, ".tab-row0 {\n" );
339 fprintf( cssFile
, "\tbackground: #f0f0f0;\n" );
340 fprintf( cssFile
, "}\n" );
341 fprintf( cssFile
, ".tab-row1 {\n" );
342 fprintf( cssFile
, "\tbackground: #d0d0d0;\n" );
343 fprintf( cssFile
, "}\n" );
344 fprintf( cssFile
, ".tab-dn {\n" );
345 fprintf( cssFile
, "}\n" );
346 fprintf( cssFile
, ".tab-addr {\n" );
347 fprintf( cssFile
, "\tfont-style: italic;\n" );
348 fprintf( cssFile
, "}\n" );
349 fprintf( cssFile
, ".tab-email {\n" );
350 fprintf( cssFile
, "\tfont-weight: bold;\n" );
351 fprintf( cssFile
, "\tfont-style: italic;\n" );
352 fprintf( cssFile
, "}\n" );
353 fprintf( cssFile
, ".tab-fn {\n" );
354 fprintf( cssFile
, "}\n" );
355 fprintf( cssFile
, ".tab-attr {\n" );
356 fprintf( cssFile
, "}\n" );
358 claws_safe_fclose( cssFile
);
363 * Create stylesheet files.
364 * Enter: ctl Export control data.
366 static void exporthtml_create_css_files( ExportHtmlCtl
*ctl
) {
370 node
= ctl
->listStyle
;
372 StylesheetEntry
*entry
= node
->data
;
373 node
= g_list_next( node
);
374 if( strlen( entry
->fileName
) ) {
375 fileSpec
= g_strconcat(
376 ctl
->dirOutput
, G_DIR_SEPARATOR_S
,
377 entry
->fileName
, NULL
);
378 if( entry
->id
== EXPORT_HTML_ID_DEFAULT
) {
379 exporthtml_create_css_dfl( fileSpec
);
381 else if( entry
->id
!= EXPORT_HTML_ID_NONE
) {
382 exporthtml_create_css_full( fileSpec
);
390 * Comparison using linked list elements.
392 static gint
exporthtml_compare_name(
393 gconstpointer ptr1
, gconstpointer ptr2
)
395 const AddrItemObject
*item1
= ptr1
;
396 const AddrItemObject
*item2
= ptr2
;
397 const gchar
*name1
= NULL
, *name2
= NULL
;
398 if( item1
) name1
= ADDRITEM_NAME( item1
);
399 if( item2
) name2
= ADDRITEM_NAME( item2
);
400 if( ! name1
) return ( name2
!= NULL
);
401 if( ! name2
) return -1;
402 return g_utf8_collate( name1
, name2
);
406 * Comparison using linked list elements.
408 static gint
exporthtml_compare_email(
409 gconstpointer ptr1
, gconstpointer ptr2
)
411 const ItemEMail
*email1
= ptr1
;
412 const ItemEMail
*email2
= ptr2
;
413 const gchar
*name1
= NULL
, *name2
= NULL
;
414 if( email1
) name1
= email1
->address
;
415 if( email2
) name2
= email2
->address
;
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_attrib(
425 gconstpointer ptr1
, gconstpointer ptr2
)
427 const UserAttribute
*attr1
= ptr1
;
428 const UserAttribute
*attr2
= ptr2
;
429 const gchar
*name1
= NULL
, *name2
= NULL
;
430 if( attr1
) name1
= attr1
->name
;
431 if( attr2
) name2
= attr2
->name
;
432 if( ! name1
) return ( name2
!= NULL
);
433 if( ! name2
) return -1;
434 return g_utf8_collate( name1
, name2
);
438 * Build sorted list of named items.
439 * Enter: list List of items to sorted.
440 * Return: Sorted list.
441 * Note: List should freed after use. Items referenced by list should not be
442 * freed since they are managed by the address cache.
444 static GList
*exporthtml_sort_name( const GList
*list
) {
446 GList
*sorted
= NULL
;
450 sorted
= g_list_insert_sorted(
451 sorted
, node
->data
, exporthtml_compare_name
);
452 node
= g_list_next( node
);
458 * Build sorted list of email items.
459 * Enter: list List of E-Mail items to sorted.
460 * Return: Sorted list.
461 * Note: List should freed after use. Items referenced by list should not be
462 * freed since they are managed by the address cache.
464 static GList
*exporthtml_sort_email( const GList
*list
) {
466 GList
*sorted
= NULL
;
470 sorted
= g_list_insert_sorted(
471 sorted
, node
->data
, exporthtml_compare_email
);
472 node
= g_list_next( node
);
478 * Build sorted list of attributes.
479 * Enter: list List of items to sorted.
480 * Return: Sorted list.
481 * Note: List should freed after use. Items referenced by list should not be
482 * freed since they are managed by the address cache.
484 static GList
*exporthtml_sort_attrib( const GList
*list
) {
486 GList
*sorted
= NULL
;
491 sorted
= g_list_insert_sorted(
492 sorted
, node
->data
, exporthtml_compare_attrib
);
493 node
= g_list_next( node
);
499 * Format a list of E-Mail addresses.
500 * Enter: ctl Export control data.
501 * stream Output stream.
502 * listEMail List of addresses.
503 * sortFlag Set to TRUE if address list should be sorted.
505 static void exporthtml_fmt_email(
506 ExportHtmlCtl
*ctl
, FILE *stream
, const GList
*listEMail
,
513 if( listEMail
== NULL
) {
514 fprintf( stream
, SC_HTML_SPACE
);
520 node
= list
= exporthtml_sort_email( listEMail
);
527 ItemEMail
*email
= ( ItemEMail
* ) node
->data
;
528 node
= g_list_next( node
);
530 name
= ADDRITEM_NAME( email
);
532 fprintf( stream
, "%s ", name
);
534 if( ctl
->linkEMail
) {
535 fprintf( stream
, "<a href=\"mailto:%s\">",
538 fprintf( stream
, "<span class=\"tab-email\">" );
539 fprintf( stream
, "%s", email
->address
);
540 fprintf( stream
, "</span>" );
541 if( ctl
->linkEMail
) {
542 fprintf( stream
, "</a>" );
544 if( email
->remarks
) {
545 if( strlen( email
->remarks
) ) {
546 fprintf( stream
, " (%s)", email
->remarks
);
549 fprintf( stream
, "<br>\n" );
555 * Format groups in an address book folder.
556 * Enter: ctl Export control data.
557 * stream Output stream.
559 * prevFlag If FALSE, list of persons were output.
560 * Return: TRUE if no groups were formatted.
562 static gboolean
exporthtml_fmt_group(
563 ExportHtmlCtl
*ctl
, FILE *stream
, const ItemFolder
*folder
,
566 gboolean retVal
, band
;
568 const gchar
*tagName
;
571 if( folder
->listGroup
== NULL
) return retVal
;
573 /* Write separator */
575 fprintf( stream
, "<br>\n" );
578 /* Write table headers */
579 fprintf( stream
, "<table" );
580 fprintf( stream
, " border=\"%d\"", BORDER_SIZE
);
581 fprintf( stream
, " cellpadding=\"%d\"", CELL_PADDING
);
582 fprintf( stream
, " cellspacing=\"%d\"", CELL_SPACING
);
583 fprintf( stream
, ">\n" );
585 fprintf( stream
, "<tr class=\"tab-head\">\n" );
586 fprintf( stream
, " <th width=\"200\">" );
587 fprintf( stream
, "%s", _( "Group Name" ) );
588 fprintf( stream
, "</th>\n" );
589 fprintf( stream
, " <th width=\"300\">" );
590 fprintf( stream
, "%s", _( "Email Address" ) );
591 fprintf( stream
, "</th>\n" );
592 fprintf( stream
, "</tr>\n" );
593 list
= exporthtml_sort_name( folder
->listGroup
);
598 AddrItemObject
*aio
= node
->data
;
599 if( aio
&& aio
->type
== ITEMTYPE_GROUP
) {
600 ItemGroup
*group
= ( ItemGroup
* ) aio
;
602 fprintf( stream
, "<tr valign=\"top\"" );
605 tagName
= _idTagRowOdd_
;
608 tagName
= _idTagRowEven_
;
610 fprintf( stream
, " class=\"%s\"", tagName
);
613 fprintf( stream
, "\">\n" );
615 fprintf( stream
, " <td class=\"tab-dn\">" );
616 fprintf( stream
, "%s", ADDRITEM_NAME( group
) );
617 fprintf( stream
, "</td>\n" );
618 fprintf( stream
, " <td class=\"tab-addr\">" );
619 exporthtml_fmt_email( ctl
, stream
, group
->listEMail
, TRUE
);
620 fprintf( stream
, "</td>\n" );
621 fprintf( stream
, "</tr>\n" );
624 node
= g_list_next( node
);
628 fprintf( stream
, "</table>\n" );
633 * Format a list of E-Mail addresses.
634 * Enter: ctl Export control data.
635 * stream Output stream.
636 * listAttr List of attributes.
638 static void exporthtml_fmt_attribs(
639 ExportHtmlCtl
*ctl
, FILE *stream
, const GList
*listAttr
)
644 if( listAttr
== NULL
) {
645 fprintf( stream
, SC_HTML_SPACE
);
649 fprintf( stream
, "<table border=\"0\">\n" );
650 node
= list
= exporthtml_sort_attrib( listAttr
);
652 UserAttribute
*attr
= ( UserAttribute
* ) node
->data
;
653 node
= g_list_next( node
);
654 fprintf( stream
, "<tr valign=\"top\">" );
655 fprintf( stream
, "<td align=\"right\">%s:</td>", attr
->name
);
656 fprintf( stream
, "<td>%s</td>", attr
->value
);
657 fprintf( stream
, "</tr>\n" );
661 fprintf( stream
, "</table>" );
666 * Enter: ctl Export control data.
668 * person Person to format.
670 static void exporthtml_fmt_fullname(
671 ExportHtmlCtl
*ctl
, gchar
*buf
, const ItemPerson
*person
)
675 if( ctl
->nameFormat
== EXPORT_HTML_LAST_FIRST
) {
677 if( person
->lastName
) {
678 if( *person
->lastName
) {
680 strcat( buf
, person
->lastName
);
684 if( person
->firstName
) {
685 if( *person
->firstName
) {
689 strcat( buf
, person
->firstName
);
694 if( person
->firstName
) {
695 if( *person
->firstName
) {
696 strcat( buf
, person
->firstName
);
699 if( person
->lastName
) {
700 if( *person
->lastName
) {
702 strcat( buf
, person
->lastName
);
709 if( *buf
) flag
= TRUE
;
710 if( person
->nickName
) {
711 if( strlen( person
->nickName
) ) {
715 strcat( buf
, person
->nickName
);
725 * Format persons in an address book folder.
726 * Enter: ctl Export control data.
727 * stream Output stream.
729 * Return: TRUE if no persons were formatted.
731 static gboolean
exporthtml_fmt_person(
732 ExportHtmlCtl
*ctl
, FILE *stream
, const ItemFolder
*folder
)
734 gboolean retVal
, band
;
736 gchar buf
[ FMT_BUFSIZE
];
737 const gchar
*tagName
;
740 if( folder
->listPerson
== NULL
) return retVal
;
742 /* Write table headers */
743 fprintf( stream
, "<table" );
744 fprintf( stream
, " border=\"%d\"", BORDER_SIZE
);
745 fprintf( stream
, " cellpadding=\"%d\"", CELL_PADDING
);
746 fprintf( stream
, " cellspacing=\"%d\"", CELL_SPACING
);
747 fprintf( stream
, ">\n" );
749 fprintf( stream
, "<tr class=\"tab-head\">\n" );
750 fprintf( stream
, " <th width=\"200\">" );
751 fprintf( stream
, "%s", _( "Display Name" ) );
752 fprintf( stream
, "</th>\n" );
753 fprintf( stream
, " <th width=\"300\">" );
754 fprintf( stream
, "%s", _( "Email Address" ) );
755 fprintf( stream
, "</th>\n" );
756 fprintf( stream
, " <th width=\"200\">" );
757 fprintf( stream
, "%s", _( "Full Name" ) );
758 fprintf( stream
, "</th>\n" );
759 if( ctl
->showAttribs
) {
760 fprintf( stream
, " <th width=\"250\">" );
761 fprintf( stream
, "%s", _( "Attributes" ) );
762 fprintf( stream
, "</th>\n" );
764 fprintf( stream
, "</tr>\n" );
767 node
= list
= exporthtml_sort_name( folder
->listPerson
);
769 AddrItemObject
*aio
= node
->data
;
770 if( aio
&& aio
->type
== ITEMTYPE_PERSON
) {
771 ItemPerson
*person
= ( ItemPerson
* ) aio
;
773 /* Format first/last/nick name */
775 exporthtml_fmt_fullname( ctl
, buf
,person
);
777 fprintf( stream
, "<tr valign=\"top\"" );
780 tagName
= _idTagRowOdd_
;
783 tagName
= _idTagRowEven_
;
785 fprintf( stream
, " class=\"%s\"", tagName
);
788 fprintf( stream
, ">\n" );
790 fprintf( stream
, " <td class=\"tab-dn\">" );
791 fprintf( stream
, "%s", ADDRITEM_NAME( person
) );
792 fprintf( stream
, "</td>\n" );
794 fprintf( stream
, " <td class=\"tab-addr\">" );
795 exporthtml_fmt_email( ctl
, stream
, person
->listEMail
, FALSE
);
796 fprintf( stream
, "</td>\n" );
798 fprintf( stream
, " <td class=\"tab-fn\">" );
800 fprintf( stream
, "%s", buf
);
803 fprintf( stream
, "%s", SC_HTML_SPACE
);
805 fprintf( stream
, "</td>\n" );
807 if( ctl
->showAttribs
) {
808 fprintf( stream
, " <td class=\"tab-attr\">" );
809 exporthtml_fmt_attribs(
810 ctl
, stream
, person
->listAttrib
);
811 fprintf( stream
, "</td>\n" );
813 fprintf( stream
, "</tr>\n" );
817 node
= g_list_next( node
);
821 fprintf( stream
, "</table>\n" );
826 * Format folder heirarchy.
827 * Enter: stream Output stream.
828 * list Heirarchy list.
830 static void exporthtml_fmt_folderhead( FILE *stream
, const GList
*list
) {
838 AddrItemObject
*aio
= node
->data
;
839 if( aio
&& aio
->type
== ITEMTYPE_FOLDER
) {
840 ItemFolder
*folder
= ( ItemFolder
* ) aio
;
842 name
= ADDRITEM_NAME( folder
);
845 fprintf( stream
, " > " );
847 fprintf( stream
, "%s", name
);
851 node
= g_list_next( node
);
856 * Format an address book folder.
857 * Enter: ctl Export control data.
858 * stream Output stream.
861 static void exporthtml_fmt_folder(
862 ExportHtmlCtl
*ctl
, FILE *stream
, const ItemFolder
*folder
)
865 GList
*listHeir
, *list
;
869 name
= ADDRITEM_NAME( folder
);
871 listHeir
= addritem_folder_path( folder
, TRUE
);
873 fprintf( stream
, "<p class=\"fmt-folder\">" );
874 fprintf( stream
, "%s: ", _( "Folder" ) );
875 exporthtml_fmt_folderhead( stream
, listHeir
);
876 fprintf( stream
, "</p>\n" );
877 g_list_free( listHeir
);
881 ret1
= exporthtml_fmt_person( ctl
, stream
, folder
);
882 exporthtml_fmt_group( ctl
, stream
, folder
, ret1
);
884 node
= list
= exporthtml_sort_name( folder
->listFolder
);
886 AddrItemObject
*aio
= node
->data
;
887 if( aio
&& aio
->type
== ITEMTYPE_FOLDER
) {
888 ItemFolder
*subFolder
= ( ItemFolder
* ) aio
;
889 exporthtml_fmt_folder( ctl
, stream
, subFolder
);
891 node
= g_list_next( node
);
899 * Format header block.
900 * Enter: ctl Export control data.
901 * stream Output stream.
904 static void exporthtml_fmt_header(
905 ExportHtmlCtl
*ctl
, FILE *stream
, gchar
*title
)
907 StylesheetEntry
*entry
;
909 entry
= exporthtml_find_stylesheet( ctl
);
912 "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" );
914 "\"http://www.w3.org/TR/html4/loose.dtd\">\n" );
915 fprintf( stream
, "<html>\n" );
916 fprintf( stream
, "<head>\n" );
918 if( ctl
->encoding
&& strlen( ctl
->encoding
) > 0 ) {
919 fprintf( stream
, "<meta " );
920 fprintf( stream
, "http-equiv=\"Content-Type\" " );
921 fprintf( stream
, "content=\"text/html; charset=%s\">\n",
925 fprintf( stream
, "<title>%s</title>\n", title
);
927 if( entry
!= NULL
) {
928 if( entry
->fileName
&& strlen( entry
->fileName
) > 0 ) {
929 fprintf( stream
, "<link " );
930 fprintf( stream
, "rel=\"stylesheet\" " );
931 fprintf( stream
, "type=\"text/css\" " );
932 fprintf( stream
, "href=\"%s\" >\n", entry
->fileName
);
935 fprintf( stream
, "</head>\n" );
939 * ============================================================================
940 * Export address book to HTML file.
941 * Enter: ctl Export control data.
942 * cache Address book/data source cache.
944 * ============================================================================
946 void exporthtml_process(
947 ExportHtmlCtl
*ctl
, AddressCache
*cache
)
949 ItemFolder
*rootFolder
;
956 htmlFile
= claws_fopen( ctl
->path
, "wb" );
958 /* Cannot open file */
959 g_print( "Cannot open file for write\n" );
960 ctl
->retVal
= MGU_OPEN_FILE
;
964 title
= _( "Claws Mail Address Book" );
965 rootFolder
= cache
->rootFolder
;
966 dsName
= cache
->name
;
968 exporthtml_fmt_header( ctl
, htmlFile
, title
);
970 fprintf( htmlFile
, "<body>\n" );
971 fprintf( htmlFile
, "<h1>%s</h1>\n", title
);
973 fprintf( htmlFile
, "<p class=\"fmt-folder\">" );
974 fprintf( htmlFile
, "%s: ", _( "Address Book" ) );
975 fprintf( htmlFile
, "%s", dsName
);
976 fprintf( htmlFile
, "</p>\n" );
978 exporthtml_fmt_folder( ctl
, htmlFile
, rootFolder
);
981 fprintf( htmlFile
, "<p>%s</p>\n", ctime_r( &tt
, buf
) );
982 fprintf( htmlFile
, "<hr width=\"100%%\">\n" );
984 fprintf( htmlFile
, "</body>\n" );
985 fprintf( htmlFile
, "</html>\n" );
987 claws_safe_fclose( htmlFile
);
988 ctl
->retVal
= MGU_SUCCESS
;
990 /* Create stylesheet files */
991 exporthtml_create_css_files( ctl
);
996 * Build full export file specification.
997 * Enter: ctl Export control data.
999 static void exporthtml_build_filespec( ExportHtmlCtl
*ctl
) {
1002 fileSpec
= g_strconcat(
1003 ctl
->dirOutput
, G_DIR_SEPARATOR_S
, ctl
->fileHtml
, NULL
);
1004 ctl
->path
= mgu_replace_string( ctl
->path
, fileSpec
);
1009 * ============================================================================
1010 * Parse directory and filename from full export file specification.
1011 * Enter: ctl Export control data.
1012 * fileSpec File spec.
1013 * ============================================================================
1015 void exporthtml_parse_filespec( ExportHtmlCtl
*ctl
, gchar
*fileSpec
) {
1017 gchar
*base
= g_path_get_basename(fileSpec
);
1020 mgu_replace_string( ctl
->fileHtml
, base
);
1022 t
= g_path_get_dirname( fileSpec
);
1023 ctl
->dirOutput
= mgu_replace_string( ctl
->dirOutput
, t
);
1025 ctl
->path
= mgu_replace_string( ctl
->path
, fileSpec
);
1029 * ============================================================================
1030 * Create output directory.
1031 * Enter: ctl Export control data.
1032 * Return: TRUE if directory created.
1033 * ============================================================================
1035 gboolean
exporthtml_create_dir( ExportHtmlCtl
*ctl
) {
1036 gboolean retVal
= FALSE
;
1039 if( g_mkdir( ctl
->dirOutput
, S_IRWXU
) == 0 ) {
1043 ctl
->rcCreate
= errno
;
1049 * ============================================================================
1050 * Retrieve create directory error message.
1051 * Enter: ctl Export control data.
1053 * ============================================================================
1055 gchar
*exporthtml_get_create_msg( ExportHtmlCtl
*ctl
) {
1058 if( ctl
->rcCreate
== EEXIST
) {
1059 msg
= _( "Name already exists but is not a directory." );
1061 else if( ctl
->rcCreate
== EACCES
) {
1062 msg
= _( "No permissions to create directory." );
1064 else if( ctl
->rcCreate
== ENAMETOOLONG
) {
1065 msg
= _( "Name is too long." );
1068 msg
= _( "Not specified." );
1074 * Set default values.
1075 * Enter: ctl Export control data.
1077 static void exporthtml_default_values( ExportHtmlCtl
*ctl
) {
1081 get_home_dir(), G_DIR_SEPARATOR_S
,
1082 DFL_DIR_CLAWS_OUT
, NULL
);
1084 ctl
->dirOutput
= mgu_replace_string( ctl
->dirOutput
, str
);
1088 mgu_replace_string( ctl
->fileHtml
, DFL_FILE_CLAWS_OUT
);
1089 ctl
->encoding
= NULL
;
1090 ctl
->stylesheet
= EXPORT_HTML_ID_DEFAULT
;
1091 ctl
->nameFormat
= EXPORT_HTML_FIRST_LAST
;
1092 ctl
->banding
= TRUE
;
1093 ctl
->linkEMail
= TRUE
;
1094 ctl
->showAttribs
= TRUE
;
1095 ctl
->retVal
= MGU_SUCCESS
;
1099 * ============================================================================
1100 * Load settings from XML properties file.
1101 * Enter: ctl Export control data.
1102 * ============================================================================
1104 void exporthtml_load_settings( ExportHtmlCtl
*ctl
) {
1110 props
= xmlprops_create();
1111 xmlprops_set_path( props
, ctl
->settingsFile
);
1112 rc
= xmlprops_load_file( props
);
1115 xmlprops_get_property_s( props
, EXMLPROP_DIRECTORY
, buf
);
1116 ctl
->dirOutput
= mgu_replace_string( ctl
->dirOutput
, buf
);
1118 xmlprops_get_property_s( props
, EXMLPROP_FILE
, buf
);
1119 ctl
->fileHtml
= mgu_replace_string( ctl
->fileHtml
, buf
);
1122 xmlprops_get_property_i( props
, EXMLPROP_STYLESHEET
);
1124 xmlprops_get_property_i( props
, EXMLPROP_FMT_NAME
);
1126 xmlprops_get_property_b( props
, EXMLPROP_BANDING
);
1128 xmlprops_get_property_b( props
, EXMLPROP_FMT_EMAIL
);
1130 xmlprops_get_property_b( props
, EXMLPROP_FMT_ATTRIB
);
1133 /* Set default values */
1134 exporthtml_default_values( ctl
);
1136 exporthtml_build_filespec( ctl
);
1137 /* exporthtml_print( ctl, stdout ); */
1139 xmlprops_free( props
);
1143 * ============================================================================
1144 * Save settings to XML properties file.
1145 * Enter: ctl Export control data.
1146 * ============================================================================
1148 void exporthtml_save_settings( ExportHtmlCtl
*ctl
) {
1151 props
= xmlprops_create();
1152 xmlprops_set_path( props
, ctl
->settingsFile
);
1154 xmlprops_set_property( props
, EXMLPROP_DIRECTORY
, ctl
->dirOutput
);
1155 xmlprops_set_property( props
, EXMLPROP_FILE
, ctl
->fileHtml
);
1156 xmlprops_set_property_i( props
, EXMLPROP_STYLESHEET
, ctl
->stylesheet
);
1157 xmlprops_set_property_i( props
, EXMLPROP_FMT_NAME
, ctl
->nameFormat
);
1158 xmlprops_set_property_b( props
, EXMLPROP_BANDING
, ctl
->banding
);
1159 xmlprops_set_property_b( props
, EXMLPROP_FMT_EMAIL
, ctl
->linkEMail
);
1160 xmlprops_set_property_b( props
, EXMLPROP_FMT_ATTRIB
, ctl
->showAttribs
);
1161 if (xmlprops_save_file( props
) != MGU_SUCCESS
)
1162 g_warning("can't save settings");
1163 xmlprops_free( props
);
1167 * ============================================================================
1169 * ============================================================================