* src/modest-ui-dimming-rules.c:
[modest] / src / modest-text-utils.h
1 /* Copyright (c) 2006, Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
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.
16  *
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.
28  */
29
30
31 /* modest-text-utils.h */
32
33 #ifndef __MODEST_TEXT_UTILS_H__
34 #define __MODEST_TEXT_UTILS_H__
35
36 #include <time.h>
37 #include <glib.h>
38 #include <gdk/gdkcolor.h>
39
40 #define _FM(str) dgettext("hildon-fm",str)
41 #define _CS(str) dgettext("hildon-common-strings",str)
42
43 /**
44  * modest_text_utils_derived_subject:
45  * @subject: a string which contains the original subject
46  * @prefix: the prefix for the new subject (such as 'Re:' or 'Fwd:'),
47  *           must not be NULL
48  *
49  * create a 'derived' subject line for eg. replies and forwards 
50  * 
51  * Returns: a newly allocated string containing the resulting subject
52  * subject == NULL, then @prefix " " will be returned
53  */
54 gchar* modest_text_utils_derived_subject (const gchar *subject, 
55                                           const gchar* prefix);
56
57
58 /**
59  * modest_text_utils_quote:
60  * @text: a non-NULL string which contains the message to quote
61  * @from: a non-NULL  sender of the original message
62  * @content_type: the non-NULL content type for the quoting, e.g. "text/html"
63  * @signature: NULL or the signature to add
64  * @sent_date: sent date/time of the original message
65  * @attachments: a #GList of the attachments
66  * @limit: specifies the maximum characters per line in the quoted text
67  * 
68  * quote an existing message
69  * 
70  * Returns: a newly allocated string containing the quoted message
71  */
72 gchar* modest_text_utils_quote (const gchar *text, 
73                                 const gchar *content_type,
74                                 const gchar *signature,
75                                 const gchar *from,
76                                 const time_t sent_date, 
77                                 GList *attachments,
78                                 int limit);
79
80
81 /**
82  * modest_text_utils_cited_text:
83  * @from: sender of the message
84  * @sent_date: the sent date of the original message
85  * @text: the text of the original message
86  *
87  * cite the text in a message
88  * 
89  * Returns: a newly allocated string containing the cited text
90  */
91 gchar* modest_text_utils_cite (const gchar *text,
92                                const gchar *content_type,
93                                const gchar *signature,
94                                const gchar *from,
95                                time_t sent_date);
96
97 /**
98  * modest_text_utils_inlined_text
99  * @from: the non-NULL sender of the original message
100  * @sent_date: sent date/time of the original message
101  * @to: 
102  * @subject: 
103  * @text: 
104  *
105  * creates a new string with the "Original message" text prepended to
106  * the text passed as argument and some data of the header
107  * 
108  * Returns: a newly allocated string containing the quoted message
109  */
110 gchar*   modest_text_utils_inline (const gchar *text,
111                                    const gchar *content_type,
112                                    const gchar *signature,
113                                    const gchar *from,
114                                    time_t sent_date,
115                                    const gchar *to,
116                                    const gchar *subject);
117
118 /**
119  * modest_text_utils_remove_address
120  * @address_list: none-NULL string with a comma-separated list of email addresses
121  * @address: an specific e-mail address 
122  *
123  * remove a specific address from a list of email addresses; if @address
124  * is NULL, returns an unchanged @address_list
125  * 
126  * Returns: a newly allocated string containing the new list, or NULL
127  * in case of error or the original @address_list was NULL
128  */
129 gchar*   modest_text_utils_remove_address (const gchar *address_list, 
130                                            const gchar *address);
131
132 /**
133  * modest_text_utils_address_range_at_position:
134  * @address_list: utf8 string containing a list of addresses
135  * @position: a gint
136  * @start: a gint pointer
137  * @end: a gint pointer
138  *
139  * Finds the start and end positions of the address at @position,
140  * in @recipients_list, a list of addresses in the format of a 
141  * recipient list in email. It stores the results in @start and
142  * @end
143  */
144 void     modest_text_utils_address_range_at_position (const gchar *recipients_list,
145                                                       gint position,
146                                                       gint *start,
147                                                       gint *end);
148                                                       
149
150 /**
151  * modest_text_utils_convert_to_html:
152  * @txt: a string
153  *
154  * convert plain text (utf8) into html
155  * 
156  * Returns: a newly allocated string containing the html
157  */
158 gchar*  modest_text_utils_convert_to_html (const gchar *txt);
159
160 /**
161  * modest_text_utils_convert_to_html_body:
162  * @txt: a string
163  *
164  * convert plain text (utf8) into html without adding html headers.
165  * 
166  * Returns: a newly allocated string containing the html
167  */
168 gchar*  modest_text_utils_convert_to_html_body (const gchar *data);
169
170
171 /**
172  * modest_text_utils_strftime:
173  * @s:
174  * @max:
175  * @fmt:
176  * @timet:
177  *
178  * this is just an alias for strftime(3), so we can use that without
179  * getting warning from gcc
180  * 
181  * Returns: a formatted string of max length @max in @s
182  */
183 size_t modest_text_utils_strftime(char *s, size_t max, const char  *fmt, time_t timet);
184
185
186
187 /**
188  * modest_text_utils_get_display_addres:
189  * @address: original address (UTF8 string)
190  *
191  * make a 'display address' from an address:
192  * "Foo Bar <foo@bar.cx> (Bla)" --> "Foo Bar"
193  * ie. removes "<...>" and "(...)" parts
194  * the change is in-place; removes leading/trailing whitespace
195  * 
196  * Returns: the new address of the string; this new string
197  * is _NOT_ newly allocated, so should not be freed. (remember
198  * the old address of the parameter if that one needs to be freed)
199  * 
200  * NULL in case of error or if address == NULL
201  */
202 gchar* modest_text_utils_get_display_address (gchar *address);
203
204
205 /**
206  * modest_text_utils_get_subject_prefix_len:
207  * @subject: original subject (UTF8 string)
208  *
209  * determine the length of the "Re:/RE:/Fwd:" prefix in an e-mail address
210  * 
211  * Returns: the length of the  prefix, or 0 if there is none
212  */
213 gint modest_text_utils_get_subject_prefix_len (const gchar *subject);
214
215
216 /**
217  * modest_text_utils_utf8_strcmp:
218  * @s1: the first string
219  * @s2: the second string
220  * @insensitive: should the comparison be case-insensitive?
221  *
222  * a strcmp that is NULL-safe, can deal with UTF8 and case-insensitive comparison 
223  *
224  * Returns: an integer less than, equal to, or greater than zero if s1 is found,
225  * respectively, to be less than, to match, or be greater than s2.
226  */
227 gint modest_text_utils_utf8_strcmp (const gchar* s1, const gchar *s2, gboolean insensitive);
228
229
230
231 /**
232  * modest_text_utils_get_display_date:
233  * @date: the date to display
234  *
235  * get a string representation for a date.
236  * 
237  * Returns: the new display date, as a newly allocated string;
238  * free with g_free
239  */
240 gchar* modest_text_utils_get_display_date (time_t date);
241
242
243 /**
244  * modest_text_utils_get_display_size:
245  * @size: size in bytes
246  *
247  * get a string representation for a size in bytes.
248  * 
249  * Returns: the newly allocated display string for the
250  * size in bytes. must be freed.
251  */
252 gchar * modest_text_utils_get_display_size (guint64 size);
253
254
255 /**
256  * modest_text_utils_validate_email_address:
257  * @email_address: a string
258  * @invalid_char_position: pointer to the position of the invalid
259  * character in case validation failed because of this, or %NULL.
260  * 
261  * validates the email address passed as argument
262  * 
263  * Returns: TRUE if the address is valid, FALSE otherwise
264  **/
265 gboolean     modest_text_utils_validate_email_address (const gchar *email_address, 
266                                                        const gchar **invalid_char_position);
267
268 /**
269  * modest_text_utils_validate_recipient:
270  * @recipient: a string
271  * @invalid_char_position: pointer to the position of the invalid char,
272  * if validation failed because there's an invalid char there, or %NULL.
273  *
274  * validates @recipient as a valid recipient field for header.
275  * It's different from modest_text_utils_validate_email_address()
276  * as it validates a whole recipient, and not only the part between
277  * the &lt; and &gt; symbols.
278  *
279  * Returns: %TRUE if the recipient is valid, FALSE otherwise
280  **/
281 gboolean     modest_text_utils_validate_recipient (const gchar *recipient,
282                                                    const gchar **invalid_char_position);
283
284 /**
285  * modest_text_utils_split_addresses_list:
286  * @addresses: a string
287  *
288  * obtains a GSList of addresses from a string of addresses
289  * in the format understood by email protocols
290  *
291  * Returns: a GSList of strings
292  **/
293 GSList      *modest_text_utils_split_addresses_list (const gchar *addresses);
294
295 /**
296  * modest_text_utils_get_addresses_indexes:
297  * @addresses: a string
298  * @start_indexes: a #GSList pointer
299  * @end_indexes: a #GSList pointer
300  *
301  * obtains two #GSList of @addresses with the range offsets of the addresses in
302  * the string
303  *
304  * Returns: a GSList of strings
305  **/
306 void         modest_text_utils_get_addresses_indexes (const gchar *addresses, GSList **start_indexes, GSList **end_indexes);
307
308 /**
309  * modest_text_utils_get_color_string:
310  * @color: a #GdkColor
311  *
312  * Obtains a proper markup string for @color, in the format used
313  * by Pango and HTML.
314  *
315  * Returns: a newly allocated string
316  */
317 gchar *      modest_text_utils_get_color_string (GdkColor *color);
318
319 #endif /* __MODEST_TEXT_UTILS_H__ */