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