2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 2002-2012 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 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 #ifdef MKDIR_TAKES_ONE_ARG
49 #define mkdir(a,b) mkdir(a)
52 #define DFL_DIR_CLAWS_OUT "claws-mail-out"
53 #define DFL_FILE_CLAWS_OUT "addressbook.html"
55 #define FMT_BUFSIZE 2048
56 #define SC_HTML_SPACE " "
58 #define CELL_PADDING 2
59 #define CELL_SPACING 2
60 #define CHAR_ENCODING "UTF-8"
62 /* Stylesheet names */
63 #define FILENAME_NONE ""
64 #define FILENAME_DEFAULT "claws-mail.css"
65 #define FILENAME_FULL "full.css"
66 #define FILENAME_CUSTOM "custom.css"
67 #define FILENAME_CUSTOM2 "custom2.css"
68 #define FILENAME_CUSTOM3 "custom3.css"
69 #define FILENAME_CUSTOM4 "custom4.css"
71 /* Settings - properties */
72 #define EXML_PROPFILE_NAME "exporthtml.xml"
73 #define EXMLPROP_DIRECTORY "directory"
74 #define EXMLPROP_FILE "file"
75 #define EXMLPROP_STYLESHEET "stylesheet"
76 #define EXMLPROP_FMT_NAME "format-full-name"
77 #define EXMLPROP_FMT_EMAIL "format-email-links"
78 #define EXMLPROP_FMT_ATTRIB "format-attributes"
79 #define EXMLPROP_BANDING "color-banding"
80 #define EXMLPROP_VALUE_YES "y"
81 #define EXMLPROP_VALUE_NO "n"
83 static gchar
*_idTagRowEven_
= "tab-row0";
84 static gchar
*_idTagRowOdd_
= "tab-row1";
89 typedef struct _StylesheetEntry StylesheetEntry
;
90 struct _StylesheetEntry
{
97 * Build stylesheet entry.
98 * Enter: ctl Export control data.
103 static void exporthtml_build_entry(
104 ExportHtmlCtl
*ctl
, const gchar
*file
, const gint id
,
107 StylesheetEntry
*entry
;
109 entry
= g_new0( StylesheetEntry
, 1 );
110 entry
->fileName
= g_strdup( file
);
112 entry
->dflValue
= dfl
;
113 ctl
->listStyle
= g_list_append( ctl
->listStyle
, entry
);
117 * Free up object by releasing internal memory.
118 * Enter: ctl Export control data.
120 ExportHtmlCtl
*exporthtml_create( void ) {
121 ExportHtmlCtl
*ctl
= g_new0( ExportHtmlCtl
, 1 );
124 ctl
->dirOutput
= NULL
;
125 ctl
->fileHtml
= NULL
;
126 ctl
->encoding
= g_strconcat(CHAR_ENCODING
, NULL
);
127 ctl
->stylesheet
= EXPORT_HTML_ID_NONE
;
128 ctl
->nameFormat
= EXPORT_HTML_FIRST_LAST
;
129 ctl
->banding
= FALSE
;
130 ctl
->linkEMail
= FALSE
;
131 ctl
->showAttribs
= FALSE
;
132 ctl
->retVal
= MGU_SUCCESS
;
133 ctl
->listStyle
= NULL
;
135 ctl
->settingsFile
= g_strconcat(
136 get_rc_dir(), G_DIR_SEPARATOR_S
, EXML_PROPFILE_NAME
, NULL
);
138 /* Build stylesheet list */
139 exporthtml_build_entry(
140 ctl
, FILENAME_NONE
, EXPORT_HTML_ID_NONE
, FALSE
);
141 exporthtml_build_entry(
142 ctl
, FILENAME_DEFAULT
, EXPORT_HTML_ID_DEFAULT
, TRUE
);
143 exporthtml_build_entry(
144 ctl
, FILENAME_FULL
, EXPORT_HTML_ID_FULL
, FALSE
);
145 exporthtml_build_entry(
146 ctl
, FILENAME_CUSTOM
, EXPORT_HTML_ID_CUSTOM
, FALSE
);
147 exporthtml_build_entry(
148 ctl
, FILENAME_CUSTOM2
, EXPORT_HTML_ID_CUSTOM2
, FALSE
);
149 exporthtml_build_entry(
150 ctl
, FILENAME_CUSTOM3
, EXPORT_HTML_ID_CUSTOM3
, FALSE
);
151 exporthtml_build_entry(
152 ctl
, FILENAME_CUSTOM4
, EXPORT_HTML_ID_CUSTOM4
, FALSE
);
158 * Free up object by releasing internal memory.
159 * Enter: ctl Export control data.
161 void exporthtml_free( ExportHtmlCtl
*ctl
) {
163 StylesheetEntry
*entry
;
165 cm_return_if_fail( ctl
!= NULL
);
167 /* Free stylesheet list */
168 node
= ctl
->listStyle
;
170 entry
= ( StylesheetEntry
* ) node
->data
;
171 g_free( entry
->fileName
);
172 entry
->fileName
= NULL
;
174 entry
->dflValue
= FALSE
;
177 node
= g_list_next( node
);
179 g_list_free( ctl
->listStyle
);
180 ctl
->listStyle
= NULL
;
183 g_free( ctl
->fileHtml
);
184 g_free( ctl
->encoding
);
185 g_free( ctl
->dirOutput
);
186 g_free( ctl
->settingsFile
);
190 ctl
->dirOutput
= NULL
;
191 ctl
->fileHtml
= NULL
;
192 ctl
->encoding
= NULL
;
193 ctl
->stylesheet
= EXPORT_HTML_ID_NONE
;
194 ctl
->nameFormat
= EXPORT_HTML_FIRST_LAST
;
195 ctl
->banding
= FALSE
;
196 ctl
->linkEMail
= FALSE
;
197 ctl
->showAttribs
= FALSE
;
198 ctl
->retVal
= MGU_SUCCESS
;
201 /* Now release object */
207 * Enter: ctl Export control data.
208 * Return: Stylesheet object, or NULL if nothing found. If a default entry is
209 * found in list, it will be returned.
211 static StylesheetEntry
*exporthtml_find_stylesheet( ExportHtmlCtl
*ctl
) {
212 StylesheetEntry
*retVal
= NULL
;
213 StylesheetEntry
*entry
;
216 node
= ctl
->listStyle
;
218 entry
= ( StylesheetEntry
* ) node
->data
;
219 if( entry
->id
== ctl
->stylesheet
) return entry
;
220 if( entry
->dflValue
) retVal
= entry
;
221 node
= g_list_next( node
);
226 void exporthtml_set_stylesheet( ExportHtmlCtl
*ctl
, const gint value
) {
227 cm_return_if_fail( ctl
!= NULL
);
228 ctl
->stylesheet
= value
;
230 void exporthtml_set_name_format( ExportHtmlCtl
*ctl
, const gint value
) {
231 cm_return_if_fail( ctl
!= NULL
);
232 ctl
->nameFormat
= value
;
234 void exporthtml_set_banding( ExportHtmlCtl
*ctl
, const gboolean value
) {
235 cm_return_if_fail( ctl
!= NULL
);
236 ctl
->banding
= value
;
238 void exporthtml_set_link_email( ExportHtmlCtl
*ctl
, const gboolean value
) {
239 cm_return_if_fail( ctl
!= NULL
);
240 ctl
->linkEMail
= value
;
242 void exporthtml_set_attributes( ExportHtmlCtl
*ctl
, const gboolean value
) {
243 cm_return_if_fail( ctl
!= NULL
);
244 ctl
->showAttribs
= value
;
248 * Create default CSS file.
249 * Enter: fileSpec File to create.
250 * Return: Status code.
252 static gint
exporthtml_create_css_dfl( const gchar
*fileSpec
) {
255 cssFile
= claws_fopen( fileSpec
, "rb" );
257 claws_fclose( cssFile
);
260 cssFile
= claws_fopen( fileSpec
, "wb" );
262 return MGU_OPEN_FILE
;
265 fprintf( cssFile
, "body {\n\tbackground: #ffffe0;\n" );
266 fprintf( cssFile
, "\tfont-family: lucida, helvetica, sans-serif;\n" );
267 fprintf( cssFile
, "\tfont-size: 10pt;\n" );
268 fprintf( cssFile
, "}\n" );
269 fprintf( cssFile
, "h1 {\n" );
270 fprintf( cssFile
, "\tcolor: #000000;\n" );
271 fprintf( cssFile
, "\ttext-align: center;\n" );
272 fprintf( cssFile
, "}\n" );
273 fprintf( cssFile
, "th {\n" );
274 fprintf( cssFile
, "\tfont-size: 10pt;\n" );
275 fprintf( cssFile
, "}\n" );
276 fprintf( cssFile
, "td {\n" );
277 fprintf( cssFile
, "\tfont-size: 10pt;\n" );
278 fprintf( cssFile
, "}\n" );
279 fprintf( cssFile
, ".fmt-folder {\n" );
280 fprintf( cssFile
, "\tcolor: #0000ff;\n" );
281 fprintf( cssFile
, "\tfont-size: 18pt;\n" );
282 fprintf( cssFile
, "\tfont-weight: bold;\n" );
283 fprintf( cssFile
, "}\n" );
284 fprintf( cssFile
, ".tab-head {\n" );
285 fprintf( cssFile
, "\tbackground: #80c0f0;\n" );
286 fprintf( cssFile
, "}\n" );
287 fprintf( cssFile
, ".tab-dn {\n" );
288 fprintf( cssFile
, "}\n" );
289 fprintf( cssFile
, ".tab-addr {\n" );
290 fprintf( cssFile
, "\tfont-style: italic;\n" );
291 fprintf( cssFile
, "}\n" );
292 fprintf( cssFile
, ".tab-email {\n" );
293 fprintf( cssFile
, "\tfont-weight: bold;\n" );
294 fprintf( cssFile
, "\tfont-style: italic;\n" );
295 fprintf( cssFile
, "}\n" );
296 fprintf( cssFile
, ".tab-fn {\n" );
297 fprintf( cssFile
, "}\n" );
298 fprintf( cssFile
, ".tab-attr {\n" );
299 fprintf( cssFile
, "}\n" );
301 claws_safe_fclose( cssFile
);
306 * Create full CSS file.
307 * Enter: fileSpec File to create.
308 * Return: Status code.
310 static gint
exporthtml_create_css_full( const gchar
*fileSpec
) {
313 cssFile
= claws_fopen( fileSpec
, "rb" );
315 claws_fclose( cssFile
);
318 cssFile
= claws_fopen( fileSpec
, "wb" );
320 return MGU_OPEN_FILE
;
323 fprintf( cssFile
, "body {\n\tbackground: #ffffe0;\n" );
324 fprintf( cssFile
, "\tfont-family: lucida, helvetica, sans-serif;\n" );
325 fprintf( cssFile
, "\tfont-size: 10pt;\n" );
326 fprintf( cssFile
, "}\n" );
327 fprintf( cssFile
, "h1 {\n" );
328 fprintf( cssFile
, "\tcolor: #000000;\n" );
329 fprintf( cssFile
, "\ttext-align: center;\n" );
330 fprintf( cssFile
, "}\n" );
331 fprintf( cssFile
, "th {\n" );
332 fprintf( cssFile
, "\tfont-size: 10pt;\n" );
333 fprintf( cssFile
, "}\n" );
334 fprintf( cssFile
, "td {\n" );
335 fprintf( cssFile
, "\tfont-size: 10pt;\n" );
336 fprintf( cssFile
, "}\n" );
337 fprintf( cssFile
, ".fmt-folder {\n" );
338 fprintf( cssFile
, "\tcolor: #0000ff;\n" );
339 fprintf( cssFile
, "\tfont-size: 18pt;\n" );
340 fprintf( cssFile
, "\tfont-weight: bold;\n" );
341 fprintf( cssFile
, "}\n" );
342 fprintf( cssFile
, ".tab-head {\n" );
343 fprintf( cssFile
, "\tbackground: #80c0f0;\n" );
344 fprintf( cssFile
, "}\n" );
345 fprintf( cssFile
, ".tab-row0 {\n" );
346 fprintf( cssFile
, "\tbackground: #f0f0f0;\n" );
347 fprintf( cssFile
, "}\n" );
348 fprintf( cssFile
, ".tab-row1 {\n" );
349 fprintf( cssFile
, "\tbackground: #d0d0d0;\n" );
350 fprintf( cssFile
, "}\n" );
351 fprintf( cssFile
, ".tab-dn {\n" );
352 fprintf( cssFile
, "}\n" );
353 fprintf( cssFile
, ".tab-addr {\n" );
354 fprintf( cssFile
, "\tfont-style: italic;\n" );
355 fprintf( cssFile
, "}\n" );
356 fprintf( cssFile
, ".tab-email {\n" );
357 fprintf( cssFile
, "\tfont-weight: bold;\n" );
358 fprintf( cssFile
, "\tfont-style: italic;\n" );
359 fprintf( cssFile
, "}\n" );
360 fprintf( cssFile
, ".tab-fn {\n" );
361 fprintf( cssFile
, "}\n" );
362 fprintf( cssFile
, ".tab-attr {\n" );
363 fprintf( cssFile
, "}\n" );
365 claws_safe_fclose( cssFile
);
370 * Create stylesheet files.
371 * Enter: ctl Export control data.
373 static void exporthtml_create_css_files( ExportHtmlCtl
*ctl
) {
377 node
= ctl
->listStyle
;
379 StylesheetEntry
*entry
= node
->data
;
380 node
= g_list_next( node
);
381 if( strlen( entry
->fileName
) ) {
382 fileSpec
= g_strconcat(
383 ctl
->dirOutput
, G_DIR_SEPARATOR_S
,
384 entry
->fileName
, NULL
);
385 if( entry
->id
== EXPORT_HTML_ID_DEFAULT
) {
386 exporthtml_create_css_dfl( fileSpec
);
388 else if( entry
->id
!= EXPORT_HTML_ID_NONE
) {
389 exporthtml_create_css_full( fileSpec
);
397 * Comparison using linked list elements.
399 static gint
exporthtml_compare_name(
400 gconstpointer ptr1
, gconstpointer ptr2
)
402 const AddrItemObject
*item1
= ptr1
;
403 const AddrItemObject
*item2
= ptr2
;
404 const gchar
*name1
= NULL
, *name2
= NULL
;
405 if( item1
) name1
= ADDRITEM_NAME( item1
);
406 if( item2
) name2
= ADDRITEM_NAME( item2
);
407 if( ! name1
) return ( name2
!= NULL
);
408 if( ! name2
) return -1;
409 return g_utf8_collate( name1
, name2
);
413 * Comparison using linked list elements.
415 static gint
exporthtml_compare_email(
416 gconstpointer ptr1
, gconstpointer ptr2
)
418 const ItemEMail
*email1
= ptr1
;
419 const ItemEMail
*email2
= ptr2
;
420 const gchar
*name1
= NULL
, *name2
= NULL
;
421 if( email1
) name1
= email1
->address
;
422 if( email2
) name2
= email2
->address
;
423 if( ! name1
) return ( name2
!= NULL
);
424 if( ! name2
) return -1;
425 return g_utf8_collate( name1
, name2
);
429 * Comparison using linked list elements.
431 static gint
exporthtml_compare_attrib(
432 gconstpointer ptr1
, gconstpointer ptr2
)
434 const UserAttribute
*attr1
= ptr1
;
435 const UserAttribute
*attr2
= ptr2
;
436 const gchar
*name1
= NULL
, *name2
= NULL
;
437 if( attr1
) name1
= attr1
->name
;
438 if( attr2
) name2
= attr2
->name
;
439 if( ! name1
) return ( name2
!= NULL
);
440 if( ! name2
) return -1;
441 return g_utf8_collate( name1
, name2
);
445 * Build sorted list of named items.
446 * Enter: list List of items to sorted.
447 * Return: Sorted list.
448 * Note: List should freed after use. Items referenced by list should not be
449 * freed since they are managed by the address cache.
451 static GList
*exporthtml_sort_name( const GList
*list
) {
453 GList
*sorted
= NULL
;
457 sorted
= g_list_insert_sorted(
458 sorted
, node
->data
, exporthtml_compare_name
);
459 node
= g_list_next( node
);
465 * Build sorted list of email items.
466 * Enter: list List of E-Mail items to sorted.
467 * Return: Sorted list.
468 * Note: List should freed after use. Items referenced by list should not be
469 * freed since they are managed by the address cache.
471 static GList
*exporthtml_sort_email( const GList
*list
) {
473 GList
*sorted
= NULL
;
477 sorted
= g_list_insert_sorted(
478 sorted
, node
->data
, exporthtml_compare_email
);
479 node
= g_list_next( node
);
485 * Build sorted list of attributes.
486 * Enter: list List of items to sorted.
487 * Return: Sorted list.
488 * Note: List should freed after use. Items referenced by list should not be
489 * freed since they are managed by the address cache.
491 static GList
*exporthtml_sort_attrib( const GList
*list
) {
493 GList
*sorted
= NULL
;
498 sorted
= g_list_insert_sorted(
499 sorted
, node
->data
, exporthtml_compare_attrib
);
500 node
= g_list_next( node
);
506 * Format a list of E-Mail addresses.
507 * Enter: ctl Export control data.
508 * stream Output stream.
509 * listEMail List of addresses.
510 * sortFlag Set to TRUE if address list should be sorted.
512 static void exporthtml_fmt_email(
513 ExportHtmlCtl
*ctl
, FILE *stream
, const GList
*listEMail
,
520 if( listEMail
== NULL
) {
521 fprintf( stream
, SC_HTML_SPACE
);
527 node
= list
= exporthtml_sort_email( listEMail
);
534 ItemEMail
*email
= ( ItemEMail
* ) node
->data
;
535 node
= g_list_next( node
);
537 name
= ADDRITEM_NAME( email
);
539 fprintf( stream
, "%s ", name
);
541 if( ctl
->linkEMail
) {
542 fprintf( stream
, "<a href=\"mailto:%s\">",
545 fprintf( stream
, "<span class=\"tab-email\">" );
546 fprintf( stream
, "%s", email
->address
);
547 fprintf( stream
, "</span>" );
548 if( ctl
->linkEMail
) {
549 fprintf( stream
, "</a>" );
551 if( email
->remarks
) {
552 if( strlen( email
->remarks
) ) {
553 fprintf( stream
, " (%s)", email
->remarks
);
556 fprintf( stream
, "<br>\n" );
562 * Format groups in an address book folder.
563 * Enter: ctl Export control data.
564 * stream Output stream.
566 * prevFlag If FALSE, list of persons were output.
567 * Return: TRUE if no groups were formatted.
569 static gboolean
exporthtml_fmt_group(
570 ExportHtmlCtl
*ctl
, FILE *stream
, const ItemFolder
*folder
,
573 gboolean retVal
, band
;
575 const gchar
*tagName
;
578 if( folder
->listGroup
== NULL
) return retVal
;
580 /* Write separator */
582 fprintf( stream
, "<br>\n" );
585 /* Write table headers */
586 fprintf( stream
, "<table" );
587 fprintf( stream
, " border=\"%d\"", BORDER_SIZE
);
588 fprintf( stream
, " cellpadding=\"%d\"", CELL_PADDING
);
589 fprintf( stream
, " cellspacing=\"%d\"", CELL_SPACING
);
590 fprintf( stream
, ">\n" );
592 fprintf( stream
, "<tr class=\"tab-head\">\n" );
593 fprintf( stream
, " <th width=\"200\">" );
594 fprintf( stream
, "%s", _( "Group Name" ) );
595 fprintf( stream
, "</th>\n" );
596 fprintf( stream
, " <th width=\"300\">" );
597 fprintf( stream
, "%s", _( "Email Address" ) );
598 fprintf( stream
, "</th>\n" );
599 fprintf( stream
, "</tr>\n" );
600 list
= exporthtml_sort_name( folder
->listGroup
);
605 AddrItemObject
*aio
= node
->data
;
606 if( aio
&& aio
->type
== ITEMTYPE_GROUP
) {
607 ItemGroup
*group
= ( ItemGroup
* ) aio
;
609 fprintf( stream
, "<tr valign=\"top\"" );
612 tagName
= _idTagRowOdd_
;
615 tagName
= _idTagRowEven_
;
617 fprintf( stream
, " class=\"%s\"", tagName
);
620 fprintf( stream
, "\">\n" );
622 fprintf( stream
, " <td class=\"tab-dn\">" );
623 fprintf( stream
, "%s", ADDRITEM_NAME( group
) );
624 fprintf( stream
, "</td>\n" );
625 fprintf( stream
, " <td class=\"tab-addr\">" );
626 exporthtml_fmt_email( ctl
, stream
, group
->listEMail
, TRUE
);
627 fprintf( stream
, "</td>\n" );
628 fprintf( stream
, "</tr>\n" );
631 node
= g_list_next( node
);
635 fprintf( stream
, "</table>\n" );
640 * Format a list of E-Mail addresses.
641 * Enter: ctl Export control data.
642 * stream Output stream.
643 * listAttr List of attributes.
645 static void exporthtml_fmt_attribs(
646 ExportHtmlCtl
*ctl
, FILE *stream
, const GList
*listAttr
)
651 if( listAttr
== NULL
) {
652 fprintf( stream
, SC_HTML_SPACE
);
656 fprintf( stream
, "<table border=\"0\">\n" );
657 node
= list
= exporthtml_sort_attrib( listAttr
);
659 UserAttribute
*attr
= ( UserAttribute
* ) node
->data
;
660 node
= g_list_next( node
);
661 fprintf( stream
, "<tr valign=\"top\">" );
662 fprintf( stream
, "<td align=\"right\">%s:</td>", attr
->name
);
663 fprintf( stream
, "<td>%s</td>", attr
->value
);
664 fprintf( stream
, "</tr>\n" );
668 fprintf( stream
, "</table>" );
673 * Enter: ctl Export control data.
675 * person Person to format.
677 static void exporthtml_fmt_fullname(
678 ExportHtmlCtl
*ctl
, gchar
*buf
, const ItemPerson
*person
)
682 if( ctl
->nameFormat
== EXPORT_HTML_LAST_FIRST
) {
684 if( person
->lastName
) {
685 if( *person
->lastName
) {
687 strcat( buf
, person
->lastName
);
691 if( person
->firstName
) {
692 if( *person
->firstName
) {
696 strcat( buf
, person
->firstName
);
701 if( person
->firstName
) {
702 if( *person
->firstName
) {
703 strcat( buf
, person
->firstName
);
706 if( person
->lastName
) {
707 if( *person
->lastName
) {
709 strcat( buf
, person
->lastName
);
716 if( *buf
) flag
= TRUE
;
717 if( person
->nickName
) {
718 if( strlen( person
->nickName
) ) {
722 strcat( buf
, person
->nickName
);
732 * Format persons in an address book folder.
733 * Enter: ctl Export control data.
734 * stream Output stream.
736 * Return: TRUE if no persons were formatted.
738 static gboolean
exporthtml_fmt_person(
739 ExportHtmlCtl
*ctl
, FILE *stream
, const ItemFolder
*folder
)
741 gboolean retVal
, band
;
743 gchar buf
[ FMT_BUFSIZE
];
744 const gchar
*tagName
;
747 if( folder
->listPerson
== NULL
) return retVal
;
749 /* Write table headers */
750 fprintf( stream
, "<table" );
751 fprintf( stream
, " border=\"%d\"", BORDER_SIZE
);
752 fprintf( stream
, " cellpadding=\"%d\"", CELL_PADDING
);
753 fprintf( stream
, " cellspacing=\"%d\"", CELL_SPACING
);
754 fprintf( stream
, ">\n" );
756 fprintf( stream
, "<tr class=\"tab-head\">\n" );
757 fprintf( stream
, " <th width=\"200\">" );
758 fprintf( stream
, "%s", _( "Display Name" ) );
759 fprintf( stream
, "</th>\n" );
760 fprintf( stream
, " <th width=\"300\">" );
761 fprintf( stream
, "%s", _( "Email Address" ) );
762 fprintf( stream
, "</th>\n" );
763 fprintf( stream
, " <th width=\"200\">" );
764 fprintf( stream
, "%s", _( "Full Name" ) );
765 fprintf( stream
, "</th>\n" );
766 if( ctl
->showAttribs
) {
767 fprintf( stream
, " <th width=\"250\">" );
768 fprintf( stream
, "%s", _( "Attributes" ) );
769 fprintf( stream
, "</th>\n" );
771 fprintf( stream
, "</tr>\n" );
774 node
= list
= exporthtml_sort_name( folder
->listPerson
);
776 AddrItemObject
*aio
= node
->data
;
777 if( aio
&& aio
->type
== ITEMTYPE_PERSON
) {
778 ItemPerson
*person
= ( ItemPerson
* ) aio
;
780 /* Format first/last/nick name */
782 exporthtml_fmt_fullname( ctl
, buf
,person
);
784 fprintf( stream
, "<tr valign=\"top\"" );
787 tagName
= _idTagRowOdd_
;
790 tagName
= _idTagRowEven_
;
792 fprintf( stream
, " class=\"%s\"", tagName
);
795 fprintf( stream
, ">\n" );
797 fprintf( stream
, " <td class=\"tab-dn\">" );
798 fprintf( stream
, "%s", ADDRITEM_NAME( person
) );
799 fprintf( stream
, "</td>\n" );
801 fprintf( stream
, " <td class=\"tab-addr\">" );
802 exporthtml_fmt_email( ctl
, stream
, person
->listEMail
, FALSE
);
803 fprintf( stream
, "</td>\n" );
805 fprintf( stream
, " <td class=\"tab-fn\">" );
807 fprintf( stream
, "%s", buf
);
810 fprintf( stream
, "%s", SC_HTML_SPACE
);
812 fprintf( stream
, "</td>\n" );
814 if( ctl
->showAttribs
) {
815 fprintf( stream
, " <td class=\"tab-attr\">" );
816 exporthtml_fmt_attribs(
817 ctl
, stream
, person
->listAttrib
);
818 fprintf( stream
, "</td>\n" );
820 fprintf( stream
, "</tr>\n" );
824 node
= g_list_next( node
);
828 fprintf( stream
, "</table>\n" );
833 * Format folder heirarchy.
834 * Enter: stream Output stream.
835 * list Heirarchy list.
837 static void exporthtml_fmt_folderhead( FILE *stream
, const GList
*list
) {
845 AddrItemObject
*aio
= node
->data
;
846 if( aio
&& aio
->type
== ITEMTYPE_FOLDER
) {
847 ItemFolder
*folder
= ( ItemFolder
* ) aio
;
849 name
= ADDRITEM_NAME( folder
);
852 fprintf( stream
, " > " );
854 fprintf( stream
, "%s", name
);
858 node
= g_list_next( node
);
863 * Format an address book folder.
864 * Enter: ctl Export control data.
865 * stream Output stream.
868 static void exporthtml_fmt_folder(
869 ExportHtmlCtl
*ctl
, FILE *stream
, const ItemFolder
*folder
)
872 GList
*listHeir
, *list
;
876 name
= ADDRITEM_NAME( folder
);
878 listHeir
= addritem_folder_path( folder
, TRUE
);
880 fprintf( stream
, "<p class=\"fmt-folder\">" );
881 fprintf( stream
, "%s: ", _( "Folder" ) );
882 exporthtml_fmt_folderhead( stream
, listHeir
);
883 fprintf( stream
, "</p>\n" );
884 g_list_free( listHeir
);
888 ret1
= exporthtml_fmt_person( ctl
, stream
, folder
);
889 exporthtml_fmt_group( ctl
, stream
, folder
, ret1
);
891 node
= list
= exporthtml_sort_name( folder
->listFolder
);
893 AddrItemObject
*aio
= node
->data
;
894 if( aio
&& aio
->type
== ITEMTYPE_FOLDER
) {
895 ItemFolder
*subFolder
= ( ItemFolder
* ) aio
;
896 exporthtml_fmt_folder( ctl
, stream
, subFolder
);
898 node
= g_list_next( node
);
906 * Format header block.
907 * Enter: ctl Export control data.
908 * stream Output stream.
911 static void exporthtml_fmt_header(
912 ExportHtmlCtl
*ctl
, FILE *stream
, gchar
*title
)
914 StylesheetEntry
*entry
;
916 entry
= exporthtml_find_stylesheet( ctl
);
919 "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" );
921 "\"http://www.w3.org/TR/html4/loose.dtd\">\n" );
922 fprintf( stream
, "<html>\n" );
923 fprintf( stream
, "<head>\n" );
925 if( ctl
->encoding
&& strlen( ctl
->encoding
) > 0 ) {
926 fprintf( stream
, "<meta " );
927 fprintf( stream
, "http-equiv=\"Content-Type\" " );
928 fprintf( stream
, "content=\"text/html; charset=%s\">\n",
932 fprintf( stream
, "<title>%s</title>\n", title
);
934 if( entry
!= NULL
) {
935 if( entry
->fileName
&& strlen( entry
->fileName
) > 0 ) {
936 fprintf( stream
, "<link " );
937 fprintf( stream
, "rel=\"stylesheet\" " );
938 fprintf( stream
, "type=\"text/css\" " );
939 fprintf( stream
, "href=\"%s\" >\n", entry
->fileName
);
942 fprintf( stream
, "</head>\n" );
946 * ============================================================================
947 * Export address book to HTML file.
948 * Enter: ctl Export control data.
949 * cache Address book/data source cache.
951 * ============================================================================
953 void exporthtml_process(
954 ExportHtmlCtl
*ctl
, AddressCache
*cache
)
956 ItemFolder
*rootFolder
;
963 htmlFile
= claws_fopen( ctl
->path
, "wb" );
965 /* Cannot open file */
966 g_print( "Cannot open file for write\n" );
967 ctl
->retVal
= MGU_OPEN_FILE
;
971 title
= _( "Claws Mail Address Book" );
972 rootFolder
= cache
->rootFolder
;
973 dsName
= cache
->name
;
975 exporthtml_fmt_header( ctl
, htmlFile
, title
);
977 fprintf( htmlFile
, "<body>\n" );
978 fprintf( htmlFile
, "<h1>%s</h1>\n", title
);
980 fprintf( htmlFile
, "<p class=\"fmt-folder\">" );
981 fprintf( htmlFile
, "%s: ", _( "Address Book" ) );
982 fprintf( htmlFile
, "%s", dsName
);
983 fprintf( htmlFile
, "</p>\n" );
985 exporthtml_fmt_folder( ctl
, htmlFile
, rootFolder
);
988 fprintf( htmlFile
, "<p>%s</p>\n", ctime_r( &tt
, buf
) );
989 fprintf( htmlFile
, "<hr width=\"100%%\">\n" );
991 fprintf( htmlFile
, "</body>\n" );
992 fprintf( htmlFile
, "</html>\n" );
994 claws_safe_fclose( htmlFile
);
995 ctl
->retVal
= MGU_SUCCESS
;
997 /* Create stylesheet files */
998 exporthtml_create_css_files( ctl
);
1003 * Build full export file specification.
1004 * Enter: ctl Export control data.
1006 static void exporthtml_build_filespec( ExportHtmlCtl
*ctl
) {
1009 fileSpec
= g_strconcat(
1010 ctl
->dirOutput
, G_DIR_SEPARATOR_S
, ctl
->fileHtml
, NULL
);
1011 ctl
->path
= mgu_replace_string( ctl
->path
, fileSpec
);
1016 * ============================================================================
1017 * Parse directory and filename from full export file specification.
1018 * Enter: ctl Export control data.
1019 * fileSpec File spec.
1020 * ============================================================================
1022 void exporthtml_parse_filespec( ExportHtmlCtl
*ctl
, gchar
*fileSpec
) {
1024 gchar
*base
= g_path_get_basename(fileSpec
);
1027 mgu_replace_string( ctl
->fileHtml
, base
);
1029 t
= g_path_get_dirname( fileSpec
);
1030 ctl
->dirOutput
= mgu_replace_string( ctl
->dirOutput
, t
);
1032 ctl
->path
= mgu_replace_string( ctl
->path
, fileSpec
);
1036 * ============================================================================
1037 * Create output directory.
1038 * Enter: ctl Export control data.
1039 * Return: TRUE if directory created.
1040 * ============================================================================
1042 gboolean
exporthtml_create_dir( ExportHtmlCtl
*ctl
) {
1043 gboolean retVal
= FALSE
;
1046 if( mkdir( ctl
->dirOutput
, S_IRWXU
) == 0 ) {
1050 ctl
->rcCreate
= errno
;
1056 * ============================================================================
1057 * Retrieve create directory error message.
1058 * Enter: ctl Export control data.
1060 * ============================================================================
1062 gchar
*exporthtml_get_create_msg( ExportHtmlCtl
*ctl
) {
1065 if( ctl
->rcCreate
== EEXIST
) {
1066 msg
= _( "Name already exists but is not a directory." );
1068 else if( ctl
->rcCreate
== EACCES
) {
1069 msg
= _( "No permissions to create directory." );
1071 else if( ctl
->rcCreate
== ENAMETOOLONG
) {
1072 msg
= _( "Name is too long." );
1075 msg
= _( "Not specified." );
1081 * Set default values.
1082 * Enter: ctl Export control data.
1084 static void exporthtml_default_values( ExportHtmlCtl
*ctl
) {
1088 get_home_dir(), G_DIR_SEPARATOR_S
,
1089 DFL_DIR_CLAWS_OUT
, NULL
);
1091 ctl
->dirOutput
= mgu_replace_string( ctl
->dirOutput
, str
);
1095 mgu_replace_string( ctl
->fileHtml
, DFL_FILE_CLAWS_OUT
);
1096 ctl
->encoding
= NULL
;
1097 ctl
->stylesheet
= EXPORT_HTML_ID_DEFAULT
;
1098 ctl
->nameFormat
= EXPORT_HTML_FIRST_LAST
;
1099 ctl
->banding
= TRUE
;
1100 ctl
->linkEMail
= TRUE
;
1101 ctl
->showAttribs
= TRUE
;
1102 ctl
->retVal
= MGU_SUCCESS
;
1106 * ============================================================================
1107 * Load settings from XML properties file.
1108 * Enter: ctl Export control data.
1109 * ============================================================================
1111 void exporthtml_load_settings( ExportHtmlCtl
*ctl
) {
1117 props
= xmlprops_create();
1118 xmlprops_set_path( props
, ctl
->settingsFile
);
1119 rc
= xmlprops_load_file( props
);
1122 xmlprops_get_property_s( props
, EXMLPROP_DIRECTORY
, buf
);
1123 ctl
->dirOutput
= mgu_replace_string( ctl
->dirOutput
, buf
);
1125 xmlprops_get_property_s( props
, EXMLPROP_FILE
, buf
);
1126 ctl
->fileHtml
= mgu_replace_string( ctl
->fileHtml
, buf
);
1129 xmlprops_get_property_i( props
, EXMLPROP_STYLESHEET
);
1131 xmlprops_get_property_i( props
, EXMLPROP_FMT_NAME
);
1133 xmlprops_get_property_b( props
, EXMLPROP_BANDING
);
1135 xmlprops_get_property_b( props
, EXMLPROP_FMT_EMAIL
);
1137 xmlprops_get_property_b( props
, EXMLPROP_FMT_ATTRIB
);
1140 /* Set default values */
1141 exporthtml_default_values( ctl
);
1143 exporthtml_build_filespec( ctl
);
1144 /* exporthtml_print( ctl, stdout ); */
1146 xmlprops_free( props
);
1150 * ============================================================================
1151 * Save settings to XML properties file.
1152 * Enter: ctl Export control data.
1153 * ============================================================================
1155 void exporthtml_save_settings( ExportHtmlCtl
*ctl
) {
1158 props
= xmlprops_create();
1159 xmlprops_set_path( props
, ctl
->settingsFile
);
1161 xmlprops_set_property( props
, EXMLPROP_DIRECTORY
, ctl
->dirOutput
);
1162 xmlprops_set_property( props
, EXMLPROP_FILE
, ctl
->fileHtml
);
1163 xmlprops_set_property_i( props
, EXMLPROP_STYLESHEET
, ctl
->stylesheet
);
1164 xmlprops_set_property_i( props
, EXMLPROP_FMT_NAME
, ctl
->nameFormat
);
1165 xmlprops_set_property_b( props
, EXMLPROP_BANDING
, ctl
->banding
);
1166 xmlprops_set_property_b( props
, EXMLPROP_FMT_EMAIL
, ctl
->linkEMail
);
1167 xmlprops_set_property_b( props
, EXMLPROP_FMT_ATTRIB
, ctl
->showAttribs
);
1168 if (xmlprops_save_file( props
) != MGU_SUCCESS
)
1169 g_warning("can't save settings");
1170 xmlprops_free( props
);
1174 * ============================================================================
1176 * ============================================================================