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/>.
21 * Export address book to HTML file.
26 #include "claws-features.h"
39 #include <glib/gi18n.h>
43 #include "exporthtml.h"
45 #include "file-utils.h"
47 #define DFL_DIR_CLAWS_OUT "claws-mail-out"
48 #define DFL_FILE_CLAWS_OUT "addressbook.html"
50 #define FMT_BUFSIZE 2048
51 #define SC_HTML_SPACE " "
53 #define CELL_PADDING 2
54 #define CELL_SPACING 2
55 #define CHAR_ENCODING "UTF-8"
57 /* Stylesheet names */
58 #define FILENAME_NONE ""
59 #define FILENAME_DEFAULT "claws-mail.css"
60 #define FILENAME_FULL "full.css"
61 #define FILENAME_CUSTOM "custom.css"
62 #define FILENAME_CUSTOM2 "custom2.css"
63 #define FILENAME_CUSTOM3 "custom3.css"
64 #define FILENAME_CUSTOM4 "custom4.css"
66 /* Settings - properties */
67 #define EXML_PROPFILE_NAME "exporthtml.xml"
68 #define EXMLPROP_DIRECTORY "directory"
69 #define EXMLPROP_FILE "file"
70 #define EXMLPROP_STYLESHEET "stylesheet"
71 #define EXMLPROP_FMT_NAME "format-full-name"
72 #define EXMLPROP_FMT_EMAIL "format-email-links"
73 #define EXMLPROP_FMT_ATTRIB "format-attributes"
74 #define EXMLPROP_BANDING "color-banding"
75 #define EXMLPROP_VALUE_YES "y"
76 #define EXMLPROP_VALUE_NO "n"
78 static gchar
*_idTagRowEven_
= "tab-row0";
79 static gchar
*_idTagRowOdd_
= "tab-row1";
84 typedef struct _StylesheetEntry StylesheetEntry
;
85 struct _StylesheetEntry
{
92 * Build stylesheet entry.
93 * Enter: ctl Export control data.
98 static void exporthtml_build_entry(
99 ExportHtmlCtl
*ctl
, const gchar
*file
, const gint id
,
102 StylesheetEntry
*entry
;
104 entry
= g_new0( StylesheetEntry
, 1 );
105 entry
->fileName
= g_strdup( file
);
107 entry
->dflValue
= dfl
;
108 ctl
->listStyle
= g_list_append( ctl
->listStyle
, entry
);
112 * Free up object by releasing internal memory.
113 * Enter: ctl Export control data.
115 ExportHtmlCtl
*exporthtml_create( void ) {
116 ExportHtmlCtl
*ctl
= g_new0( ExportHtmlCtl
, 1 );
119 ctl
->dirOutput
= NULL
;
120 ctl
->fileHtml
= NULL
;
121 ctl
->encoding
= g_strconcat(CHAR_ENCODING
, NULL
);
122 ctl
->stylesheet
= EXPORT_HTML_ID_NONE
;
123 ctl
->nameFormat
= EXPORT_HTML_FIRST_LAST
;
124 ctl
->banding
= FALSE
;
125 ctl
->linkEMail
= FALSE
;
126 ctl
->showAttribs
= FALSE
;
127 ctl
->retVal
= MGU_SUCCESS
;
128 ctl
->listStyle
= NULL
;
130 ctl
->settingsFile
= g_strconcat(
131 get_rc_dir(), G_DIR_SEPARATOR_S
, EXML_PROPFILE_NAME
, NULL
);
133 /* Build stylesheet list */
134 exporthtml_build_entry(
135 ctl
, FILENAME_NONE
, EXPORT_HTML_ID_NONE
, FALSE
);
136 exporthtml_build_entry(
137 ctl
, FILENAME_DEFAULT
, EXPORT_HTML_ID_DEFAULT
, TRUE
);
138 exporthtml_build_entry(
139 ctl
, FILENAME_FULL
, EXPORT_HTML_ID_FULL
, FALSE
);
140 exporthtml_build_entry(
141 ctl
, FILENAME_CUSTOM
, EXPORT_HTML_ID_CUSTOM
, FALSE
);
142 exporthtml_build_entry(
143 ctl
, FILENAME_CUSTOM2
, EXPORT_HTML_ID_CUSTOM2
, FALSE
);
144 exporthtml_build_entry(
145 ctl
, FILENAME_CUSTOM3
, EXPORT_HTML_ID_CUSTOM3
, FALSE
);
146 exporthtml_build_entry(
147 ctl
, FILENAME_CUSTOM4
, EXPORT_HTML_ID_CUSTOM4
, FALSE
);
153 * Free up object by releasing internal memory.
154 * Enter: ctl Export control data.
156 void exporthtml_free( ExportHtmlCtl
*ctl
) {
158 StylesheetEntry
*entry
;
160 cm_return_if_fail( ctl
!= NULL
);
162 /* Free stylesheet list */
163 node
= ctl
->listStyle
;
165 entry
= ( StylesheetEntry
* ) node
->data
;
166 g_free( entry
->fileName
);
167 entry
->fileName
= NULL
;
169 entry
->dflValue
= FALSE
;
172 node
= g_list_next( node
);
174 g_list_free( ctl
->listStyle
);
175 ctl
->listStyle
= NULL
;
178 g_free( ctl
->fileHtml
);
179 g_free( ctl
->encoding
);
180 g_free( ctl
->dirOutput
);
181 g_free( ctl
->settingsFile
);
185 ctl
->dirOutput
= NULL
;
186 ctl
->fileHtml
= NULL
;
187 ctl
->encoding
= NULL
;
188 ctl
->stylesheet
= EXPORT_HTML_ID_NONE
;
189 ctl
->nameFormat
= EXPORT_HTML_FIRST_LAST
;
190 ctl
->banding
= FALSE
;
191 ctl
->linkEMail
= FALSE
;
192 ctl
->showAttribs
= FALSE
;
193 ctl
->retVal
= MGU_SUCCESS
;
196 /* Now release object */
202 * Enter: ctl Export control data.
203 * Return: Stylesheet object, or NULL if nothing found. If a default entry is
204 * found in list, it will be returned.
206 static StylesheetEntry
*exporthtml_find_stylesheet( ExportHtmlCtl
*ctl
) {
207 StylesheetEntry
*retVal
= NULL
;
208 StylesheetEntry
*entry
;
211 node
= ctl
->listStyle
;
213 entry
= ( StylesheetEntry
* ) node
->data
;
214 if( entry
->id
== ctl
->stylesheet
) return entry
;
215 if( entry
->dflValue
) retVal
= entry
;
216 node
= g_list_next( node
);
221 void exporthtml_set_stylesheet( ExportHtmlCtl
*ctl
, const gint value
) {
222 cm_return_if_fail( ctl
!= NULL
);
223 ctl
->stylesheet
= value
;
225 void exporthtml_set_name_format( ExportHtmlCtl
*ctl
, const gint value
) {
226 cm_return_if_fail( ctl
!= NULL
);
227 ctl
->nameFormat
= value
;
229 void exporthtml_set_banding( ExportHtmlCtl
*ctl
, const gboolean value
) {
230 cm_return_if_fail( ctl
!= NULL
);
231 ctl
->banding
= value
;
233 void exporthtml_set_link_email( ExportHtmlCtl
*ctl
, const gboolean value
) {
234 cm_return_if_fail( ctl
!= NULL
);
235 ctl
->linkEMail
= value
;
237 void exporthtml_set_attributes( ExportHtmlCtl
*ctl
, const gboolean value
) {
238 cm_return_if_fail( ctl
!= NULL
);
239 ctl
->showAttribs
= value
;
243 * Create default CSS file.
244 * Enter: fileSpec File to create.
245 * Return: Status code.
247 static gint
exporthtml_create_css_dfl( const gchar
*fileSpec
) {
250 cssFile
= claws_fopen( fileSpec
, "rb" );
252 claws_fclose( cssFile
);
255 cssFile
= claws_fopen( fileSpec
, "wb" );
257 return MGU_OPEN_FILE
;
260 fprintf( cssFile
, "body {\n\tbackground: #ffffe0;\n" );
261 fprintf( cssFile
, "\tfont-family: lucida, helvetica, sans-serif;\n" );
262 fprintf( cssFile
, "\tfont-size: 10pt;\n" );
263 fprintf( cssFile
, "}\n" );
264 fprintf( cssFile
, "h1 {\n" );
265 fprintf( cssFile
, "\tcolor: #000000;\n" );
266 fprintf( cssFile
, "\ttext-align: center;\n" );
267 fprintf( cssFile
, "}\n" );
268 fprintf( cssFile
, "th {\n" );
269 fprintf( cssFile
, "\tfont-size: 10pt;\n" );
270 fprintf( cssFile
, "}\n" );
271 fprintf( cssFile
, "td {\n" );
272 fprintf( cssFile
, "\tfont-size: 10pt;\n" );
273 fprintf( cssFile
, "}\n" );
274 fprintf( cssFile
, ".fmt-folder {\n" );
275 fprintf( cssFile
, "\tcolor: #0000ff;\n" );
276 fprintf( cssFile
, "\tfont-size: 18pt;\n" );
277 fprintf( cssFile
, "\tfont-weight: bold;\n" );
278 fprintf( cssFile
, "}\n" );
279 fprintf( cssFile
, ".tab-head {\n" );
280 fprintf( cssFile
, "\tbackground: #80c0f0;\n" );
281 fprintf( cssFile
, "}\n" );
282 fprintf( cssFile
, ".tab-dn {\n" );
283 fprintf( cssFile
, "}\n" );
284 fprintf( cssFile
, ".tab-addr {\n" );
285 fprintf( cssFile
, "\tfont-style: italic;\n" );
286 fprintf( cssFile
, "}\n" );
287 fprintf( cssFile
, ".tab-email {\n" );
288 fprintf( cssFile
, "\tfont-weight: bold;\n" );
289 fprintf( cssFile
, "\tfont-style: italic;\n" );
290 fprintf( cssFile
, "}\n" );
291 fprintf( cssFile
, ".tab-fn {\n" );
292 fprintf( cssFile
, "}\n" );
293 fprintf( cssFile
, ".tab-attr {\n" );
294 fprintf( cssFile
, "}\n" );
296 claws_safe_fclose( cssFile
);
301 * Create full CSS file.
302 * Enter: fileSpec File to create.
303 * Return: Status code.
305 static gint
exporthtml_create_css_full( const gchar
*fileSpec
) {
308 cssFile
= claws_fopen( fileSpec
, "rb" );
310 claws_fclose( cssFile
);
313 cssFile
= claws_fopen( fileSpec
, "wb" );
315 return MGU_OPEN_FILE
;
318 fprintf( cssFile
, "body {\n\tbackground: #ffffe0;\n" );
319 fprintf( cssFile
, "\tfont-family: lucida, helvetica, sans-serif;\n" );
320 fprintf( cssFile
, "\tfont-size: 10pt;\n" );
321 fprintf( cssFile
, "}\n" );
322 fprintf( cssFile
, "h1 {\n" );
323 fprintf( cssFile
, "\tcolor: #000000;\n" );
324 fprintf( cssFile
, "\ttext-align: center;\n" );
325 fprintf( cssFile
, "}\n" );
326 fprintf( cssFile
, "th {\n" );
327 fprintf( cssFile
, "\tfont-size: 10pt;\n" );
328 fprintf( cssFile
, "}\n" );
329 fprintf( cssFile
, "td {\n" );
330 fprintf( cssFile
, "\tfont-size: 10pt;\n" );
331 fprintf( cssFile
, "}\n" );
332 fprintf( cssFile
, ".fmt-folder {\n" );
333 fprintf( cssFile
, "\tcolor: #0000ff;\n" );
334 fprintf( cssFile
, "\tfont-size: 18pt;\n" );
335 fprintf( cssFile
, "\tfont-weight: bold;\n" );
336 fprintf( cssFile
, "}\n" );
337 fprintf( cssFile
, ".tab-head {\n" );
338 fprintf( cssFile
, "\tbackground: #80c0f0;\n" );
339 fprintf( cssFile
, "}\n" );
340 fprintf( cssFile
, ".tab-row0 {\n" );
341 fprintf( cssFile
, "\tbackground: #f0f0f0;\n" );
342 fprintf( cssFile
, "}\n" );
343 fprintf( cssFile
, ".tab-row1 {\n" );
344 fprintf( cssFile
, "\tbackground: #d0d0d0;\n" );
345 fprintf( cssFile
, "}\n" );
346 fprintf( cssFile
, ".tab-dn {\n" );
347 fprintf( cssFile
, "}\n" );
348 fprintf( cssFile
, ".tab-addr {\n" );
349 fprintf( cssFile
, "\tfont-style: italic;\n" );
350 fprintf( cssFile
, "}\n" );
351 fprintf( cssFile
, ".tab-email {\n" );
352 fprintf( cssFile
, "\tfont-weight: bold;\n" );
353 fprintf( cssFile
, "\tfont-style: italic;\n" );
354 fprintf( cssFile
, "}\n" );
355 fprintf( cssFile
, ".tab-fn {\n" );
356 fprintf( cssFile
, "}\n" );
357 fprintf( cssFile
, ".tab-attr {\n" );
358 fprintf( cssFile
, "}\n" );
360 claws_safe_fclose( cssFile
);
365 * Create stylesheet files.
366 * Enter: ctl Export control data.
368 static void exporthtml_create_css_files( ExportHtmlCtl
*ctl
) {
372 node
= ctl
->listStyle
;
374 StylesheetEntry
*entry
= node
->data
;
375 node
= g_list_next( node
);
376 if( strlen( entry
->fileName
) ) {
377 fileSpec
= g_strconcat(
378 ctl
->dirOutput
, G_DIR_SEPARATOR_S
,
379 entry
->fileName
, NULL
);
380 if( entry
->id
== EXPORT_HTML_ID_DEFAULT
) {
381 exporthtml_create_css_dfl( fileSpec
);
383 else if( entry
->id
!= EXPORT_HTML_ID_NONE
) {
384 exporthtml_create_css_full( fileSpec
);
392 * Comparison using linked list elements.
394 static gint
exporthtml_compare_name(
395 gconstpointer ptr1
, gconstpointer ptr2
)
397 const AddrItemObject
*item1
= ptr1
;
398 const AddrItemObject
*item2
= ptr2
;
399 const gchar
*name1
= NULL
, *name2
= NULL
;
400 if( item1
) name1
= ADDRITEM_NAME( item1
);
401 if( item2
) name2
= ADDRITEM_NAME( item2
);
402 if( ! name1
) return ( name2
!= NULL
);
403 if( ! name2
) return -1;
404 return g_utf8_collate( name1
, name2
);
408 * Comparison using linked list elements.
410 static gint
exporthtml_compare_email(
411 gconstpointer ptr1
, gconstpointer ptr2
)
413 const ItemEMail
*email1
= ptr1
;
414 const ItemEMail
*email2
= ptr2
;
415 const gchar
*name1
= NULL
, *name2
= NULL
;
416 if( email1
) name1
= email1
->address
;
417 if( email2
) name2
= email2
->address
;
418 if( ! name1
) return ( name2
!= NULL
);
419 if( ! name2
) return -1;
420 return g_utf8_collate( name1
, name2
);
424 * Comparison using linked list elements.
426 static gint
exporthtml_compare_attrib(
427 gconstpointer ptr1
, gconstpointer ptr2
)
429 const UserAttribute
*attr1
= ptr1
;
430 const UserAttribute
*attr2
= ptr2
;
431 const gchar
*name1
= NULL
, *name2
= NULL
;
432 if( attr1
) name1
= attr1
->name
;
433 if( attr2
) name2
= attr2
->name
;
434 if( ! name1
) return ( name2
!= NULL
);
435 if( ! name2
) return -1;
436 return g_utf8_collate( name1
, name2
);
440 * Build sorted list of named items.
441 * Enter: list List of items to sorted.
442 * Return: Sorted list.
443 * Note: List should freed after use. Items referenced by list should not be
444 * freed since they are managed by the address cache.
446 static GList
*exporthtml_sort_name( const GList
*list
) {
448 GList
*sorted
= NULL
;
452 sorted
= g_list_insert_sorted(
453 sorted
, node
->data
, exporthtml_compare_name
);
454 node
= g_list_next( node
);
460 * Build sorted list of email items.
461 * Enter: list List of E-Mail items to sorted.
462 * Return: Sorted list.
463 * Note: List should freed after use. Items referenced by list should not be
464 * freed since they are managed by the address cache.
466 static GList
*exporthtml_sort_email( const GList
*list
) {
468 GList
*sorted
= NULL
;
472 sorted
= g_list_insert_sorted(
473 sorted
, node
->data
, exporthtml_compare_email
);
474 node
= g_list_next( node
);
480 * Build sorted list of attributes.
481 * Enter: list List of items to sorted.
482 * Return: Sorted list.
483 * Note: List should freed after use. Items referenced by list should not be
484 * freed since they are managed by the address cache.
486 static GList
*exporthtml_sort_attrib( const GList
*list
) {
488 GList
*sorted
= NULL
;
493 sorted
= g_list_insert_sorted(
494 sorted
, node
->data
, exporthtml_compare_attrib
);
495 node
= g_list_next( node
);
501 * Format a list of E-Mail addresses.
502 * Enter: ctl Export control data.
503 * stream Output stream.
504 * listEMail List of addresses.
505 * sortFlag Set to TRUE if address list should be sorted.
507 static void exporthtml_fmt_email(
508 ExportHtmlCtl
*ctl
, FILE *stream
, const GList
*listEMail
,
515 if( listEMail
== NULL
) {
516 fprintf( stream
, SC_HTML_SPACE
);
522 node
= list
= exporthtml_sort_email( listEMail
);
529 ItemEMail
*email
= ( ItemEMail
* ) node
->data
;
530 node
= g_list_next( node
);
532 name
= ADDRITEM_NAME( email
);
534 fprintf( stream
, "%s ", name
);
536 if( ctl
->linkEMail
) {
537 fprintf( stream
, "<a href=\"mailto:%s\">",
540 fprintf( stream
, "<span class=\"tab-email\">" );
541 fprintf( stream
, "%s", email
->address
);
542 fprintf( stream
, "</span>" );
543 if( ctl
->linkEMail
) {
544 fprintf( stream
, "</a>" );
546 if( email
->remarks
) {
547 if( strlen( email
->remarks
) ) {
548 fprintf( stream
, " (%s)", email
->remarks
);
551 fprintf( stream
, "<br>\n" );
557 * Format groups in an address book folder.
558 * Enter: ctl Export control data.
559 * stream Output stream.
561 * prevFlag If FALSE, list of persons were output.
562 * Return: TRUE if no groups were formatted.
564 static gboolean
exporthtml_fmt_group(
565 ExportHtmlCtl
*ctl
, FILE *stream
, const ItemFolder
*folder
,
568 gboolean retVal
, band
;
570 const gchar
*tagName
;
573 if( folder
->listGroup
== NULL
) return retVal
;
575 /* Write separator */
577 fprintf( stream
, "<br>\n" );
580 /* Write table headers */
581 fprintf( stream
, "<table" );
582 fprintf( stream
, " border=\"%d\"", BORDER_SIZE
);
583 fprintf( stream
, " cellpadding=\"%d\"", CELL_PADDING
);
584 fprintf( stream
, " cellspacing=\"%d\"", CELL_SPACING
);
585 fprintf( stream
, ">\n" );
587 fprintf( stream
, "<tr class=\"tab-head\">\n" );
588 fprintf( stream
, " <th width=\"200\">" );
589 fprintf( stream
, "%s", _( "Group Name" ) );
590 fprintf( stream
, "</th>\n" );
591 fprintf( stream
, " <th width=\"300\">" );
592 fprintf( stream
, "%s", _( "Email Address" ) );
593 fprintf( stream
, "</th>\n" );
594 fprintf( stream
, "</tr>\n" );
595 list
= exporthtml_sort_name( folder
->listGroup
);
600 AddrItemObject
*aio
= node
->data
;
601 if( aio
&& aio
->type
== ITEMTYPE_GROUP
) {
602 ItemGroup
*group
= ( ItemGroup
* ) aio
;
604 fprintf( stream
, "<tr valign=\"top\"" );
607 tagName
= _idTagRowOdd_
;
610 tagName
= _idTagRowEven_
;
612 fprintf( stream
, " class=\"%s\"", tagName
);
615 fprintf( stream
, "\">\n" );
617 fprintf( stream
, " <td class=\"tab-dn\">" );
618 fprintf( stream
, "%s", ADDRITEM_NAME( group
) );
619 fprintf( stream
, "</td>\n" );
620 fprintf( stream
, " <td class=\"tab-addr\">" );
621 exporthtml_fmt_email( ctl
, stream
, group
->listEMail
, TRUE
);
622 fprintf( stream
, "</td>\n" );
623 fprintf( stream
, "</tr>\n" );
626 node
= g_list_next( node
);
630 fprintf( stream
, "</table>\n" );
635 * Format a list of E-Mail addresses.
636 * Enter: ctl Export control data.
637 * stream Output stream.
638 * listAttr List of attributes.
640 static void exporthtml_fmt_attribs(
641 ExportHtmlCtl
*ctl
, FILE *stream
, const GList
*listAttr
)
646 if( listAttr
== NULL
) {
647 fprintf( stream
, SC_HTML_SPACE
);
651 fprintf( stream
, "<table border=\"0\">\n" );
652 node
= list
= exporthtml_sort_attrib( listAttr
);
654 UserAttribute
*attr
= ( UserAttribute
* ) node
->data
;
655 node
= g_list_next( node
);
656 fprintf( stream
, "<tr valign=\"top\">" );
657 fprintf( stream
, "<td align=\"right\">%s:</td>", attr
->name
);
658 fprintf( stream
, "<td>%s</td>", attr
->value
);
659 fprintf( stream
, "</tr>\n" );
663 fprintf( stream
, "</table>" );
668 * Enter: ctl Export control data.
670 * person Person to format.
672 static void exporthtml_fmt_fullname(
673 ExportHtmlCtl
*ctl
, gchar
*buf
, const ItemPerson
*person
)
677 if( ctl
->nameFormat
== EXPORT_HTML_LAST_FIRST
) {
679 if( person
->lastName
) {
680 if( *person
->lastName
) {
682 strcat( buf
, person
->lastName
);
686 if( person
->firstName
) {
687 if( *person
->firstName
) {
691 strcat( buf
, person
->firstName
);
696 if( person
->firstName
) {
697 if( *person
->firstName
) {
698 strcat( buf
, person
->firstName
);
701 if( person
->lastName
) {
702 if( *person
->lastName
) {
704 strcat( buf
, person
->lastName
);
711 if( *buf
) flag
= TRUE
;
712 if( person
->nickName
) {
713 if( strlen( person
->nickName
) ) {
717 strcat( buf
, person
->nickName
);
727 * Format persons in an address book folder.
728 * Enter: ctl Export control data.
729 * stream Output stream.
731 * Return: TRUE if no persons were formatted.
733 static gboolean
exporthtml_fmt_person(
734 ExportHtmlCtl
*ctl
, FILE *stream
, const ItemFolder
*folder
)
736 gboolean retVal
, band
;
738 gchar buf
[ FMT_BUFSIZE
];
739 const gchar
*tagName
;
742 if( folder
->listPerson
== NULL
) return retVal
;
744 /* Write table headers */
745 fprintf( stream
, "<table" );
746 fprintf( stream
, " border=\"%d\"", BORDER_SIZE
);
747 fprintf( stream
, " cellpadding=\"%d\"", CELL_PADDING
);
748 fprintf( stream
, " cellspacing=\"%d\"", CELL_SPACING
);
749 fprintf( stream
, ">\n" );
751 fprintf( stream
, "<tr class=\"tab-head\">\n" );
752 fprintf( stream
, " <th width=\"200\">" );
753 fprintf( stream
, "%s", _( "Display Name" ) );
754 fprintf( stream
, "</th>\n" );
755 fprintf( stream
, " <th width=\"300\">" );
756 fprintf( stream
, "%s", _( "Email Address" ) );
757 fprintf( stream
, "</th>\n" );
758 fprintf( stream
, " <th width=\"200\">" );
759 fprintf( stream
, "%s", _( "Full Name" ) );
760 fprintf( stream
, "</th>\n" );
761 if( ctl
->showAttribs
) {
762 fprintf( stream
, " <th width=\"250\">" );
763 fprintf( stream
, "%s", _( "Attributes" ) );
764 fprintf( stream
, "</th>\n" );
766 fprintf( stream
, "</tr>\n" );
769 node
= list
= exporthtml_sort_name( folder
->listPerson
);
771 AddrItemObject
*aio
= node
->data
;
772 if( aio
&& aio
->type
== ITEMTYPE_PERSON
) {
773 ItemPerson
*person
= ( ItemPerson
* ) aio
;
775 /* Format first/last/nick name */
777 exporthtml_fmt_fullname( ctl
, buf
,person
);
779 fprintf( stream
, "<tr valign=\"top\"" );
782 tagName
= _idTagRowOdd_
;
785 tagName
= _idTagRowEven_
;
787 fprintf( stream
, " class=\"%s\"", tagName
);
790 fprintf( stream
, ">\n" );
792 fprintf( stream
, " <td class=\"tab-dn\">" );
793 fprintf( stream
, "%s", ADDRITEM_NAME( person
) );
794 fprintf( stream
, "</td>\n" );
796 fprintf( stream
, " <td class=\"tab-addr\">" );
797 exporthtml_fmt_email( ctl
, stream
, person
->listEMail
, FALSE
);
798 fprintf( stream
, "</td>\n" );
800 fprintf( stream
, " <td class=\"tab-fn\">" );
802 fprintf( stream
, "%s", buf
);
805 fprintf( stream
, "%s", SC_HTML_SPACE
);
807 fprintf( stream
, "</td>\n" );
809 if( ctl
->showAttribs
) {
810 fprintf( stream
, " <td class=\"tab-attr\">" );
811 exporthtml_fmt_attribs(
812 ctl
, stream
, person
->listAttrib
);
813 fprintf( stream
, "</td>\n" );
815 fprintf( stream
, "</tr>\n" );
819 node
= g_list_next( node
);
823 fprintf( stream
, "</table>\n" );
828 * Format folder heirarchy.
829 * Enter: stream Output stream.
830 * list Heirarchy list.
832 static void exporthtml_fmt_folderhead( FILE *stream
, const GList
*list
) {
840 AddrItemObject
*aio
= node
->data
;
841 if( aio
&& aio
->type
== ITEMTYPE_FOLDER
) {
842 ItemFolder
*folder
= ( ItemFolder
* ) aio
;
844 name
= ADDRITEM_NAME( folder
);
847 fprintf( stream
, " > " );
849 fprintf( stream
, "%s", name
);
853 node
= g_list_next( node
);
858 * Format an address book folder.
859 * Enter: ctl Export control data.
860 * stream Output stream.
863 static void exporthtml_fmt_folder(
864 ExportHtmlCtl
*ctl
, FILE *stream
, const ItemFolder
*folder
)
867 GList
*listHeir
, *list
;
871 name
= ADDRITEM_NAME( folder
);
873 listHeir
= addritem_folder_path( folder
, TRUE
);
875 fprintf( stream
, "<p class=\"fmt-folder\">" );
876 fprintf( stream
, "%s: ", _( "Folder" ) );
877 exporthtml_fmt_folderhead( stream
, listHeir
);
878 fprintf( stream
, "</p>\n" );
879 g_list_free( listHeir
);
883 ret1
= exporthtml_fmt_person( ctl
, stream
, folder
);
884 exporthtml_fmt_group( ctl
, stream
, folder
, ret1
);
886 node
= list
= exporthtml_sort_name( folder
->listFolder
);
888 AddrItemObject
*aio
= node
->data
;
889 if( aio
&& aio
->type
== ITEMTYPE_FOLDER
) {
890 ItemFolder
*subFolder
= ( ItemFolder
* ) aio
;
891 exporthtml_fmt_folder( ctl
, stream
, subFolder
);
893 node
= g_list_next( node
);
901 * Format header block.
902 * Enter: ctl Export control data.
903 * stream Output stream.
906 static void exporthtml_fmt_header(
907 ExportHtmlCtl
*ctl
, FILE *stream
, gchar
*title
)
909 StylesheetEntry
*entry
;
911 entry
= exporthtml_find_stylesheet( ctl
);
914 "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" );
916 "\"http://www.w3.org/TR/html4/loose.dtd\">\n" );
917 fprintf( stream
, "<html>\n" );
918 fprintf( stream
, "<head>\n" );
920 if( ctl
->encoding
&& strlen( ctl
->encoding
) > 0 ) {
921 fprintf( stream
, "<meta " );
922 fprintf( stream
, "http-equiv=\"Content-Type\" " );
923 fprintf( stream
, "content=\"text/html; charset=%s\">\n",
927 fprintf( stream
, "<title>%s</title>\n", title
);
929 if( entry
!= NULL
) {
930 if( entry
->fileName
&& strlen( entry
->fileName
) > 0 ) {
931 fprintf( stream
, "<link " );
932 fprintf( stream
, "rel=\"stylesheet\" " );
933 fprintf( stream
, "type=\"text/css\" " );
934 fprintf( stream
, "href=\"%s\" >\n", entry
->fileName
);
937 fprintf( stream
, "</head>\n" );
941 * ============================================================================
942 * Export address book to HTML file.
943 * Enter: ctl Export control data.
944 * cache Address book/data source cache.
946 * ============================================================================
948 void exporthtml_process(
949 ExportHtmlCtl
*ctl
, AddressCache
*cache
)
951 ItemFolder
*rootFolder
;
958 htmlFile
= claws_fopen( ctl
->path
, "wb" );
960 /* Cannot open file */
961 g_print( "Cannot open file for write\n" );
962 ctl
->retVal
= MGU_OPEN_FILE
;
966 title
= _( "Claws Mail Address Book" );
967 rootFolder
= cache
->rootFolder
;
968 dsName
= cache
->name
;
970 exporthtml_fmt_header( ctl
, htmlFile
, title
);
972 fprintf( htmlFile
, "<body>\n" );
973 fprintf( htmlFile
, "<h1>%s</h1>\n", title
);
975 fprintf( htmlFile
, "<p class=\"fmt-folder\">" );
976 fprintf( htmlFile
, "%s: ", _( "Address Book" ) );
977 fprintf( htmlFile
, "%s", dsName
);
978 fprintf( htmlFile
, "</p>\n" );
980 exporthtml_fmt_folder( ctl
, htmlFile
, rootFolder
);
983 fprintf( htmlFile
, "<p>%s</p>\n", ctime_r( &tt
, buf
) );
984 fprintf( htmlFile
, "<hr width=\"100%%\">\n" );
986 fprintf( htmlFile
, "</body>\n" );
987 fprintf( htmlFile
, "</html>\n" );
989 claws_safe_fclose( htmlFile
);
990 ctl
->retVal
= MGU_SUCCESS
;
992 /* Create stylesheet files */
993 exporthtml_create_css_files( ctl
);
998 * Build full export file specification.
999 * Enter: ctl Export control data.
1001 static void exporthtml_build_filespec( ExportHtmlCtl
*ctl
) {
1004 fileSpec
= g_strconcat(
1005 ctl
->dirOutput
, G_DIR_SEPARATOR_S
, ctl
->fileHtml
, NULL
);
1006 ctl
->path
= mgu_replace_string( ctl
->path
, fileSpec
);
1011 * ============================================================================
1012 * Parse directory and filename from full export file specification.
1013 * Enter: ctl Export control data.
1014 * fileSpec File spec.
1015 * ============================================================================
1017 void exporthtml_parse_filespec( ExportHtmlCtl
*ctl
, gchar
*fileSpec
) {
1019 gchar
*base
= g_path_get_basename(fileSpec
);
1022 mgu_replace_string( ctl
->fileHtml
, base
);
1024 t
= g_path_get_dirname( fileSpec
);
1025 ctl
->dirOutput
= mgu_replace_string( ctl
->dirOutput
, t
);
1027 ctl
->path
= mgu_replace_string( ctl
->path
, fileSpec
);
1031 * ============================================================================
1032 * Create output directory.
1033 * Enter: ctl Export control data.
1034 * Return: TRUE if directory created.
1035 * ============================================================================
1037 gboolean
exporthtml_create_dir( ExportHtmlCtl
*ctl
) {
1038 gboolean retVal
= FALSE
;
1041 if( g_mkdir( ctl
->dirOutput
, S_IRWXU
) == 0 ) {
1045 ctl
->rcCreate
= errno
;
1051 * ============================================================================
1052 * Retrieve create directory error message.
1053 * Enter: ctl Export control data.
1055 * ============================================================================
1057 gchar
*exporthtml_get_create_msg( ExportHtmlCtl
*ctl
) {
1060 if( ctl
->rcCreate
== EEXIST
) {
1061 msg
= _( "Name already exists but is not a directory." );
1063 else if( ctl
->rcCreate
== EACCES
) {
1064 msg
= _( "No permissions to create directory." );
1066 else if( ctl
->rcCreate
== ENAMETOOLONG
) {
1067 msg
= _( "Name is too long." );
1070 msg
= _( "Not specified." );
1076 * Set default values.
1077 * Enter: ctl Export control data.
1079 static void exporthtml_default_values( ExportHtmlCtl
*ctl
) {
1083 get_home_dir(), G_DIR_SEPARATOR_S
,
1084 DFL_DIR_CLAWS_OUT
, NULL
);
1086 ctl
->dirOutput
= mgu_replace_string( ctl
->dirOutput
, str
);
1090 mgu_replace_string( ctl
->fileHtml
, DFL_FILE_CLAWS_OUT
);
1091 ctl
->encoding
= NULL
;
1092 ctl
->stylesheet
= EXPORT_HTML_ID_DEFAULT
;
1093 ctl
->nameFormat
= EXPORT_HTML_FIRST_LAST
;
1094 ctl
->banding
= TRUE
;
1095 ctl
->linkEMail
= TRUE
;
1096 ctl
->showAttribs
= TRUE
;
1097 ctl
->retVal
= MGU_SUCCESS
;
1101 * ============================================================================
1102 * Load settings from XML properties file.
1103 * Enter: ctl Export control data.
1104 * ============================================================================
1106 void exporthtml_load_settings( ExportHtmlCtl
*ctl
) {
1112 props
= xmlprops_create();
1113 xmlprops_set_path( props
, ctl
->settingsFile
);
1114 rc
= xmlprops_load_file( props
);
1117 xmlprops_get_property_s( props
, EXMLPROP_DIRECTORY
, buf
);
1118 ctl
->dirOutput
= mgu_replace_string( ctl
->dirOutput
, buf
);
1120 xmlprops_get_property_s( props
, EXMLPROP_FILE
, buf
);
1121 ctl
->fileHtml
= mgu_replace_string( ctl
->fileHtml
, buf
);
1124 xmlprops_get_property_i( props
, EXMLPROP_STYLESHEET
);
1126 xmlprops_get_property_i( props
, EXMLPROP_FMT_NAME
);
1128 xmlprops_get_property_b( props
, EXMLPROP_BANDING
);
1130 xmlprops_get_property_b( props
, EXMLPROP_FMT_EMAIL
);
1132 xmlprops_get_property_b( props
, EXMLPROP_FMT_ATTRIB
);
1135 /* Set default values */
1136 exporthtml_default_values( ctl
);
1138 exporthtml_build_filespec( ctl
);
1139 /* exporthtml_print( ctl, stdout ); */
1141 xmlprops_free( props
);
1145 * ============================================================================
1146 * Save settings to XML properties file.
1147 * Enter: ctl Export control data.
1148 * ============================================================================
1150 void exporthtml_save_settings( ExportHtmlCtl
*ctl
) {
1153 props
= xmlprops_create();
1154 xmlprops_set_path( props
, ctl
->settingsFile
);
1156 xmlprops_set_property( props
, EXMLPROP_DIRECTORY
, ctl
->dirOutput
);
1157 xmlprops_set_property( props
, EXMLPROP_FILE
, ctl
->fileHtml
);
1158 xmlprops_set_property_i( props
, EXMLPROP_STYLESHEET
, ctl
->stylesheet
);
1159 xmlprops_set_property_i( props
, EXMLPROP_FMT_NAME
, ctl
->nameFormat
);
1160 xmlprops_set_property_b( props
, EXMLPROP_BANDING
, ctl
->banding
);
1161 xmlprops_set_property_b( props
, EXMLPROP_FMT_EMAIL
, ctl
->linkEMail
);
1162 xmlprops_set_property_b( props
, EXMLPROP_FMT_ATTRIB
, ctl
->showAttribs
);
1163 if (xmlprops_save_file( props
) != MGU_SUCCESS
)
1164 g_warning("can't save settings");
1165 xmlprops_free( props
);
1169 * ============================================================================
1171 * ============================================================================