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__
38 #include <gdk/gdkcolor.h>
39 #include <gtk/gtktextbuffer.h>
40 #include <gtk/gtklabel.h>
42 #define _FM(str) dgettext("hildon-fm",str)
43 #define _CS(str) dgettext("hildon-common-strings",str)
44 #define _HL(str) dgettext("hildon-libs",str)
45 #define _MD(str) dgettext("maemo-af-desktop",str)
46 #define _AB(str) dgettext("osso-addressbook",str)
47 #define _KR(str) dgettext("ke-recv",str)
48 #define _UR(str) dgettext("osso-uri",str)
50 /* Forbidden char arrays */
51 extern const gchar account_title_forbidden_chars[];
52 extern const gchar folder_name_forbidden_chars[];
53 extern const gchar user_name_forbidden_chars[];
54 extern const guint ACCOUNT_TITLE_FORBIDDEN_CHARS_LENGTH;
55 extern const guint FOLDER_NAME_FORBIDDEN_CHARS_LENGTH;
56 extern const guint USER_NAME_FORBIDDEN_CHARS_LENGTH;
58 /* It includes a white space as RFC 3676 Section 4.3 about usenet
59 message signatures defines */
60 #define MODEST_TEXT_UTILS_SIGNATURE_MARKER "-- "
63 * modest_text_utils_derived_subject:
64 * @subject: a string which contains the original subject
65 * @is_reply: whether the derived subject is for a reply or a forward message
67 * create a 'derived' subject line for eg. replies and forwards. Note
68 * that this function will use the localized versions of "Re" and
69 * "Fw", unless one of these two versions was already included. For
70 * example replying to an email in Finish would work as:
72 * "some subject" -> "VS: some subject"
73 * "VS: some subject" -> "VS: some subject"
74 * "Re: some subject" -> "Re: some subject"
75 * "Fw: some subject" -> "VS: Fw: some subject"
77 * Returns: a newly allocated string containing the resulting subject
79 gchar* modest_text_utils_derived_subject (const gchar *subject,
84 * modest_text_utils_quote:
85 * @text: a non-NULL string which contains the message to quote
86 * @from: a non-NULL sender of the original message
87 * @content_type: the non-NULL content type for the quoting, e.g. "text/html"
88 * @signature: NULL or the signature to add
89 * @sent_date: sent date/time of the original message
90 * @attachments: a #GList of the attachments
91 * @limit: specifies the maximum characters per line in the quoted text
93 * quote an existing message
95 * Returns: a newly allocated string containing the quoted message
97 gchar* modest_text_utils_quote (const gchar *text,
98 const gchar *content_type,
99 const gchar *signature,
101 const time_t sent_date,
107 * modest_text_utils_cited_text:
108 * @from: sender of the message
109 * @sent_date: the sent date of the original message
110 * @text: the text of the original message
112 * cite the text in a message
114 * Returns: a newly allocated string containing the cited text
116 gchar* modest_text_utils_cite (const gchar *text,
117 const gchar *content_type,
118 const gchar *signature,
123 * modest_text_utils_inlined_text
124 * @from: the non-NULL sender of the original message
125 * @sent_date: sent date/time of the original message
130 * creates a new string with the "Original message" text prepended to
131 * the text passed as argument and some data of the header
133 * Returns: a newly allocated string containing the quoted message
135 gchar* modest_text_utils_inline (const gchar *text,
136 const gchar *content_type,
137 const gchar *signature,
141 const gchar *subject);
144 * modest_text_utils_remove_address
145 * @address_list: non-NULL string with a comma-separated list of email addresses
146 * @address: an specific e-mail address
148 * remove a specific address from a list of email addresses; if @address
149 * is NULL, returns an unchanged (but newly allocated) @address_list
151 * Returns: a newly allocated string containing the new list, or NULL
152 * in case of error or the original @address_list was NULL
154 gchar* modest_text_utils_remove_address (const gchar *address_list,
155 const gchar *address);
159 * modest_text_utils_remove_duplicate_addresses
160 * @address_list: non-NULL string with a comma-separated list of email addresses
162 * remove duplicate addresses from a list of email addresses
164 * Returns: a newly allocated string containing the new list, or NULL
165 * in case of error or the original @address_list was NULL
167 gchar* modest_text_utils_remove_duplicate_addresses (const gchar *address_list);
171 * modest_text_utils_address_range_at_position:
172 * @address_list: non-NULL utf8 string containing a list of addresses
174 * @start: a gint pointer
175 * @end: a gint pointer
177 * Finds the start and end positions of the address at @position,
178 * in @recipients_list, a list of addresses in the format of a
179 * recipient list in email. It stores the results in @start and
182 void modest_text_utils_address_range_at_position (const gchar *recipients_list,
188 * modest_text_utils_hyperlinkify_begin:
190 * begin a linkify block, compiling the caches to be reused. Use it in mainloop.
192 void modest_text_utils_hyperlinkify_begin (void);
195 * modest_text_utils_hyperlinkify_end:
197 * end a linkify block, freeing the caches to be reused. Use it in mainloop.
199 void modest_text_utils_hyperlinkify_end (void);
202 * modest_text_utils_convert_to_html:
205 * convert plain text (utf8) into html
207 * Returns: a newly allocated string containing the html
209 gchar* modest_text_utils_convert_to_html (const gchar *txt);
212 * modest_text_utils_convert_to_html_body:
215 * convert plain text (utf8) into html without adding html headers.
217 * Returns: a newly allocated string containing the html
219 gchar* modest_text_utils_convert_to_html_body (const gchar *data, gssize n, gboolean hyperlinkify);
223 * modest_text_utils_strftime:
229 * this is just an alias for strftime(3), so we can use that without
230 * getting warning from gcc
232 * Returns: a formatted string of max length @max in @s
234 size_t modest_text_utils_strftime(char *s, size_t max, const char *fmt, time_t timet);
237 * modest_text_utils_hyperlinkify:
238 * @string_buffer: buffer where we replace uri strings with links
240 * Replace uri's with links in the buffer. This is required that the document
241 * do not contain linkified links already.
243 void modest_text_utils_hyperlinkify (GString *string_buffer);
246 * modest_text_utils_get_display_address:
247 * @address: original address (UTF8 string)
249 * make a 'display address' from an address:
250 * "Foo Bar <foo@bar.cx>" --> "Foo Bar"
251 * ie. removes "<...>" parts
252 * the change is in-place; removes leading whitespace
254 * NOTE: for optimization reasons, this function changes @address
257 void modest_text_utils_get_display_address (gchar *address);
260 * modest_text_utils_get_display_addresses:
261 * @addresses: a list of comma-separated addresses
263 * Transforms a list of email addresses in a list of recipients,
264 * replacing each plain email address by the correspondent display
267 * Returns: a newly allocated string, that must be freed by the caller
269 gchar *modest_text_utils_get_display_addresses (const gchar *addresses);
273 * modest_text_utils_get_email_address:
274 * @full_address: original address (UTF8 string)
276 * make a 'foo@bar.cx' from an address:
277 * "Foo Bar <foo@bar.cx> (Bla)" --> "foo@bar.cx"
278 * If no "<...>" is found, then it returns the full
281 * Returns: a newly allocated string with the copy.
283 * NULL in case of error or if address == NULL
285 gchar* modest_text_utils_get_email_address (const gchar *email_address);
289 * modest_text_utils_get_subject_prefix_len:
290 * @subject: original subject (UTF8 string)
292 * determine the length of the "Re:/RE:/Fwd:" prefix in an e-mail address
294 * Returns: the length of the prefix, or 0 if there is none
296 gint modest_text_utils_get_subject_prefix_len (const gchar *subject);
300 * modest_text_utils_utf8_strcmp:
301 * @s1: the first string
302 * @s2: the second string
303 * @insensitive: should the comparison be case-insensitive?
305 * a strcmp that is NULL-safe, can deal with UTF8 and case-insensitive comparison
307 * Returns: an integer less than, equal to, or greater than zero if s1 is found,
308 * respectively, to be less than, to match, or be greater than s2.
310 gint modest_text_utils_utf8_strcmp (const gchar* s1, const gchar *s2, gboolean insensitive);
315 * modest_text_utils_get_display_date:
316 * @date: the date to display
318 * get a string representation for a date.
320 * Returns: the new display date, as a *static* string.
321 * This string should not be modified, and will change
322 * upon recalling this function. g_strdup it if you to
326 const gchar* modest_text_utils_get_display_date (time_t date);
330 * modest_text_utils_get_display_size:
331 * @size: size in bytes
333 * get a string representation for a size in bytes.
335 * Returns: the newly allocated display string for the
336 * size in bytes. must be freed.
338 gchar * modest_text_utils_get_display_size (guint64 size);
343 * modest_text_utils_validate_domain_name:
344 * @email_address: a NULL-terminated string
346 * validates the domain name passed as argument
348 * Returns: TRUE if the domain name is valid, FALSE otherwise
350 gboolean modest_text_utils_validate_domain_name (const gchar *domain);
353 * modest_text_utils_validate_email_address:
354 * @email_address: a string
355 * @invalid_char_position: pointer to the position of the invalid
356 * character in case validation failed because of this, or %NULL.
358 * validates the email address passed as argument
360 * Returns: TRUE if the address is valid, FALSE otherwise
362 gboolean modest_text_utils_validate_email_address (const gchar *email_address,
363 const gchar **invalid_char_position);
367 * modest_text_utils_validate_folder_name:
368 * @folder_name: a string
370 * validates the folder name passed as argument. a 'valid folder name'
371 * is a name which should be valid on both Unix and Windows file systems.
372 * of course, this might be stricter than strictly needed in some cases,
373 * but it's better to err on the safe side.
375 * Returns: TRUE if the folder name is valid, FALSE otherwise
377 gboolean modest_text_utils_validate_folder_name (const gchar *folder_name);
380 * modest_text_utils_validate_recipient:
381 * @recipient: a string
382 * @invalid_char_position: pointer to the position of the invalid char,
383 * if validation failed because there's an invalid char there, or %NULL.
385 * validates @recipient as a valid recipient field for header.
386 * It's different from modest_text_utils_validate_email_address()
387 * as it validates a whole recipient, and not only the part between
388 * the < and > symbols.
390 * Returns: %TRUE if the recipient is valid, FALSE otherwise
392 gboolean modest_text_utils_validate_recipient (const gchar *recipient,
393 const gchar **invalid_char_position);
396 * modest_text_utils_split_addresses_list:
397 * @addresses: a string
399 * obtains a GSList of addresses from a string of addresses
400 * in the format understood by email protocols
402 * Returns: a newly allocated GSList of strings
404 GSList *modest_text_utils_split_addresses_list (const gchar *addresses);
407 * modest_text_utils_join_addresses:
408 * @from: comma separated string of addresses
409 * @to: comma separated string of addresses
410 * @cc: comma separated string of addresses
411 * @bcc: comma separated string of addresses
413 * joins all the addresses in a single comma-separated string
415 * Returns: a newly allocated string with a list of addresses
417 gchar *modest_text_utils_join_addresses (const gchar *from,
423 * modest_text_utils_get_addresses_indexes:
424 * @addresses: a string
425 * @start_indexes: a #GSList pointer
426 * @end_indexes: a #GSList pointer
428 * obtains two #GSList of @addresses with the range offsets of the addresses in
431 * Returns: a GSList of strings
433 void modest_text_utils_get_addresses_indexes (const gchar *addresses, GSList **start_indexes, GSList **end_indexes);
436 * modest_text_utils_address_with_standard_length:
437 * @recipients_list: a string
439 * obtains the list of recipients, but making sure that lines are not longer than 1000 chars
441 * Returns: a newly allocated string
443 gchar * modest_text_utils_address_with_standard_length (const gchar *recipients_list);
446 * modest_text_utils_get_color_string:
447 * @color: a #GdkColor
449 * Obtains a proper markup string for @color, in the format used
452 * Returns: a newly allocated string
454 gchar * modest_text_utils_get_color_string (GdkColor *color);
457 * modest_text_utils_text_buffer_get_text:
458 * @buffer: a #GtkTextBuffer
460 * Obtains the contents of a @buffer in a string, replacing image
461 * pixbufs with blank spaces.
463 * Returns: a newly allocated UTF-8 string
465 gchar * modest_text_utils_text_buffer_get_text (GtkTextBuffer *buffer);
468 ACCOUNT_TITLE_FORBIDDEN_CHARS,
469 FOLDER_NAME_FORBIDDEN_CHARS,
470 USER_NAME_FORBIDDEN_NAMES,
471 } ModestTextUtilsForbiddenCharType;
474 * modest_text_utils_label_get_selection:
475 * @label: a #GtkLabel
477 * Obtain the current selection of @label
479 * Returns: a string with current selection, or %NULL if no selection in @label
481 gchar * modest_text_utils_label_get_selection (GtkLabel *label);
484 * modest_text_utils_is_forbidden_char:
485 * @character: some character
486 * @type: the type of forbidden char (see #ModestTextUtilsForbiddenCharType)
488 * check whether the given character is 'forbidden'
490 * Returns: TRUE if it's forbidden, FALSE otherwise
492 gboolean modest_text_utils_is_forbidden_char (const gchar character,
493 ModestTextUtilsForbiddenCharType type);
496 * modest_text_utils_buffer_selection_is_valid:
497 * @buffer: a #GtkTextBuffer
499 * Checks if @buffer contains a valid selection for cut/copy. This means it's
500 * not empty, and no images are in the selection.
502 * Returns: %TRUE if there's a valid selection, false otherwise.
504 gboolean modest_text_utils_buffer_selection_is_valid (GtkTextBuffer *buffer);
507 * modest_text_utils_escape_mnemonics:
510 * obtains the representation of text, but escaping mnemonics (we duplicate _)
512 * Returns: a newly allocated string
514 gchar *modest_text_utils_escape_mnemonics (const gchar *text);
517 * modest_text_utils_simplify_recipients:
518 * @recipients: a list of recipients
520 * returns a list of simplified recipients:
521 * * a@b <a@b> converted to a@b
522 * * NULL converted to ""
524 * It's mainly intended for printing in screen addresses, but it can
525 * also be used for reply/forward.
527 gchar *modest_text_utils_simplify_recipients (const gchar *recipient);
530 * modest_text_utils_remove_duplicate_addresses_list
531 * @address_list: non-NULL #GSList of email addresses
533 * remove duplicate addresses from a list of email addresses
535 * Returns: a list without the duplicate addresses or NULL in case of
536 * error or the original @address_list was NULL
538 GSList *modest_text_utils_remove_duplicate_addresses_list (GSList *address_list);
541 * modest_text_utils_get_secure_header:
542 * @value: the value of a mail header
543 * @header: the header that we're evaluating
545 * This function returns the secure value for a header. Basically it
546 * avoids DoS attacks caused by specially malformed headers like for
547 * example. From:From:From...From: some@mail.com
549 * Returns: returns the secured header
551 gchar * modest_text_utils_get_secure_header (const gchar *value, const gchar *header);
554 * modest_text_utils_quote_names:
555 * @recipients: a list of valid email addresses separated by ',' or ';'
557 * This function quotes the name part of an email address if it's not
558 * quoted and if it exists. For example
559 * aaa@bbb.com -> aaa@bbb.com
560 * "my name" <aaa@bbb.com> -> "my name" <aaa@bbb.com>
561 * my name aaa@bbb.com -> "my name" aaa@bbb.com
563 * It even supports things like
564 * my, name <aaa@bbb.com>, aaa@ccc.com -> "my, name" <aaa@bbb.com>; aaa@ccc.com
566 * Returns: a newly allocated string with the quoted email addresses
568 gchar * modest_text_utils_quote_names (const gchar *recipients);
570 #endif /* __MODEST_TEXT_UTILS_H__ */