1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 /* modest-text-utils.h */
33 #ifndef __MODEST_TEXT_UTILS_H__
34 #define __MODEST_TEXT_UTILS_H__
41 #define _FM(str) dgettext("hildon-fm",str)
42 #define _CS(str) dgettext("hildon-common-strings",str)
43 #define _HL(str) dgettext("hildon-libs",str)
44 #define _MD(str) dgettext("maemo-af-desktop",str)
45 #define _AB(str) dgettext("osso-addressbook",str)
46 #define _KR(str) dgettext("ke-recv",str)
47 #define _UR(str) dgettext("osso-uri",str)
49 #ifdef MODEST_TOOLKIT_HILDON2
50 #define _HL_SAVE _HL("wdgt_bd_save")
51 #define _HL_YES _HL("wdgt_bd_yes")
52 #define _HL_NO _HL("wdgt_bd_no")
53 #define _HL_VIEW _HL("wdgt_bd_view")
54 #define _HL_TITLE_SORT _HL("ckdg_ti_sort")
55 #define _HL_TITLE_NEW_FOLDER _HL("ckdg_ti_new_folder")
56 #define _HL_TITLE_RENAME_FOLDER _HL("ckdg_ti_rename_folder")
57 #define _HL_DATE _HL("wdgt_va_date")
58 #define _HL_24H_TIME _HL("wdgt_va_24h_time")
59 #define _HL_WEEK _HL("wdgt_va_week")
60 #define _HL_DATE_MEDIUM _HL("wdgt_va_date_medium")
61 #define _HL_12H_TIME_PM _HL("wdgt_va_12h_time_pm")
62 #define _HL_12H_TIME_AM _HL("wdgt_va_12h_time_am")
63 #define _HL_DONE _HL("wdgt_bd_done")
64 #define _HL_DELETE _HL("wdgt_bd_delete")
65 #define _HL_MOVE _HL("wdgt_bd_move")
66 #define _HL_RENAME _HL("wdgt_bd_rename")
67 #define _HL_IB_FIND_COMPLETE _HL("ckct_ib_find_search_complete")
68 #define _HL_IB_FIND_NO_MATCHES _HL("ckct_ib_find_no_matches")
69 #define _HL_IB_ZOOM _HL("wdgt_ib_zoom")
71 #define _HL_SAVE _("Save")
72 #define _HL_YES _("Yes")
73 #define _HL_NO _("Yes")
74 #define _HL_VIEW _("View")
75 #define _HL_TITLE_SORT _("Sort")
76 #define _HL_TITLE_NEW_FOLDER _("New folder")
77 #define _HL_TITLE_RENAME_FOLDER _HL("Rename folder")
78 #define _HL_RENAME_NAME _("Name")
79 #define _HL_24H_TIME _("%H:%M")
80 #define _HL_DATE _("%m/%d/%Y")
81 #define _HL_WEEK _("%A")
82 #define _HL_DATE_MEDIUM _("%e %B %Y")
83 #define _HL_12H_TIME_PM _("%l:%M pm")
84 #define _HL_12H_TIME_AM _("%l:%M am")
85 #define _HL_DONE _("Done")
86 #define _HL_DELETE _("Delete")
87 #define _HL_MOVE _("Move")
88 #define _HL_RENAME _("Rename")
89 #define _HL_IB_FIND_COMPLETE _("Search complete")
90 #define _HL_IB_FIND_NO_MATCHES _("No matches")
91 #define _HL_IB_ZOOM _("Zoom %d")
94 /* Forbidden char arrays */
95 extern const gchar account_title_forbidden_chars[];
96 extern const gchar folder_name_forbidden_chars[];
97 extern const gchar user_name_forbidden_chars[];
98 extern const guint ACCOUNT_TITLE_FORBIDDEN_CHARS_LENGTH;
99 extern const guint FOLDER_NAME_FORBIDDEN_CHARS_LENGTH;
100 extern const guint USER_NAME_FORBIDDEN_CHARS_LENGTH;
102 /* It includes a white space as RFC 3676 Section 4.3 about usenet
103 message signatures defines */
104 #define MODEST_TEXT_UTILS_SIGNATURE_MARKER "-- "
107 * modest_text_utils_derived_subject:
108 * @subject: a string which contains the original subject
109 * @is_reply: whether the derived subject is for a reply or a forward message
111 * create a 'derived' subject line for eg. replies and forwards. Note
112 * that this function will use the localized versions of "Re" and
113 * "Fw", unless one of these two versions was already included. For
114 * example replying to an email in Finish would work as:
116 * "some subject" -> "VS: some subject"
117 * "VS: some subject" -> "VS: some subject"
118 * "Re: some subject" -> "Re: some subject"
119 * "Fw: some subject" -> "VS: Fw: some subject"
121 * Returns: a newly allocated string containing the resulting subject
123 gchar* modest_text_utils_derived_subject (const gchar *subject,
128 * modest_text_utils_quote:
129 * @text: a non-NULL string which contains the message to quote
130 * @from: a non-NULL sender of the original message
131 * @content_type: the non-NULL content type for the quoting, e.g. "text/html"
132 * @signature: NULL or the signature to add
133 * @sent_date: sent date/time of the original message
134 * @attachments: a #GList of the attachments
135 * @limit: specifies the maximum characters per line in the quoted text
137 * quote an existing message
139 * Returns: a newly allocated string containing the quoted message
141 gchar* modest_text_utils_quote (const gchar *text,
142 const gchar *content_type,
143 const gchar *signature,
145 const time_t sent_date,
151 * modest_text_utils_cited_text:
152 * @from: sender of the message
153 * @sent_date: the sent date of the original message
154 * @text: the text of the original message
156 * cite the text in a message
158 * Returns: a newly allocated string containing the cited text
160 gchar* modest_text_utils_cite (const gchar *text,
161 const gchar *content_type,
162 const gchar *signature,
167 * modest_text_utils_inlined_text
168 * @from: the non-NULL sender of the original message
169 * @sent_date: sent date/time of the original message
174 * creates a new string with the "Original message" text prepended to
175 * the text passed as argument and some data of the header
177 * Returns: a newly allocated string containing the quoted message
179 gchar* modest_text_utils_inline (const gchar *text,
180 const gchar *content_type,
181 const gchar *signature,
185 const gchar *subject);
188 * modest_text_utils_remove_address
189 * @address_list: non-NULL string with a comma-separated list of email addresses
190 * @address: an specific e-mail address
192 * remove a specific address from a list of email addresses; if @address
193 * is NULL, returns an unchanged (but newly allocated) @address_list
195 * Returns: a newly allocated string containing the new list, or NULL
196 * in case of error or the original @address_list was NULL
198 gchar* modest_text_utils_remove_address (const gchar *address_list,
199 const gchar *address);
203 * modest_text_utils_remove_duplicate_addresses
204 * @address_list: non-NULL string with a comma-separated list of email addresses
206 * remove duplicate addresses from a list of email addresses
208 * Returns: a newly allocated string containing the new list, or NULL
209 * in case of error or the original @address_list was NULL
211 gchar* modest_text_utils_remove_duplicate_addresses (const gchar *address_list);
215 * modest_text_utils_address_range_at_position:
216 * @address_list: non-NULL utf8 string containing a list of addresses
218 * @start: a gint pointer
219 * @end: a gint pointer
221 * Finds the start and end positions of the address at @position,
222 * in @recipients_list, a list of addresses in the format of a
223 * recipient list in email. It stores the results in @start and
226 void modest_text_utils_address_range_at_position (const gchar *recipients_list,
232 * modest_text_utils_hyperlinkify_begin:
234 * begin a linkify block, compiling the caches to be reused. Use it in mainloop.
236 void modest_text_utils_hyperlinkify_begin (void);
239 * modest_text_utils_hyperlinkify_end:
241 * end a linkify block, freeing the caches to be reused. Use it in mainloop.
243 void modest_text_utils_hyperlinkify_end (void);
246 * modest_text_utils_convert_to_html:
249 * convert plain text (utf8) into html
251 * Returns: a newly allocated string containing the html
253 gchar* modest_text_utils_convert_to_html (const gchar *txt);
256 * modest_text_utils_convert_to_html_body:
259 * convert plain text (utf8) into html without adding html headers.
261 * Returns: a newly allocated string containing the html
263 gchar* modest_text_utils_convert_to_html_body (const gchar *data, gssize n, gboolean hyperlinkify);
267 * modest_text_utils_strftime:
273 * this is just an alias for strftime(3), so we can use that without
274 * getting warning from gcc
276 * Returns: a formatted string of max length @max in @s
278 size_t modest_text_utils_strftime(char *s, size_t max, const char *fmt, time_t timet);
281 * modest_text_utils_hyperlinkify:
282 * @string_buffer: buffer where we replace uri strings with links
284 * Replace uri's with links in the buffer. This is required that the document
285 * do not contain linkified links already.
287 void modest_text_utils_hyperlinkify (GString *string_buffer);
290 * modest_text_utils_get_display_address:
291 * @address: original address (UTF8 string)
293 * make a 'display address' from an address:
294 * "Foo Bar <foo@bar.cx>" --> "Foo Bar"
295 * ie. removes "<...>" parts
296 * the change is in-place; removes leading whitespace
298 * NOTE: for optimization reasons, this function changes @address
301 void modest_text_utils_get_display_address (gchar *address);
304 * modest_text_utils_get_display_addresses:
305 * @addresses: a list of comma-separated addresses
307 * Transforms a list of email addresses in a list of recipients,
308 * replacing each plain email address by the correspondent display
311 * Returns: a newly allocated string, that must be freed by the caller
313 gchar *modest_text_utils_get_display_addresses (const gchar *addresses);
317 * modest_text_utils_get_email_address:
318 * @full_address: original address (UTF8 string)
320 * make a 'foo@bar.cx' from an address:
321 * "Foo Bar <foo@bar.cx> (Bla)" --> "foo@bar.cx"
322 * If no "<...>" is found, then it returns the full
325 * Returns: a newly allocated string with the copy.
327 * NULL in case of error or if address == NULL
329 gchar* modest_text_utils_get_email_address (const gchar *email_address);
333 * modest_text_utils_get_subject_prefix_len:
334 * @subject: original subject (UTF8 string)
336 * determine the length of the "Re:/RE:/Fwd:" prefix in an e-mail address
338 * Returns: the length of the prefix, or 0 if there is none
340 gint modest_text_utils_get_subject_prefix_len (const gchar *subject);
344 * modest_text_utils_utf8_strcmp:
345 * @s1: the first string
346 * @s2: the second string
347 * @insensitive: should the comparison be case-insensitive?
349 * a strcmp that is NULL-safe, can deal with UTF8 and case-insensitive comparison
351 * Returns: an integer less than, equal to, or greater than zero if s1 is found,
352 * respectively, to be less than, to match, or be greater than s2.
354 gint modest_text_utils_utf8_strcmp (const gchar* s1, const gchar *s2, gboolean insensitive);
359 * modest_text_utils_get_display_date:
360 * @date: the date to display
362 * get a string representation for a date.
364 * Returns: the new display date, as a *static* string.
365 * This string should not be modified, and will change
366 * upon recalling this function. g_strdup it if you to
370 const gchar* modest_text_utils_get_display_date (time_t date);
374 * modest_text_utils_get_display_size:
375 * @size: size in bytes
377 * get a string representation for a size in bytes.
379 * Returns: the newly allocated display string for the
380 * size in bytes. must be freed.
382 gchar * modest_text_utils_get_display_size (guint64 size);
387 * modest_text_utils_validate_domain_name:
388 * @email_address: a NULL-terminated string
390 * validates the domain name passed as argument
392 * Returns: TRUE if the domain name is valid, FALSE otherwise
394 gboolean modest_text_utils_validate_domain_name (const gchar *domain);
397 * modest_text_utils_validate_email_address:
398 * @email_address: a string
399 * @invalid_char_position: pointer to the position of the invalid
400 * character in case validation failed because of this, or %NULL.
402 * validates the email address passed as argument
404 * Returns: TRUE if the address is valid, FALSE otherwise
406 gboolean modest_text_utils_validate_email_address (const gchar *email_address,
407 const gchar **invalid_char_position);
411 * modest_text_utils_validate_folder_name:
412 * @folder_name: a string
414 * validates the folder name passed as argument. a 'valid folder name'
415 * is a name which should be valid on both Unix and Windows file systems.
416 * of course, this might be stricter than strictly needed in some cases,
417 * but it's better to err on the safe side.
419 * Returns: TRUE if the folder name is valid, FALSE otherwise
421 gboolean modest_text_utils_validate_folder_name (const gchar *folder_name);
424 * modest_text_utils_validate_recipient:
425 * @recipient: a string
426 * @invalid_char_position: pointer to the position of the invalid char,
427 * if validation failed because there's an invalid char there, or %NULL.
429 * validates @recipient as a valid recipient field for header.
430 * It's different from modest_text_utils_validate_email_address()
431 * as it validates a whole recipient, and not only the part between
432 * the < and > symbols.
434 * Returns: %TRUE if the recipient is valid, FALSE otherwise
436 gboolean modest_text_utils_validate_recipient (const gchar *recipient,
437 const gchar **invalid_char_position);
440 * modest_text_utils_split_addresses_list:
441 * @addresses: a string
443 * obtains a GSList of addresses from a string of addresses
444 * in the format understood by email protocols
446 * Returns: a newly allocated GSList of strings
448 GSList *modest_text_utils_split_addresses_list (const gchar *addresses);
451 * modest_text_utils_join_addresses:
452 * @from: comma separated string of addresses
453 * @to: comma separated string of addresses
454 * @cc: comma separated string of addresses
455 * @bcc: comma separated string of addresses
457 * joins all the addresses in a single comma-separated string
459 * Returns: a newly allocated string with a list of addresses
461 gchar *modest_text_utils_join_addresses (const gchar *from,
467 * modest_text_utils_get_addresses_indexes:
468 * @addresses: a string
469 * @start_indexes: a #GSList pointer
470 * @end_indexes: a #GSList pointer
472 * obtains two #GSList of @addresses with the range offsets of the addresses in
475 * Returns: a GSList of strings
477 void modest_text_utils_get_addresses_indexes (const gchar *addresses, GSList **start_indexes, GSList **end_indexes);
480 * modest_text_utils_address_with_standard_length:
481 * @recipients_list: a string
483 * obtains the list of recipients, but making sure that lines are not longer than 1000 chars
485 * Returns: a newly allocated string
487 gchar * modest_text_utils_address_with_standard_length (const gchar *recipients_list);
490 * modest_text_utils_get_color_string:
491 * @color: a #GdkColor
493 * Obtains a proper markup string for @color, in the format used
496 * Returns: a newly allocated string
498 gchar * modest_text_utils_get_color_string (GdkColor *color);
501 * modest_text_utils_text_buffer_get_text:
502 * @buffer: a #GtkTextBuffer
504 * Obtains the contents of a @buffer in a string, replacing image
505 * pixbufs with blank spaces.
507 * Returns: a newly allocated UTF-8 string
509 gchar * modest_text_utils_text_buffer_get_text (GtkTextBuffer *buffer);
512 ACCOUNT_TITLE_FORBIDDEN_CHARS,
513 FOLDER_NAME_FORBIDDEN_CHARS,
514 USER_NAME_FORBIDDEN_NAMES,
515 } ModestTextUtilsForbiddenCharType;
518 * modest_text_utils_label_get_selection:
519 * @label: a #GtkLabel
521 * Obtain the current selection of @label
523 * Returns: a string with current selection, or %NULL if no selection in @label
525 gchar * modest_text_utils_label_get_selection (GtkLabel *label);
528 * modest_text_utils_is_forbidden_char:
529 * @character: some character
530 * @type: the type of forbidden char (see #ModestTextUtilsForbiddenCharType)
532 * check whether the given character is 'forbidden'
534 * Returns: TRUE if it's forbidden, FALSE otherwise
536 gboolean modest_text_utils_is_forbidden_char (const gchar character,
537 ModestTextUtilsForbiddenCharType type);
540 * modest_text_utils_buffer_selection_is_valid:
541 * @buffer: a #GtkTextBuffer
543 * Checks if @buffer contains a valid selection for cut/copy. This means it's
544 * not empty, and no images are in the selection.
546 * Returns: %TRUE if there's a valid selection, false otherwise.
548 gboolean modest_text_utils_buffer_selection_is_valid (GtkTextBuffer *buffer);
551 * modest_text_utils_escape_mnemonics:
554 * obtains the representation of text, but escaping mnemonics (we duplicate _)
556 * Returns: a newly allocated string
558 gchar *modest_text_utils_escape_mnemonics (const gchar *text);
561 * modest_text_utils_simplify_recipients:
562 * @recipients: a list of recipients
564 * returns a list of simplified recipients:
565 * * a@b <a@b> converted to a@b
566 * * NULL converted to ""
568 * It's mainly intended for printing in screen addresses, but it can
569 * also be used for reply/forward.
571 gchar *modest_text_utils_simplify_recipients (const gchar *recipient);
574 * modest_text_utils_remove_duplicate_addresses_list
575 * @address_list: non-NULL #GSList of email addresses
577 * remove duplicate addresses from a list of email addresses
579 * Returns: a list without the duplicate addresses or NULL in case of
580 * error or the original @address_list was NULL
582 GSList *modest_text_utils_remove_duplicate_addresses_list (GSList *address_list);
585 * modest_text_utils_get_secure_header:
586 * @value: the value of a mail header
587 * @header: the header that we're evaluating
589 * This function returns the secure value for a header. Basically it
590 * avoids DoS attacks caused by specially malformed headers like for
591 * example. From:From:From...From: some@mail.com
593 * Returns: returns the secured header
595 gchar * modest_text_utils_get_secure_header (const gchar *value, const gchar *header);
598 * modest_text_utils_quote_names:
599 * @recipients: a list of valid email addresses separated by ',' or ';'
601 * This function quotes the name part of an email address if it's not
602 * quoted and if it exists. For example
603 * aaa@bbb.com -> aaa@bbb.com
604 * "my name" <aaa@bbb.com> -> "my name" <aaa@bbb.com>
605 * my name aaa@bbb.com -> "my name" aaa@bbb.com
607 * It even supports things like
608 * my, name <aaa@bbb.com>, aaa@ccc.com -> "my, name" <aaa@bbb.com>; aaa@ccc.com
610 * Returns: a newly allocated string with the quoted email addresses
612 gchar * modest_text_utils_quote_names (const gchar *recipients);
614 #endif /* __MODEST_TEXT_UTILS_H__ */