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__
40 * modest_text_utils_derived_subject:
41 * @subject: a string which contains the original subject
42 * @prefix: the prefix for the new subject (such as 'Re:' or 'Fwd:'),
45 * create a 'derived' subject line for eg. replies and forwards
47 * Returns: a newly allocated string containing the resulting subject
48 * subject == NULL, then @prefix " " will be returned
50 gchar* modest_text_utils_derived_subject (const gchar *subject,
55 * modest_text_utils_quote:
56 * @text: a non-NULL string which contains the message to quote
57 * @from: a non-NULL sender of the original message
58 * @content_type: the non-NULL content type for the quoting, e.g. "text/html"
59 * @signature: NULL or the signature to add
60 * @sent_date: sent date/time of the original message
61 * @limit: specifies the maximum characters per line in the quoted text
63 * quote an existing message
65 * Returns: a newly allocated string containing the quoted message
67 gchar* modest_text_utils_quote (const gchar *text,
68 const gchar *content_type,
69 const gchar *signature,
71 const time_t sent_date,
76 * modest_text_utils_cited_text:
77 * @from: sender of the message
78 * @sent_date: the sent date of the original message
79 * @text: the text of the original message
81 * cite the text in a message
83 * Returns: a newly allocated string containing the cited text
85 gchar* modest_text_utils_cite (const gchar *text,
86 const gchar *content_type,
87 const gchar *signature,
92 * modest_text_utils_inlined_text
93 * @from: the non-NULL sender of the original message
94 * @sent_date: sent date/time of the original message
99 * creates a new string with the "Original message" text prepended to
100 * the text passed as argument and some data of the header
102 * Returns: a newly allocated string containing the quoted message
104 gchar* modest_text_utils_inline (const gchar *text,
105 const gchar *content_type,
106 const gchar *signature,
110 const gchar *subject);
113 * modest_text_utils_remove_address
114 * @address_list: none-NULL string with a comma-separated list of email addresses
115 * @address: an specific e-mail address
117 * remove a specific address from a list of email addresses; if @address
118 * is NULL, returns an unchanged @address_list
120 * Returns: a newly allocated string containing the new list, or NULL
121 * in case of error or the original @address_list was NULL
123 gchar* modest_text_utils_remove_address (const gchar *address_list,
124 const gchar *address);
127 * modest_text_utils_address_range_at_position:
128 * @address_list: utf8 string containing a list of addresses
130 * @start: a gint pointer
131 * @end: a gint pointer
133 * Finds the start and end positions of the address at @position,
134 * in @recipients_list, a list of addresses in the format of a
135 * recipient list in email. It stores the results in @start and
138 void modest_text_utils_address_range_at_position (const gchar *recipients_list,
145 * modest_text_utils_convert_to_html:
148 * convert plain text (utf8) into html
150 * Returns: a newly allocated string containing the html
152 gchar* modest_text_utils_convert_to_html (const gchar *txt);
155 * modest_text_utils_convert_to_html_body:
158 * convert plain text (utf8) into html without adding html headers.
160 * Returns: a newly allocated string containing the html
162 gchar* modest_text_utils_convert_to_html_body (const gchar *data);
166 * modest_text_utils_strftime:
172 * this is just an alias for strftime(3), so we can use that without
173 * getting warning from gcc
175 * Returns: a formatted string of max length @max in @s
177 size_t modest_text_utils_strftime(char *s, size_t max, const char *fmt, time_t timet);
182 * modest_text_utils_get_display_addres:
183 * @address: original address (UTF8 string)
185 * make a 'display address' from an address:
186 * "Foo Bar <foo@bar.cx> (Bla)" --> "Foo Bar"
187 * ie. removes "<...>" and "(...)" parts
188 * the change is in-place; removes leading/trailing whitespace
190 * Returns: the new address. The string is *not* newly allocated.
191 * NULL in case of error
193 gchar* modest_text_utils_get_display_address (gchar *address);
197 * modest_text_utils_get_subject_prefix_len:
198 * @subject: original subject (UTF8 string)
200 * determine the length of the "Re:/RE:/Fwd:" prefix in an e-mail address
202 * Returns: the length of the prefix, or 0 if there is none
204 gint modest_text_utils_get_subject_prefix_len (const gchar *subject);
208 * modest_text_utils_utf8_strcmp:
209 * @s1: the first string
210 * @s2: the second string
211 * @insensitive: should the comparison be case-insensitive?
213 * a strcmp that is NULL-safe, can deal with UTF8 and case-insensitive comparison
215 * Returns: an integer less than, equal to, or greater than zero if s1 is found,
216 * respectively, to be less than, to match, or be greater than s2.
218 gint modest_text_utils_utf8_strcmp (const gchar* s1, const gchar *s2, gboolean insensitive);
223 * modest_text_utils_get_display_date:
224 * @date: the date to display
226 * get a string representation for a date.
228 * Returns: the new display date, as a newly allocated string;
231 gchar* modest_text_utils_get_display_date (time_t date);
235 * modest_text_utils_get_display_size:
236 * @size: size in bytes
238 * get a string representation for a size in bytes.
240 * Returns: the newly allocated display string for the
241 * size in bytes. must be freed.
243 gchar * modest_text_utils_get_display_size (guint size);
247 * modest_text_utils_validate_email_address:
248 * @email_address: a string
250 * validates the email address passed as argument
252 * Returns: TRUE if the address is valid, FALSE otherwise
254 gboolean modest_text_utils_validate_email_address (const gchar *email_address);
257 * modest_text_utils_validate_recipient:
258 * @recipient: a string
260 * validates @recipient as a valid recipient field for header.
261 * It's different from modest_text_utils_validate_email_address()
262 * as it validates a whole recipient, and not only the part between
263 * the < and > symbols.
265 * Returns: %TRUE if the recipient is valid, FALSE otherwise
267 gboolean modest_text_utils_validate_recipient (const gchar *recipient);
270 * modest_text_utils_split_addresses_list:
271 * @addresses: a string
273 * obtains a GSList of addresses from a string of addresses
274 * in the format understood by email protocols
276 * Returns: a GSList of strings
278 GSList *modest_text_utils_split_addresses_list (const gchar *addresses);
280 #endif /* __MODEST_TEXT_UTILS_H__ */