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 /* Forbidden char arrays */
50 extern const gchar account_title_forbidden_chars[];
51 extern const gchar folder_name_forbidden_chars[];
52 extern const gchar user_name_forbidden_chars[];
53 extern const guint ACCOUNT_TITLE_FORBIDDEN_CHARS_LENGTH;
54 extern const guint FOLDER_NAME_FORBIDDEN_CHARS_LENGTH;
55 extern const guint USER_NAME_FORBIDDEN_CHARS_LENGTH;
57 /* It includes a white space as RFC 3676 Section 4.3 about usenet
58 message signatures defines */
59 #define MODEST_TEXT_UTILS_SIGNATURE_MARKER "-- "
62 * modest_text_utils_derived_subject:
63 * @subject: a string which contains the original subject
64 * @is_reply: whether the derived subject is for a reply or a forward message
66 * create a 'derived' subject line for eg. replies and forwards. Note
67 * that this function will use the localized versions of "Re" and
68 * "Fw", unless one of these two versions was already included. For
69 * example replying to an email in Finish would work as:
71 * "some subject" -> "VS: some subject"
72 * "VS: some subject" -> "VS: some subject"
73 * "Re: some subject" -> "Re: some subject"
74 * "Fw: some subject" -> "VS: Fw: some subject"
76 * Returns: a newly allocated string containing the resulting subject
78 gchar* modest_text_utils_derived_subject (const gchar *subject,
83 * modest_text_utils_quote:
84 * @text: a non-NULL string which contains the message to quote
85 * @from: a non-NULL sender of the original message
86 * @content_type: the non-NULL content type for the quoting, e.g. "text/html"
87 * @signature: NULL or the signature to add
88 * @sent_date: sent date/time of the original message
89 * @attachments: a #GList of the attachments
90 * @limit: specifies the maximum characters per line in the quoted text
92 * quote an existing message
94 * Returns: a newly allocated string containing the quoted message
96 gchar* modest_text_utils_quote (const gchar *text,
97 const gchar *content_type,
98 const gchar *signature,
100 const time_t sent_date,
106 * modest_text_utils_cited_text:
107 * @from: sender of the message
108 * @sent_date: the sent date of the original message
109 * @text: the text of the original message
111 * cite the text in a message
113 * Returns: a newly allocated string containing the cited text
115 gchar* modest_text_utils_cite (const gchar *text,
116 const gchar *content_type,
117 const gchar *signature,
122 * modest_text_utils_inlined_text
123 * @from: the non-NULL sender of the original message
124 * @sent_date: sent date/time of the original message
129 * creates a new string with the "Original message" text prepended to
130 * the text passed as argument and some data of the header
132 * Returns: a newly allocated string containing the quoted message
134 gchar* modest_text_utils_inline (const gchar *text,
135 const gchar *content_type,
136 const gchar *signature,
140 const gchar *subject);
143 * modest_text_utils_remove_address
144 * @address_list: non-NULL string with a comma-separated list of email addresses
145 * @address: an specific e-mail address
147 * remove a specific address from a list of email addresses; if @address
148 * is NULL, returns an unchanged (but newly allocated) @address_list
150 * Returns: a newly allocated string containing the new list, or NULL
151 * in case of error or the original @address_list was NULL
153 gchar* modest_text_utils_remove_address (const gchar *address_list,
154 const gchar *address);
158 * modest_text_utils_remove_duplicate_addresses
159 * @address_list: non-NULL string with a comma-separated list of email addresses
161 * remove duplicate addresses from a list of email addresses
163 * Returns: a newly allocated string containing the new list, or NULL
164 * in case of error or the original @address_list was NULL
166 gchar* modest_text_utils_remove_duplicate_addresses (const gchar *address_list);
170 * modest_text_utils_address_range_at_position:
171 * @address_list: non-NULL utf8 string containing a list of addresses
173 * @start: a gint pointer
174 * @end: a gint pointer
176 * Finds the start and end positions of the address at @position,
177 * in @recipients_list, a list of addresses in the format of a
178 * recipient list in email. It stores the results in @start and
181 void modest_text_utils_address_range_at_position (const gchar *recipients_list,
187 * modest_text_utils_hyperlinkify_begin:
189 * begin a linkify block, compiling the caches to be reused. Use it in mainloop.
191 void modest_text_utils_hyperlinkify_begin (void);
194 * modest_text_utils_hyperlinkify_end:
196 * end a linkify block, freeing the caches to be reused. Use it in mainloop.
198 void modest_text_utils_hyperlinkify_end (void);
201 * modest_text_utils_convert_to_html:
204 * convert plain text (utf8) into html
206 * Returns: a newly allocated string containing the html
208 gchar* modest_text_utils_convert_to_html (const gchar *txt);
211 * modest_text_utils_convert_to_html_body:
214 * convert plain text (utf8) into html without adding html headers.
216 * Returns: a newly allocated string containing the html
218 gchar* modest_text_utils_convert_to_html_body (const gchar *data, gssize n, gboolean hyperlinkify);
222 * modest_text_utils_strftime:
228 * this is just an alias for strftime(3), so we can use that without
229 * getting warning from gcc
231 * Returns: a formatted string of max length @max in @s
233 size_t modest_text_utils_strftime(char *s, size_t max, const char *fmt, time_t timet);
236 * modest_text_utils_hyperlinkify:
237 * @string_buffer: buffer where we replace uri strings with links
239 * Replace uri's with links in the buffer. This is required that the document
240 * do not contain linkified links already.
242 void modest_text_utils_hyperlinkify (GString *string_buffer);
245 * modest_text_utils_get_display_address:
246 * @address: original address (UTF8 string)
248 * make a 'display address' from an address:
249 * "Foo Bar <foo@bar.cx>" --> "Foo Bar"
250 * ie. removes "<...>" parts
251 * the change is in-place; removes leading whitespace
253 * NOTE: for optimization reasons, this function changes @address
256 void modest_text_utils_get_display_address (gchar *address);
259 * modest_text_utils_get_display_addresses:
260 * @addresses: a list of comma-separated addresses
262 * Transforms a list of email addresses in a list of recipients,
263 * replacing each plain email address by the correspondent display
266 * Returns: a newly allocated string, that must be freed by the caller
268 gchar *modest_text_utils_get_display_addresses (const gchar *addresses);
272 * modest_text_utils_get_email_address:
273 * @full_address: original address (UTF8 string)
275 * make a 'foo@bar.cx' from an address:
276 * "Foo Bar <foo@bar.cx> (Bla)" --> "foo@bar.cx"
277 * If no "<...>" is found, then it returns the full
280 * Returns: a newly allocated string with the copy.
282 * NULL in case of error or if address == NULL
284 gchar* modest_text_utils_get_email_address (const gchar *email_address);
288 * modest_text_utils_get_subject_prefix_len:
289 * @subject: original subject (UTF8 string)
291 * determine the length of the "Re:/RE:/Fwd:" prefix in an e-mail address
293 * Returns: the length of the prefix, or 0 if there is none
295 gint modest_text_utils_get_subject_prefix_len (const gchar *subject);
299 * modest_text_utils_utf8_strcmp:
300 * @s1: the first string
301 * @s2: the second string
302 * @insensitive: should the comparison be case-insensitive?
304 * a strcmp that is NULL-safe, can deal with UTF8 and case-insensitive comparison
306 * Returns: an integer less than, equal to, or greater than zero if s1 is found,
307 * respectively, to be less than, to match, or be greater than s2.
309 gint modest_text_utils_utf8_strcmp (const gchar* s1, const gchar *s2, gboolean insensitive);
314 * modest_text_utils_get_display_date:
315 * @date: the date to display
317 * get a string representation for a date.
319 * Returns: the new display date, as a *static* string.
320 * This string should not be modified, and will change
321 * upon recalling this function. g_strdup it if you to
325 const gchar* modest_text_utils_get_display_date (time_t date);
329 * modest_text_utils_get_display_size:
330 * @size: size in bytes
332 * get a string representation for a size in bytes.
334 * Returns: the newly allocated display string for the
335 * size in bytes. must be freed.
337 gchar * modest_text_utils_get_display_size (guint64 size);
342 * modest_text_utils_validate_domain_name:
343 * @email_address: a NULL-terminated string
345 * validates the domain name passed as argument
347 * Returns: TRUE if the domain name is valid, FALSE otherwise
349 gboolean modest_text_utils_validate_domain_name (const gchar *domain);
352 * modest_text_utils_validate_email_address:
353 * @email_address: a string
354 * @invalid_char_position: pointer to the position of the invalid
355 * character in case validation failed because of this, or %NULL.
357 * validates the email address passed as argument
359 * Returns: TRUE if the address is valid, FALSE otherwise
361 gboolean modest_text_utils_validate_email_address (const gchar *email_address,
362 const gchar **invalid_char_position);
366 * modest_text_utils_validate_folder_name:
367 * @folder_name: a string
369 * validates the folder name passed as argument. a 'valid folder name'
370 * is a name which should be valid on both Unix and Windows file systems.
371 * of course, this might be stricter than strictly needed in some cases,
372 * but it's better to err on the safe side.
374 * Returns: TRUE if the folder name is valid, FALSE otherwise
376 gboolean modest_text_utils_validate_folder_name (const gchar *folder_name);
379 * modest_text_utils_validate_recipient:
380 * @recipient: a string
381 * @invalid_char_position: pointer to the position of the invalid char,
382 * if validation failed because there's an invalid char there, or %NULL.
384 * validates @recipient as a valid recipient field for header.
385 * It's different from modest_text_utils_validate_email_address()
386 * as it validates a whole recipient, and not only the part between
387 * the < and > symbols.
389 * Returns: %TRUE if the recipient is valid, FALSE otherwise
391 gboolean modest_text_utils_validate_recipient (const gchar *recipient,
392 const gchar **invalid_char_position);
395 * modest_text_utils_split_addresses_list:
396 * @addresses: a string
398 * obtains a GSList of addresses from a string of addresses
399 * in the format understood by email protocols
401 * Returns: a newly allocated GSList of strings
403 GSList *modest_text_utils_split_addresses_list (const gchar *addresses);
406 * modest_text_utils_join_addresses:
407 * @from: comma separated string of addresses
408 * @to: comma separated string of addresses
409 * @cc: comma separated string of addresses
410 * @bcc: comma separated string of addresses
412 * joins all the addresses in a single comma-separated string
414 * Returns: a newly allocated string with a list of addresses
416 gchar *modest_text_utils_join_addresses (const gchar *from,
422 * modest_text_utils_get_addresses_indexes:
423 * @addresses: a string
424 * @start_indexes: a #GSList pointer
425 * @end_indexes: a #GSList pointer
427 * obtains two #GSList of @addresses with the range offsets of the addresses in
430 * Returns: a GSList of strings
432 void modest_text_utils_get_addresses_indexes (const gchar *addresses, GSList **start_indexes, GSList **end_indexes);
435 * modest_text_utils_address_with_standard_length:
436 * @recipients_list: a string
438 * obtains the list of recipients, but making sure that lines are not longer than 1000 chars
440 * Returns: a newly allocated string
442 gchar * modest_text_utils_address_with_standard_length (const gchar *recipients_list);
445 * modest_text_utils_get_color_string:
446 * @color: a #GdkColor
448 * Obtains a proper markup string for @color, in the format used
451 * Returns: a newly allocated string
453 gchar * modest_text_utils_get_color_string (GdkColor *color);
456 * modest_text_utils_text_buffer_get_text:
457 * @buffer: a #GtkTextBuffer
459 * Obtains the contents of a @buffer in a string, replacing image
460 * pixbufs with blank spaces.
462 * Returns: a newly allocated UTF-8 string
464 gchar * modest_text_utils_text_buffer_get_text (GtkTextBuffer *buffer);
467 ACCOUNT_TITLE_FORBIDDEN_CHARS,
468 FOLDER_NAME_FORBIDDEN_CHARS,
469 USER_NAME_FORBIDDEN_NAMES,
470 } ModestTextUtilsForbiddenCharType;
473 * modest_text_utils_label_get_selection:
474 * @label: a #GtkLabel
476 * Obtain the current selection of @label
478 * Returns: a string with current selection, or %NULL if no selection in @label
480 gchar * modest_text_utils_label_get_selection (GtkLabel *label);
483 * modest_text_utils_is_forbidden_char:
484 * @character: some character
485 * @type: the type of forbidden char (see #ModestTextUtilsForbiddenCharType)
487 * check whether the given character is 'forbidden'
489 * Returns: TRUE if it's forbidden, FALSE otherwise
491 gboolean modest_text_utils_is_forbidden_char (const gchar character,
492 ModestTextUtilsForbiddenCharType type);
495 * modest_text_utils_buffer_selection_is_valid:
496 * @buffer: a #GtkTextBuffer
498 * Checks if @buffer contains a valid selection for cut/copy. This means it's
499 * not empty, and no images are in the selection.
501 * Returns: %TRUE if there's a valid selection, false otherwise.
503 gboolean modest_text_utils_buffer_selection_is_valid (GtkTextBuffer *buffer);
506 * modest_text_utils_escape_mnemonics:
509 * obtains the representation of text, but escaping mnemonics (we duplicate _)
511 * Returns: a newly allocated string
513 gchar *modest_text_utils_escape_mnemonics (const gchar *text);
516 * modest_text_utils_simplify_recipients:
517 * @recipients: a list of recipients
519 * returns a list of simplified recipients:
520 * * a@b <a@b> converted to a@b
521 * * NULL converted to ""
523 * It's mainly intended for printing in screen addresses, but it can
524 * also be used for reply/forward.
526 gchar *modest_text_utils_simplify_recipients (const gchar *recipient);
529 * modest_text_utils_remove_duplicate_addresses_list
530 * @address_list: non-NULL #GSList of email addresses
532 * remove duplicate addresses from a list of email addresses
534 * Returns: a list without the duplicate addresses or NULL in case of
535 * error or the original @address_list was NULL
537 GSList *modest_text_utils_remove_duplicate_addresses_list (GSList *address_list);
540 * modest_text_utils_get_secure_header:
541 * @value: the value of a mail header
542 * @header: the header that we're evaluating
544 * This function returns the secure value for a header. Basically it
545 * avoids DoS attacks caused by specially malformed headers like for
546 * example. From:From:From...From: some@mail.com
548 * Returns: returns the secured header
550 gchar * modest_text_utils_get_secure_header (const gchar *value, const gchar *header);
553 * modest_text_utils_quote_names:
554 * @recipients: a list of valid email addresses separated by ',' or ';'
556 * This function quotes the name part of an email address if it's not
557 * quoted and if it exists. For example
558 * aaa@bbb.com -> aaa@bbb.com
559 * "my name" <aaa@bbb.com> -> "my name" <aaa@bbb.com>
560 * my name aaa@bbb.com -> "my name" aaa@bbb.com
562 * It even supports things like
563 * my, name <aaa@bbb.com>, aaa@ccc.com -> "my, name" <aaa@bbb.com>; aaa@ccc.com
565 * Returns: a newly allocated string with the quoted email addresses
567 gchar * modest_text_utils_quote_names (const gchar *recipients);
569 #endif /* __MODEST_TEXT_UTILS_H__ */