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>
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)
46 /* Forbidden char arrays */
47 extern const gchar account_title_forbidden_chars[];
48 extern const gchar folder_name_forbidden_chars[];
49 extern const gchar user_name_forbidden_chars[];
50 extern const guint ACCOUNT_TITLE_FORBIDDEN_CHARS_LENGTH;
51 extern const guint FOLDER_NAME_FORBIDDEN_CHARS_LENGTH;
52 extern const guint USER_NAME_FORBIDDEN_CHARS_LENGTH;
55 * modest_text_utils_derived_subject:
56 * @subject: a string which contains the original subject
57 * @prefix: the prefix for the new subject (such as 'Re:' or 'Fwd:'),
60 * create a 'derived' subject line for eg. replies and forwards
62 * Returns: a newly allocated string containing the resulting subject
63 * subject == NULL, then @prefix " " will be returned
65 gchar* modest_text_utils_derived_subject (const gchar *subject,
70 * modest_text_utils_quote:
71 * @text: a non-NULL string which contains the message to quote
72 * @from: a non-NULL sender of the original message
73 * @content_type: the non-NULL content type for the quoting, e.g. "text/html"
74 * @signature: NULL or the signature to add
75 * @sent_date: sent date/time of the original message
76 * @attachments: a #GList of the attachments
77 * @limit: specifies the maximum characters per line in the quoted text
79 * quote an existing message
81 * Returns: a newly allocated string containing the quoted message
83 gchar* modest_text_utils_quote (const gchar *text,
84 const gchar *content_type,
85 const gchar *signature,
87 const time_t sent_date,
93 * modest_text_utils_cited_text:
94 * @from: sender of the message
95 * @sent_date: the sent date of the original message
96 * @text: the text of the original message
98 * cite the text in a message
100 * Returns: a newly allocated string containing the cited text
102 gchar* modest_text_utils_cite (const gchar *text,
103 const gchar *content_type,
104 const gchar *signature,
109 * modest_text_utils_inlined_text
110 * @from: the non-NULL sender of the original message
111 * @sent_date: sent date/time of the original message
116 * creates a new string with the "Original message" text prepended to
117 * the text passed as argument and some data of the header
119 * Returns: a newly allocated string containing the quoted message
121 gchar* modest_text_utils_inline (const gchar *text,
122 const gchar *content_type,
123 const gchar *signature,
127 const gchar *subject);
130 * modest_text_utils_remove_address
131 * @address_list: none-NULL string with a comma-separated list of email addresses
132 * @address: an specific e-mail address
134 * remove a specific address from a list of email addresses; if @address
135 * is NULL, returns an unchanged @address_list
137 * Returns: a newly allocated string containing the new list, or NULL
138 * in case of error or the original @address_list was NULL
140 gchar* modest_text_utils_remove_address (const gchar *address_list,
141 const gchar *address);
144 * modest_text_utils_address_range_at_position:
145 * @address_list: utf8 string containing a list of addresses
147 * @start: a gint pointer
148 * @end: a gint pointer
150 * Finds the start and end positions of the address at @position,
151 * in @recipients_list, a list of addresses in the format of a
152 * recipient list in email. It stores the results in @start and
155 void modest_text_utils_address_range_at_position (const gchar *recipients_list,
162 * modest_text_utils_convert_to_html:
165 * convert plain text (utf8) into html
167 * Returns: a newly allocated string containing the html
169 gchar* modest_text_utils_convert_to_html (const gchar *txt);
172 * modest_text_utils_convert_to_html_body:
175 * convert plain text (utf8) into html without adding html headers.
177 * Returns: a newly allocated string containing the html
179 gchar* modest_text_utils_convert_to_html_body (const gchar *data);
183 * modest_text_utils_strftime:
189 * this is just an alias for strftime(3), so we can use that without
190 * getting warning from gcc
192 * Returns: a formatted string of max length @max in @s
194 size_t modest_text_utils_strftime(char *s, size_t max, const char *fmt, time_t timet);
199 * modest_text_utils_get_display_address:
200 * @address: original address (UTF8 string)
202 * make a 'display address' from an address:
203 * "Foo Bar <foo@bar.cx> (Bla)" --> "Foo Bar"
204 * ie. removes "<...>" and "(...)" parts
205 * the change is in-place; removes leading/trailing whitespace
207 * Returns: a new allocated string with the display address. NULL in
208 * case of error or if address == NULL
210 gchar* modest_text_utils_get_display_address (const gchar *address);
213 * modest_text_utils_get_email_address:
214 * @full_address: original address (UTF8 string)
216 * make a 'foo@bar.cx' from an address:
217 * "Foo Bar <foo@bar.cx> (Bla)" --> "foo@bar.cx"
218 * If no "<...>" is found, then it returns the full
221 * Returns: a newly allocated string with the copy.
223 * NULL in case of error or if address == NULL
225 gchar* modest_text_utils_get_email_address (const gchar *email_address);
229 * modest_text_utils_get_subject_prefix_len:
230 * @subject: original subject (UTF8 string)
232 * determine the length of the "Re:/RE:/Fwd:" prefix in an e-mail address
234 * Returns: the length of the prefix, or 0 if there is none
236 gint modest_text_utils_get_subject_prefix_len (const gchar *subject);
240 * modest_text_utils_utf8_strcmp:
241 * @s1: the first string
242 * @s2: the second string
243 * @insensitive: should the comparison be case-insensitive?
245 * a strcmp that is NULL-safe, can deal with UTF8 and case-insensitive comparison
247 * Returns: an integer less than, equal to, or greater than zero if s1 is found,
248 * respectively, to be less than, to match, or be greater than s2.
250 gint modest_text_utils_utf8_strcmp (const gchar* s1, const gchar *s2, gboolean insensitive);
255 * modest_text_utils_get_display_date:
256 * @date: the date to display
258 * get a string representation for a date.
260 * Returns: the new display date, as a newly allocated string;
263 gchar* modest_text_utils_get_display_date (time_t date);
267 * modest_text_utils_get_display_size:
268 * @size: size in bytes
270 * get a string representation for a size in bytes.
272 * Returns: the newly allocated display string for the
273 * size in bytes. must be freed.
275 gchar * modest_text_utils_get_display_size (guint64 size);
280 * modest_text_utils_validate_domain_name:
281 * @email_address: a NULL-terminated string
283 * validates the domain name passed as argument
285 * Returns: TRUE if the domain name is valid, FALSE otherwise
287 gboolean modest_text_utils_validate_domain_name (const gchar *domain);
290 * modest_text_utils_validate_email_address:
291 * @email_address: a string
292 * @invalid_char_position: pointer to the position of the invalid
293 * character in case validation failed because of this, or %NULL.
295 * validates the email address passed as argument
297 * Returns: TRUE if the address is valid, FALSE otherwise
299 gboolean modest_text_utils_validate_email_address (const gchar *email_address,
300 const gchar **invalid_char_position);
304 * modest_text_utils_validate_folder_name:
305 * @folder_name: a string
307 * validates the folder name passed as argument. a 'valid folder name'
308 * is a name which should be valid on both Unix and Windows file systems.
309 * of course, this might be stricter than strictly needed in some cases,
310 * but it's better to err on the safe side.
312 * Returns: TRUE if the folder name is valid, FALSE otherwise
314 gboolean modest_text_utils_validate_folder_name (const gchar *folder_name);
317 * modest_text_utils_validate_recipient:
318 * @recipient: a string
319 * @invalid_char_position: pointer to the position of the invalid char,
320 * if validation failed because there's an invalid char there, or %NULL.
322 * validates @recipient as a valid recipient field for header.
323 * It's different from modest_text_utils_validate_email_address()
324 * as it validates a whole recipient, and not only the part between
325 * the < and > symbols.
327 * Returns: %TRUE if the recipient is valid, FALSE otherwise
329 gboolean modest_text_utils_validate_recipient (const gchar *recipient,
330 const gchar **invalid_char_position);
333 * modest_text_utils_split_addresses_list:
334 * @addresses: a string
336 * obtains a GSList of addresses from a string of addresses
337 * in the format understood by email protocols
339 * Returns: a GSList of strings
341 GSList *modest_text_utils_split_addresses_list (const gchar *addresses);
344 * modest_text_utils_get_addresses_indexes:
345 * @addresses: a string
346 * @start_indexes: a #GSList pointer
347 * @end_indexes: a #GSList pointer
349 * obtains two #GSList of @addresses with the range offsets of the addresses in
352 * Returns: a GSList of strings
354 void modest_text_utils_get_addresses_indexes (const gchar *addresses, GSList **start_indexes, GSList **end_indexes);
357 * modest_text_utils_get_color_string:
358 * @color: a #GdkColor
360 * Obtains a proper markup string for @color, in the format used
363 * Returns: a newly allocated string
365 gchar * modest_text_utils_get_color_string (GdkColor *color);
368 * modest_text_utils_text_buffer_get_text:
369 * @buffer: a #GtkTextBuffer
371 * Obtains the contents of a @buffer in a string, replacing image
372 * pixbufs with blank spaces.
374 * Returns: a newly allocated UTF-8 string
376 gchar * modest_text_utils_text_buffer_get_text (GtkTextBuffer *buffer);
379 ACCOUNT_TITLE_FORBIDDEN_CHARS,
380 FOLDER_NAME_FORBIDDEN_CHARS,
381 USER_NAME_FORBIDDEN_NAMES,
382 } ModestTextUtilsForbiddenCharType;
384 gboolean modest_text_utils_is_forbidden_char (const gchar character,
385 ModestTextUtilsForbiddenCharType type);
387 #endif /* __MODEST_TEXT_UTILS_H__ */