2 * Sylpheed -- 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>
47 #include "exporthtml.h"
49 #include "file-utils.h"
51 #ifdef MKDIR_TAKES_ONE_ARG
53 #define mkdir(a,b) mkdir(a)
56 #define DFL_DIR_CLAWS_OUT "claws-mail-out"
57 #define DFL_FILE_CLAWS_OUT "addressbook.html"
59 #define FMT_BUFSIZE 2048
60 #define SC_HTML_SPACE " "
62 #define CELL_PADDING 2
63 #define CELL_SPACING 2
64 #define CHAR_ENCODING "UTF-8"
66 /* Stylesheet names */
67 #define FILENAME_NONE ""
68 #define FILENAME_DEFAULT "claws-mail.css"
69 #define FILENAME_FULL "full.css"
70 #define FILENAME_CUSTOM "custom.css"
71 #define FILENAME_CUSTOM2 "custom2.css"
72 #define FILENAME_CUSTOM3 "custom3.css"
73 #define FILENAME_CUSTOM4 "custom4.css"
75 /* Settings - properties */
76 #define EXML_PROPFILE_NAME "exporthtml.xml"
77 #define EXMLPROP_DIRECTORY "directory"
78 #define EXMLPROP_FILE "file"
79 #define EXMLPROP_STYLESHEET "stylesheet"
80 #define EXMLPROP_FMT_NAME "format-full-name"
81 #define EXMLPROP_FMT_EMAIL "format-email-links"
82 #define EXMLPROP_FMT_ATTRIB "format-attributes"
83 #define EXMLPROP_BANDING "color-banding"
84 #define EXMLPROP_VALUE_YES "y"
85 #define EXMLPROP_VALUE_NO "n"
87 static gchar
*_idTagRowEven_
= "tab-row0";
88 static gchar
*_idTagRowOdd_
= "tab-row1";
93 typedef struct _StylesheetEntry StylesheetEntry
;
94 struct _StylesheetEntry
{
101 * Build stylesheet entry.
102 * Enter: ctl Export control data.
107 static void exporthtml_build_entry(
108 ExportHtmlCtl
*ctl
, const gchar
*file
, const gint id
,
111 StylesheetEntry
*entry
;
113 entry
= g_new0( StylesheetEntry
, 1 );
114 entry
->fileName
= g_strdup( file
);
116 entry
->dflValue
= dfl
;
117 ctl
->listStyle
= g_list_append( ctl
->listStyle
, entry
);
121 * Free up object by releasing internal memory.
122 * Enter: ctl Export control data.
124 ExportHtmlCtl
*exporthtml_create( void ) {
125 ExportHtmlCtl
*ctl
= g_new0( ExportHtmlCtl
, 1 );
128 ctl
->dirOutput
= NULL
;
129 ctl
->fileHtml
= NULL
;
130 ctl
->encoding
= g_strconcat(CHAR_ENCODING
, NULL
);
131 ctl
->stylesheet
= EXPORT_HTML_ID_NONE
;
132 ctl
->nameFormat
= EXPORT_HTML_FIRST_LAST
;
133 ctl
->banding
= FALSE
;
134 ctl
->linkEMail
= FALSE
;
135 ctl
->showAttribs
= FALSE
;
136 ctl
->retVal
= MGU_SUCCESS
;
137 ctl
->listStyle
= NULL
;
139 ctl
->settingsFile
= g_strconcat(
140 get_rc_dir(), G_DIR_SEPARATOR_S
, EXML_PROPFILE_NAME
, NULL
);
142 /* Build stylesheet list */
143 exporthtml_build_entry(
144 ctl
, FILENAME_NONE
, EXPORT_HTML_ID_NONE
, FALSE
);
145 exporthtml_build_entry(
146 ctl
, FILENAME_DEFAULT
, EXPORT_HTML_ID_DEFAULT
, TRUE
);
147 exporthtml_build_entry(
148 ctl
, FILENAME_FULL
, EXPORT_HTML_ID_FULL
, FALSE
);
149 exporthtml_build_entry(
150 ctl
, FILENAME_CUSTOM
, EXPORT_HTML_ID_CUSTOM
, FALSE
);
151 exporthtml_build_entry(
152 ctl
, FILENAME_CUSTOM2
, EXPORT_HTML_ID_CUSTOM2
, FALSE
);
153 exporthtml_build_entry(
154 ctl
, FILENAME_CUSTOM3
, EXPORT_HTML_ID_CUSTOM3
, FALSE
);
155 exporthtml_build_entry(
156 ctl
, FILENAME_CUSTOM4
, EXPORT_HTML_ID_CUSTOM4
, FALSE
);
162 * Free up object by releasing internal memory.
163 * Enter: ctl Export control data.
165 void exporthtml_free( ExportHtmlCtl
*ctl
) {
167 StylesheetEntry
*entry
;
169 cm_return_if_fail( ctl
!= NULL
);
171 /* Free stylesheet list */
172 node
= ctl
->listStyle
;
174 entry
= ( StylesheetEntry
* ) node
->data
;
175 g_free( entry
->fileName
);
176 entry
->fileName
= NULL
;
178 entry
->dflValue
= FALSE
;
181 node
= g_list_next( node
);
183 g_list_free( ctl
->listStyle
);
184 ctl
->listStyle
= NULL
;
187 g_free( ctl
->fileHtml
);
188 g_free( ctl
->encoding
);
189 g_free( ctl
->dirOutput
);
190 g_free( ctl
->settingsFile
);
194 ctl
->dirOutput
= NULL
;
195 ctl
->fileHtml
= NULL
;
196 ctl
->encoding
= NULL
;
197 ctl
->stylesheet
= EXPORT_HTML_ID_NONE
;
198 ctl
->nameFormat
= EXPORT_HTML_FIRST_LAST
;
199 ctl
->banding
= FALSE
;
200 ctl
->linkEMail
= FALSE
;
201 ctl
->showAttribs
= FALSE
;
202 ctl
->retVal
= MGU_SUCCESS
;
205 /* Now release object */
211 * Enter: ctl Export control data.
212 * Return: Stylesheet object, or NULL if nothing found. If a default entry is
213 * found in list, it will be returned.
215 static StylesheetEntry
*exporthtml_find_stylesheet( ExportHtmlCtl
*ctl
) {
216 StylesheetEntry
*retVal
= NULL
;
217 StylesheetEntry
*entry
;
220 node
= ctl
->listStyle
;
222 entry
= ( StylesheetEntry
* ) node
->data
;
223 if( entry
->id
== ctl
->stylesheet
) return entry
;
224 if( entry
->dflValue
) retVal
= entry
;
225 node
= g_list_next( node
);
230 void exporthtml_set_stylesheet( ExportHtmlCtl
*ctl
, const gint value
) {
231 cm_return_if_fail( ctl
!= NULL
);
232 ctl
->stylesheet
= value
;
234 void exporthtml_set_name_format( ExportHtmlCtl
*ctl
, const gint value
) {
235 cm_return_if_fail( ctl
!= NULL
);
236 ctl
->nameFormat
= value
;
238 void exporthtml_set_banding( ExportHtmlCtl
*ctl
, const gboolean value
) {
239 cm_return_if_fail( ctl
!= NULL
);
240 ctl
->banding
= value
;
242 void exporthtml_set_link_email( ExportHtmlCtl
*ctl
, const gboolean value
) {
243 cm_return_if_fail( ctl
!= NULL
);
244 ctl
->linkEMail
= value
;
246 void exporthtml_set_attributes( ExportHtmlCtl
*ctl
, const gboolean value
) {
247 cm_return_if_fail( ctl
!= NULL
);
248 ctl
->showAttribs
= value
;
252 * Create default CSS file.
253 * Enter: fileSpec File to create.
254 * Return: Status code.
256 static gint
exporthtml_create_css_dfl( const gchar
*fileSpec
) {
259 cssFile
= claws_fopen( fileSpec
, "rb" );
261 claws_fclose( cssFile
);
264 cssFile
= claws_fopen( fileSpec
, "wb" );
266 return MGU_OPEN_FILE
;
269 fprintf( cssFile
, "body {\n\tbackground: #ffffe0;\n" );
270 fprintf( cssFile
, "\tfont-family: lucida, helvetica, sans-serif;\n" );
271 fprintf( cssFile
, "\tfont-size: 10pt;\n" );
272 fprintf( cssFile
, "}\n" );
273 fprintf( cssFile
, "h1 {\n" );
274 fprintf( cssFile
, "\tcolor: #000000;\n" );
275 fprintf( cssFile
, "\ttext-align: center;\n" );
276 fprintf( cssFile
, "}\n" );
277 fprintf( cssFile
, "th {\n" );
278 fprintf( cssFile
, "\tfont-size: 10pt;\n" );
279 fprintf( cssFile
, "}\n" );
280 fprintf( cssFile
, "td {\n" );
281 fprintf( cssFile
, "\tfont-size: 10pt;\n" );
282 fprintf( cssFile
, "}\n" );
283 fprintf( cssFile
, ".fmt-folder {\n" );
284 fprintf( cssFile
, "\tcolor: #0000ff;\n" );
285 fprintf( cssFile
, "\tfont-size: 18pt;\n" );
286 fprintf( cssFile
, "\tfont-weight: bold;\n" );
287 fprintf( cssFile
, "}\n" );
288 fprintf( cssFile
, ".tab-head {\n" );
289 fprintf( cssFile
, "\tbackground: #80c0f0;\n" );
290 fprintf( cssFile
, "}\n" );
291 fprintf( cssFile
, ".tab-dn {\n" );
292 fprintf( cssFile
, "}\n" );
293 fprintf( cssFile
, ".tab-addr {\n" );
294 fprintf( cssFile
, "\tfont-style: italic;\n" );
295 fprintf( cssFile
, "}\n" );
296 fprintf( cssFile
, ".tab-email {\n" );
297 fprintf( cssFile
, "\tfont-weight: bold;\n" );
298 fprintf( cssFile
, "\tfont-style: italic;\n" );
299 fprintf( cssFile
, "}\n" );
300 fprintf( cssFile
, ".tab-fn {\n" );
301 fprintf( cssFile
, "}\n" );
302 fprintf( cssFile
, ".tab-attr {\n" );
303 fprintf( cssFile
, "}\n" );
305 claws_safe_fclose( cssFile
);
310 * Create full CSS file.
311 * Enter: fileSpec File to create.
312 * Return: Status code.
314 static gint
exporthtml_create_css_full( const gchar
*fileSpec
) {
317 cssFile
= claws_fopen( fileSpec
, "rb" );
319 claws_fclose( cssFile
);
322 cssFile
= claws_fopen( fileSpec
, "wb" );
324 return MGU_OPEN_FILE
;
327 fprintf( cssFile
, "body {\n\tbackground: #ffffe0;\n" );
328 fprintf( cssFile
, "\tfont-family: lucida, helvetica, sans-serif;\n" );
329 fprintf( cssFile
, "\tfont-size: 10pt;\n" );
330 fprintf( cssFile
, "}\n" );
331 fprintf( cssFile
, "h1 {\n" );
332 fprintf( cssFile
, "\tcolor: #000000;\n" );
333 fprintf( cssFile
, "\ttext-align: center;\n" );
334 fprintf( cssFile
, "}\n" );
335 fprintf( cssFile
, "th {\n" );
336 fprintf( cssFile
, "\tfont-size: 10pt;\n" );
337 fprintf( cssFile
, "}\n" );
338 fprintf( cssFile
, "td {\n" );
339 fprintf( cssFile
, "\tfont-size: 10pt;\n" );
340 fprintf( cssFile
, "}\n" );
341 fprintf( cssFile
, ".fmt-folder {\n" );
342 fprintf( cssFile
, "\tcolor: #0000ff;\n" );
343 fprintf( cssFile
, "\tfont-size: 18pt;\n" );
344 fprintf( cssFile
, "\tfont-weight: bold;\n" );
345 fprintf( cssFile
, "}\n" );
346 fprintf( cssFile
, ".tab-head {\n" );
347 fprintf( cssFile
, "\tbackground: #80c0f0;\n" );
348 fprintf( cssFile
, "}\n" );
349 fprintf( cssFile
, ".tab-row0 {\n" );
350 fprintf( cssFile
, "\tbackground: #f0f0f0;\n" );
351 fprintf( cssFile
, "}\n" );
352 fprintf( cssFile
, ".tab-row1 {\n" );
353 fprintf( cssFile
, "\tbackground: #d0d0d0;\n" );
354 fprintf( cssFile
, "}\n" );
355 fprintf( cssFile
, ".tab-dn {\n" );
356 fprintf( cssFile
, "}\n" );
357 fprintf( cssFile
, ".tab-addr {\n" );
358 fprintf( cssFile
, "\tfont-style: italic;\n" );
359 fprintf( cssFile
, "}\n" );
360 fprintf( cssFile
, ".tab-email {\n" );
361 fprintf( cssFile
, "\tfont-weight: bold;\n" );
362 fprintf( cssFile
, "\tfont-style: italic;\n" );
363 fprintf( cssFile
, "}\n" );
364 fprintf( cssFile
, ".tab-fn {\n" );
365 fprintf( cssFile
, "}\n" );
366 fprintf( cssFile
, ".tab-attr {\n" );
367 fprintf( cssFile
, "}\n" );
369 claws_safe_fclose( cssFile
);
374 * Create stylesheet files.
375 * Enter: ctl Export control data.
377 static void exporthtml_create_css_files( ExportHtmlCtl
*ctl
) {
381 node
= ctl
->listStyle
;
383 StylesheetEntry
*entry
= node
->data
;
384 node
= g_list_next( node
);
385 if( strlen( entry
->fileName
) ) {
386 fileSpec
= g_strconcat(
387 ctl
->dirOutput
, G_DIR_SEPARATOR_S
,
388 entry
->fileName
, NULL
);
389 if( entry
->id
== EXPORT_HTML_ID_DEFAULT
) {
390 exporthtml_create_css_dfl( fileSpec
);
392 else if( entry
->id
!= EXPORT_HTML_ID_NONE
) {
393 exporthtml_create_css_full( fileSpec
);
401 * Comparison using linked list elements.
403 static gint
exporthtml_compare_name(
404 gconstpointer ptr1
, gconstpointer ptr2
)
406 const AddrItemObject
*item1
= ptr1
;
407 const AddrItemObject
*item2
= ptr2
;
408 const gchar
*name1
= NULL
, *name2
= NULL
;
409 if( item1
) name1
= ADDRITEM_NAME( item1
);
410 if( item2
) name2
= ADDRITEM_NAME( item2
);
411 if( ! name1
) return ( name2
!= NULL
);
412 if( ! name2
) return -1;
413 return g_utf8_collate( name1
, name2
);
417 * Comparison using linked list elements.
419 static gint
exporthtml_compare_email(
420 gconstpointer ptr1
, gconstpointer ptr2
)
422 const ItemEMail
*email1
= ptr1
;
423 const ItemEMail
*email2
= ptr2
;
424 const gchar
*name1
= NULL
, *name2
= NULL
;
425 if( email1
) name1
= email1
->address
;
426 if( email2
) name2
= email2
->address
;
427 if( ! name1
) return ( name2
!= NULL
);
428 if( ! name2
) return -1;
429 return g_utf8_collate( name1
, name2
);
433 * Comparison using linked list elements.
435 static gint
exporthtml_compare_attrib(
436 gconstpointer ptr1
, gconstpointer ptr2
)
438 const UserAttribute
*attr1
= ptr1
;
439 const UserAttribute
*attr2
= ptr2
;
440 const gchar
*name1
= NULL
, *name2
= NULL
;
441 if( attr1
) name1
= attr1
->name
;
442 if( attr2
) name2
= attr2
->name
;
443 if( ! name1
) return ( name2
!= NULL
);
444 if( ! name2
) return -1;
445 return g_utf8_collate( name1
, name2
);
449 * Build sorted list of named items.
450 * Enter: list List of items to sorted.
451 * Return: Sorted list.
452 * Note: List should freed after use. Items referenced by list should not be
453 * freed since they are managed by the address cache.
455 static GList
*exporthtml_sort_name( const GList
*list
) {
457 GList
*sorted
= NULL
;
461 sorted
= g_list_insert_sorted(
462 sorted
, node
->data
, exporthtml_compare_name
);
463 node
= g_list_next( node
);
469 * Build sorted list of email items.
470 * Enter: list List of E-Mail items to sorted.
471 * Return: Sorted list.
472 * Note: List should freed after use. Items referenced by list should not be
473 * freed since they are managed by the address cache.
475 static GList
*exporthtml_sort_email( const GList
*list
) {
477 GList
*sorted
= NULL
;
481 sorted
= g_list_insert_sorted(
482 sorted
, node
->data
, exporthtml_compare_email
);
483 node
= g_list_next( node
);
489 * Build sorted list of attributes.
490 * Enter: list List of items to sorted.
491 * Return: Sorted list.
492 * Note: List should freed after use. Items referenced by list should not be
493 * freed since they are managed by the address cache.
495 static GList
*exporthtml_sort_attrib( const GList
*list
) {
497 GList
*sorted
= NULL
;
502 sorted
= g_list_insert_sorted(
503 sorted
, node
->data
, exporthtml_compare_attrib
);
504 node
= g_list_next( node
);
510 * Format a list of E-Mail addresses.
511 * Enter: ctl Export control data.
512 * stream Output stream.
513 * listEMail List of addresses.
514 * sortFlag Set to TRUE if address list should be sorted.
516 static void exporthtml_fmt_email(
517 ExportHtmlCtl
*ctl
, FILE *stream
, const GList
*listEMail
,
524 if( listEMail
== NULL
) {
525 fprintf( stream
, SC_HTML_SPACE
);
531 node
= list
= exporthtml_sort_email( listEMail
);
538 ItemEMail
*email
= ( ItemEMail
* ) node
->data
;
539 node
= g_list_next( node
);
541 name
= ADDRITEM_NAME( email
);
543 fprintf( stream
, "%s ", name
);
545 if( ctl
->linkEMail
) {
546 fprintf( stream
, "<a href=\"mailto:%s\">",
549 fprintf( stream
, "<span class=\"tab-email\">" );
550 fprintf( stream
, "%s", email
->address
);
551 fprintf( stream
, "</span>" );
552 if( ctl
->linkEMail
) {
553 fprintf( stream
, "</a>" );
555 if( email
->remarks
) {
556 if( strlen( email
->remarks
) ) {
557 fprintf( stream
, " (%s)", email
->remarks
);
560 fprintf( stream
, "<br>\n" );
566 * Format groups in an address book folder.
567 * Enter: ctl Export control data.
568 * stream Output stream.
570 * prevFlag If FALSE, list of persons were output.
571 * Return: TRUE if no groups were formatted.
573 static gboolean
exporthtml_fmt_group(
574 ExportHtmlCtl
*ctl
, FILE *stream
, const ItemFolder
*folder
,
577 gboolean retVal
, band
;
579 const gchar
*tagName
;
582 if( folder
->listGroup
== NULL
) return retVal
;
584 /* Write separator */
586 fprintf( stream
, "<br>\n" );
589 /* Write table headers */
590 fprintf( stream
, "<table" );
591 fprintf( stream
, " border=\"%d\"", BORDER_SIZE
);
592 fprintf( stream
, " cellpadding=\"%d\"", CELL_PADDING
);
593 fprintf( stream
, " cellspacing=\"%d\"", CELL_SPACING
);
594 fprintf( stream
, ">\n" );
596 fprintf( stream
, "<tr class=\"tab-head\">\n" );
597 fprintf( stream
, " <th width=\"200\">" );
598 fprintf( stream
, "%s", _( "Group Name" ) );
599 fprintf( stream
, "</th>\n" );
600 fprintf( stream
, " <th width=\"300\">" );
601 fprintf( stream
, "%s", _( "Email Address" ) );
602 fprintf( stream
, "</th>\n" );
603 fprintf( stream
, "</tr>\n" );
604 list
= exporthtml_sort_name( folder
->listGroup
);
609 AddrItemObject
*aio
= node
->data
;
610 if( aio
&& aio
->type
== ITEMTYPE_GROUP
) {
611 ItemGroup
*group
= ( ItemGroup
* ) aio
;
613 fprintf( stream
, "<tr valign=\"top\"" );
616 tagName
= _idTagRowOdd_
;
619 tagName
= _idTagRowEven_
;
621 fprintf( stream
, " class=\"%s\"", tagName
);
624 fprintf( stream
, "\">\n" );
626 fprintf( stream
, " <td class=\"tab-dn\">" );
627 fprintf( stream
, "%s", ADDRITEM_NAME( group
) );
628 fprintf( stream
, "</td>\n" );
629 fprintf( stream
, " <td class=\"tab-addr\">" );
630 exporthtml_fmt_email( ctl
, stream
, group
->listEMail
, TRUE
);
631 fprintf( stream
, "</td>\n" );
632 fprintf( stream
, "</tr>\n" );
635 node
= g_list_next( node
);
639 fprintf( stream
, "</table>\n" );
644 * Format a list of E-Mail addresses.
645 * Enter: ctl Export control data.
646 * stream Output stream.
647 * listAttr List of attributes.
649 static void exporthtml_fmt_attribs(
650 ExportHtmlCtl
*ctl
, FILE *stream
, const GList
*listAttr
)
655 if( listAttr
== NULL
) {
656 fprintf( stream
, SC_HTML_SPACE
);
660 fprintf( stream
, "<table border=\"0\">\n" );
661 node
= list
= exporthtml_sort_attrib( listAttr
);
663 UserAttribute
*attr
= ( UserAttribute
* ) node
->data
;
664 node
= g_list_next( node
);
665 fprintf( stream
, "<tr valign=\"top\">" );
666 fprintf( stream
, "<td align=\"right\">%s:</td>", attr
->name
);
667 fprintf( stream
, "<td>%s</td>", attr
->value
);
668 fprintf( stream
, "</tr>\n" );
672 fprintf( stream
, "</table>" );
677 * Enter: ctl Export control data.
679 * person Person to format.
681 static void exporthtml_fmt_fullname(
682 ExportHtmlCtl
*ctl
, gchar
*buf
, const ItemPerson
*person
)
686 if( ctl
->nameFormat
== EXPORT_HTML_LAST_FIRST
) {
688 if( person
->lastName
) {
689 if( *person
->lastName
) {
691 strcat( buf
, person
->lastName
);
695 if( person
->firstName
) {
696 if( *person
->firstName
) {
700 strcat( buf
, person
->firstName
);
705 if( person
->firstName
) {
706 if( *person
->firstName
) {
707 strcat( buf
, person
->firstName
);
710 if( person
->lastName
) {
711 if( *person
->lastName
) {
713 strcat( buf
, person
->lastName
);
720 if( *buf
) flag
= TRUE
;
721 if( person
->nickName
) {
722 if( strlen( person
->nickName
) ) {
726 strcat( buf
, person
->nickName
);
736 * Format persons in an address book folder.
737 * Enter: ctl Export control data.
738 * stream Output stream.
740 * Return: TRUE if no persons were formatted.
742 static gboolean
exporthtml_fmt_person(
743 ExportHtmlCtl
*ctl
, FILE *stream
, const ItemFolder
*folder
)
745 gboolean retVal
, band
;
747 gchar buf
[ FMT_BUFSIZE
];
748 const gchar
*tagName
;
751 if( folder
->listPerson
== NULL
) return retVal
;
753 /* Write table headers */
754 fprintf( stream
, "<table" );
755 fprintf( stream
, " border=\"%d\"", BORDER_SIZE
);
756 fprintf( stream
, " cellpadding=\"%d\"", CELL_PADDING
);
757 fprintf( stream
, " cellspacing=\"%d\"", CELL_SPACING
);
758 fprintf( stream
, ">\n" );
760 fprintf( stream
, "<tr class=\"tab-head\">\n" );
761 fprintf( stream
, " <th width=\"200\">" );
762 fprintf( stream
, "%s", _( "Display Name" ) );
763 fprintf( stream
, "</th>\n" );
764 fprintf( stream
, " <th width=\"300\">" );
765 fprintf( stream
, "%s", _( "Email Address" ) );
766 fprintf( stream
, "</th>\n" );
767 fprintf( stream
, " <th width=\"200\">" );
768 fprintf( stream
, "%s", _( "Full Name" ) );
769 fprintf( stream
, "</th>\n" );
770 if( ctl
->showAttribs
) {
771 fprintf( stream
, " <th width=\"250\">" );
772 fprintf( stream
, "%s", _( "Attributes" ) );
773 fprintf( stream
, "</th>\n" );
775 fprintf( stream
, "</tr>\n" );
778 node
= list
= exporthtml_sort_name( folder
->listPerson
);
780 AddrItemObject
*aio
= node
->data
;
781 if( aio
&& aio
->type
== ITEMTYPE_PERSON
) {
782 ItemPerson
*person
= ( ItemPerson
* ) aio
;
784 /* Format first/last/nick name */
786 exporthtml_fmt_fullname( ctl
, buf
,person
);
788 fprintf( stream
, "<tr valign=\"top\"" );
791 tagName
= _idTagRowOdd_
;
794 tagName
= _idTagRowEven_
;
796 fprintf( stream
, " class=\"%s\"", tagName
);
799 fprintf( stream
, ">\n" );
801 fprintf( stream
, " <td class=\"tab-dn\">" );
802 fprintf( stream
, "%s", ADDRITEM_NAME( person
) );
803 fprintf( stream
, "</td>\n" );
805 fprintf( stream
, " <td class=\"tab-addr\">" );
806 exporthtml_fmt_email( ctl
, stream
, person
->listEMail
, FALSE
);
807 fprintf( stream
, "</td>\n" );
809 fprintf( stream
, " <td class=\"tab-fn\">" );
811 fprintf( stream
, "%s", buf
);
814 fprintf( stream
, "%s", SC_HTML_SPACE
);
816 fprintf( stream
, "</td>\n" );
818 if( ctl
->showAttribs
) {
819 fprintf( stream
, " <td class=\"tab-attr\">" );
820 exporthtml_fmt_attribs(
821 ctl
, stream
, person
->listAttrib
);
822 fprintf( stream
, "</td>\n" );
824 fprintf( stream
, "</tr>\n" );
828 node
= g_list_next( node
);
832 fprintf( stream
, "</table>\n" );
837 * Format folder heirarchy.
838 * Enter: stream Output stream.
839 * list Heirarchy list.
841 static void exporthtml_fmt_folderhead( FILE *stream
, const GList
*list
) {
849 AddrItemObject
*aio
= node
->data
;
850 if( aio
&& aio
->type
== ITEMTYPE_FOLDER
) {
851 ItemFolder
*folder
= ( ItemFolder
* ) aio
;
853 name
= ADDRITEM_NAME( folder
);
856 fprintf( stream
, " > " );
858 fprintf( stream
, "%s", name
);
862 node
= g_list_next( node
);
867 * Format an address book folder.
868 * Enter: ctl Export control data.
869 * stream Output stream.
872 static void exporthtml_fmt_folder(
873 ExportHtmlCtl
*ctl
, FILE *stream
, const ItemFolder
*folder
)
876 GList
*listHeir
, *list
;
880 name
= ADDRITEM_NAME( folder
);
882 listHeir
= addritem_folder_path( folder
, TRUE
);
884 fprintf( stream
, "<p class=\"fmt-folder\">" );
885 fprintf( stream
, "%s: ", _( "Folder" ) );
886 exporthtml_fmt_folderhead( stream
, listHeir
);
887 fprintf( stream
, "</p>\n" );
888 g_list_free( listHeir
);
892 ret1
= exporthtml_fmt_person( ctl
, stream
, folder
);
893 exporthtml_fmt_group( ctl
, stream
, folder
, ret1
);
895 node
= list
= exporthtml_sort_name( folder
->listFolder
);
897 AddrItemObject
*aio
= node
->data
;
898 if( aio
&& aio
->type
== ITEMTYPE_FOLDER
) {
899 ItemFolder
*subFolder
= ( ItemFolder
* ) aio
;
900 exporthtml_fmt_folder( ctl
, stream
, subFolder
);
902 node
= g_list_next( node
);
910 * Format header block.
911 * Enter: ctl Export control data.
912 * stream Output stream.
915 static void exporthtml_fmt_header(
916 ExportHtmlCtl
*ctl
, FILE *stream
, gchar
*title
)
918 StylesheetEntry
*entry
;
920 entry
= exporthtml_find_stylesheet( ctl
);
923 "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" );
925 "\"http://www.w3.org/TR/html4/loose.dtd\">\n" );
926 fprintf( stream
, "<html>\n" );
927 fprintf( stream
, "<head>\n" );
929 if( ctl
->encoding
&& strlen( ctl
->encoding
) > 0 ) {
930 fprintf( stream
, "<meta " );
931 fprintf( stream
, "http-equiv=\"Content-Type\" " );
932 fprintf( stream
, "content=\"text/html; charset=%s\">\n",
936 fprintf( stream
, "<title>%s</title>\n", title
);
938 if( entry
!= NULL
) {
939 if( entry
->fileName
&& strlen( entry
->fileName
) > 0 ) {
940 fprintf( stream
, "<link " );
941 fprintf( stream
, "rel=\"stylesheet\" " );
942 fprintf( stream
, "type=\"text/css\" " );
943 fprintf( stream
, "href=\"%s\" >\n", entry
->fileName
);
946 fprintf( stream
, "</head>\n" );
950 * ============================================================================
951 * Export address book to HTML file.
952 * Enter: ctl Export control data.
953 * cache Address book/data source cache.
955 * ============================================================================
957 void exporthtml_process(
958 ExportHtmlCtl
*ctl
, AddressCache
*cache
)
960 ItemFolder
*rootFolder
;
967 htmlFile
= claws_fopen( ctl
->path
, "wb" );
969 /* Cannot open file */
970 g_print( "Cannot open file for write\n" );
971 ctl
->retVal
= MGU_OPEN_FILE
;
975 title
= _( "Claws Mail Address Book" );
976 rootFolder
= cache
->rootFolder
;
977 dsName
= cache
->name
;
979 exporthtml_fmt_header( ctl
, htmlFile
, title
);
981 fprintf( htmlFile
, "<body>\n" );
982 fprintf( htmlFile
, "<h1>%s</h1>\n", title
);
984 fprintf( htmlFile
, "<p class=\"fmt-folder\">" );
985 fprintf( htmlFile
, "%s: ", _( "Address Book" ) );
986 fprintf( htmlFile
, "%s", dsName
);
987 fprintf( htmlFile
, "</p>\n" );
989 exporthtml_fmt_folder( ctl
, htmlFile
, rootFolder
);
992 fprintf( htmlFile
, "<p>%s</p>\n", ctime_r( &tt
, buf
) );
993 fprintf( htmlFile
, "<hr width=\"100%%\">\n" );
995 fprintf( htmlFile
, "</body>\n" );
996 fprintf( htmlFile
, "</html>\n" );
998 claws_safe_fclose( htmlFile
);
999 ctl
->retVal
= MGU_SUCCESS
;
1001 /* Create stylesheet files */
1002 exporthtml_create_css_files( ctl
);
1007 * Build full export file specification.
1008 * Enter: ctl Export control data.
1010 static void exporthtml_build_filespec( ExportHtmlCtl
*ctl
) {
1013 fileSpec
= g_strconcat(
1014 ctl
->dirOutput
, G_DIR_SEPARATOR_S
, ctl
->fileHtml
, NULL
);
1015 ctl
->path
= mgu_replace_string( ctl
->path
, fileSpec
);
1020 * ============================================================================
1021 * Parse directory and filename from full export file specification.
1022 * Enter: ctl Export control data.
1023 * fileSpec File spec.
1024 * ============================================================================
1026 void exporthtml_parse_filespec( ExportHtmlCtl
*ctl
, gchar
*fileSpec
) {
1028 gchar
*base
= g_path_get_basename(fileSpec
);
1031 mgu_replace_string( ctl
->fileHtml
, base
);
1033 t
= g_path_get_dirname( fileSpec
);
1034 ctl
->dirOutput
= mgu_replace_string( ctl
->dirOutput
, t
);
1036 ctl
->path
= mgu_replace_string( ctl
->path
, fileSpec
);
1040 * ============================================================================
1041 * Create output directory.
1042 * Enter: ctl Export control data.
1043 * Return: TRUE if directory created.
1044 * ============================================================================
1046 gboolean
exporthtml_create_dir( ExportHtmlCtl
*ctl
) {
1047 gboolean retVal
= FALSE
;
1050 if( mkdir( ctl
->dirOutput
, S_IRWXU
) == 0 ) {
1054 ctl
->rcCreate
= errno
;
1060 * ============================================================================
1061 * Retrieve create directory error message.
1062 * Enter: ctl Export control data.
1064 * ============================================================================
1066 gchar
*exporthtml_get_create_msg( ExportHtmlCtl
*ctl
) {
1069 if( ctl
->rcCreate
== EEXIST
) {
1070 msg
= _( "Name already exists but is not a directory." );
1072 else if( ctl
->rcCreate
== EACCES
) {
1073 msg
= _( "No permissions to create directory." );
1075 else if( ctl
->rcCreate
== ENAMETOOLONG
) {
1076 msg
= _( "Name is too long." );
1079 msg
= _( "Not specified." );
1085 * Set default values.
1086 * Enter: ctl Export control data.
1088 static void exporthtml_default_values( ExportHtmlCtl
*ctl
) {
1092 get_home_dir(), G_DIR_SEPARATOR_S
,
1093 DFL_DIR_CLAWS_OUT
, NULL
);
1095 ctl
->dirOutput
= mgu_replace_string( ctl
->dirOutput
, str
);
1099 mgu_replace_string( ctl
->fileHtml
, DFL_FILE_CLAWS_OUT
);
1100 ctl
->encoding
= NULL
;
1101 ctl
->stylesheet
= EXPORT_HTML_ID_DEFAULT
;
1102 ctl
->nameFormat
= EXPORT_HTML_FIRST_LAST
;
1103 ctl
->banding
= TRUE
;
1104 ctl
->linkEMail
= TRUE
;
1105 ctl
->showAttribs
= TRUE
;
1106 ctl
->retVal
= MGU_SUCCESS
;
1110 * ============================================================================
1111 * Load settings from XML properties file.
1112 * Enter: ctl Export control data.
1113 * ============================================================================
1115 void exporthtml_load_settings( ExportHtmlCtl
*ctl
) {
1121 props
= xmlprops_create();
1122 xmlprops_set_path( props
, ctl
->settingsFile
);
1123 rc
= xmlprops_load_file( props
);
1126 xmlprops_get_property_s( props
, EXMLPROP_DIRECTORY
, buf
);
1127 ctl
->dirOutput
= mgu_replace_string( ctl
->dirOutput
, buf
);
1129 xmlprops_get_property_s( props
, EXMLPROP_FILE
, buf
);
1130 ctl
->fileHtml
= mgu_replace_string( ctl
->fileHtml
, buf
);
1133 xmlprops_get_property_i( props
, EXMLPROP_STYLESHEET
);
1135 xmlprops_get_property_i( props
, EXMLPROP_FMT_NAME
);
1137 xmlprops_get_property_b( props
, EXMLPROP_BANDING
);
1139 xmlprops_get_property_b( props
, EXMLPROP_FMT_EMAIL
);
1141 xmlprops_get_property_b( props
, EXMLPROP_FMT_ATTRIB
);
1144 /* Set default values */
1145 exporthtml_default_values( ctl
);
1147 exporthtml_build_filespec( ctl
);
1148 /* exporthtml_print( ctl, stdout ); */
1150 xmlprops_free( props
);
1154 * ============================================================================
1155 * Save settings to XML properties file.
1156 * Enter: ctl Export control data.
1157 * ============================================================================
1159 void exporthtml_save_settings( ExportHtmlCtl
*ctl
) {
1162 props
= xmlprops_create();
1163 xmlprops_set_path( props
, ctl
->settingsFile
);
1165 xmlprops_set_property( props
, EXMLPROP_DIRECTORY
, ctl
->dirOutput
);
1166 xmlprops_set_property( props
, EXMLPROP_FILE
, ctl
->fileHtml
);
1167 xmlprops_set_property_i( props
, EXMLPROP_STYLESHEET
, ctl
->stylesheet
);
1168 xmlprops_set_property_i( props
, EXMLPROP_FMT_NAME
, ctl
->nameFormat
);
1169 xmlprops_set_property_b( props
, EXMLPROP_BANDING
, ctl
->banding
);
1170 xmlprops_set_property_b( props
, EXMLPROP_FMT_EMAIL
, ctl
->linkEMail
);
1171 xmlprops_set_property_b( props
, EXMLPROP_FMT_ATTRIB
, ctl
->showAttribs
);
1172 if (xmlprops_save_file( props
) != MGU_SUCCESS
)
1173 g_warning("can't save settings");
1174 xmlprops_free( props
);
1178 * ============================================================================
1180 * ============================================================================