405a231e45cf981dd977943879e4b65c7355af22
[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
39 /**
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:'),
43  *           must not be NULL
44  *
45  * create a 'derived' subject line for eg. replies and forwards 
46  * 
47  * Returns: a newly allocated string containing the resulting subject
48  * subject == NULL, then @prefix " " will be returned
49  */
50 gchar* modest_text_utils_derived_subject (const gchar *subject, 
51                                           const gchar* prefix);
52
53
54 /**
55  * modest_text_utils_quote:
56  * @buf: a string which contains the message to quote
57  * @from: the sender of the original message
58  * @sent_date: sent date/time of the original message
59  * @limit: specifies the maximum characters per line in the quoted text
60  * 
61  * quote an existing message
62  * 
63  * Returns: a newly allocated string containing the quoted message
64  */
65 gchar* modest_text_utils_quote (const gchar *text, 
66                                 const gchar *content_type,
67                                 const gchar *from,
68                                 const time_t sent_date, 
69                                 int limit);
70
71
72 /**
73  * modest_text_utils_cited_text:
74  * @from: sender of the message
75  * @sent_date: the sent date of the original message
76  * @text: the text of the original message
77  *
78  * cite the text in a message
79  * 
80  * Returns: a newly allocated string containing the cited text
81  */
82 gchar* modest_text_utils_cite (const gchar *text,
83                                const gchar *content_type,
84                                const gchar *from,
85                                time_t sent_date);
86
87 /**
88  * modest_text_utils_inlined_text
89  * @from: the sender of the original message
90  * @sent_date: sent date/time of the original message
91  * @to: sent date/time of the original message
92  * @subject: sent date/time of the original message
93  * @text: sent date/time of the original message
94  *
95  * creates a new string with the "Original message" text prepended to
96  * the text passed as argument and some data of the header
97  * 
98  * Returns: a newly allocated string containing the quoted message
99  */
100 gchar*   modest_text_utils_inline (const gchar *text,
101                                    const gchar *content_type,
102                                    const gchar *from,
103                                    time_t sent_date,
104                                    const gchar *to,
105                                    const gchar *subject);
106
107 /**
108  * modest_text_utils_remove_address
109  * @address_list: none-NULL string with a comma-separated list of email addresses
110  * @address: an specific e-mail address 
111  *
112  * remove a specific address from a list of email addresses; if @address
113  * is NULL, returns an unchanged @address_list
114  * 
115  * Returns: a newly allocated string containing the new list, or NULL
116  * in case of error or the original @address_list was NULL
117  */
118 gchar*   modest_text_utils_remove_address (const gchar *address_list, 
119                                            const gchar *address);
120
121 /**
122  * modest_text_utils_convert_to_html:
123  * @txt: a string which contains the message to quote
124  *
125  * convert plain text (utf8) into html
126  * 
127  * Returns: a newly allocated string containing the html
128  */
129 gchar*  modest_text_utils_convert_to_html (const gchar *data);
130
131
132 /**
133  * modest_text_utils_strftime:
134  * @s:
135  * @max:
136  * @fmt:
137  * @tm
138  *
139  * this is just an alias for strftime(3), so we can use that without
140  * getting warning from gcc
141  * 
142  * Returns: a formatted string of max length @max in @s
143  */
144 size_t modest_text_utils_strftime(char *s, size_t max, const char  *fmt, const  struct tm *tm);
145
146
147
148 /**
149  * modest_text_utils_display_addres:
150  * @address: original address (UTF8 string)
151  *
152  * make a 'display address' from an address:
153  * "Foo Bar <foo@bar.cx> (Bla)" --> "Foo Bar"
154  * ie. removes "<...>" and "(...)" parts
155  * the change is in-place; removes leading/trailing whitespace
156  * 
157  * Returns: the new address. The string is *not* newly allocated.
158  * NULL in case of error
159  */
160 gchar* modest_text_utils_display_address (gchar *address);
161
162
163 #endif /* __MODEST_TEXT_UTILS_H__ */