1 /*
2  Copyright (c) 2004-2012 NFG Net Facilities Group BV support@nfg.nl
3 
4  This program is free software; you can redistribute it and/or
5  modify it under the terms of the GNU General Public License
6  as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later
8  version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 
20 /*
21  *
22  * \brief DbmailMessage class
23  *
24  */
25 
26 #ifndef DM_MESSAGE_H
27 #define DM_MESSAGE_H
28 
29 
30 #include "dbmail.h"
31 
32 /*
33  * preliminary goal is to provide an interface between dbmail and gmime.
34  *
35  * ambition is facilitation of language-bindings.
36  *
37  * very much unfinished, work in progress, subject to change, etc...
38  *
39  */
40 
41 
42 /*
43  * initializers
44  */
45 
46 DbmailMessage * dbmail_message_new(Mempool_T);
47 DbmailMessage * dbmail_message_init_with_string(DbmailMessage *self, const char *content);
48 DbmailMessage * dbmail_message_construct(DbmailMessage *self,
49 		const gchar *sender, const gchar *recipient,
50 		const gchar *subject, const gchar *body);
51 
52 /*
53  * database facilities
54  */
55 
56 int dbmail_message_store(DbmailMessage *message);
57 int dbmail_message_cache_headers(const DbmailMessage *message);
58 gboolean dm_message_store(DbmailMessage *m);
59 
60 DbmailMessage * dbmail_message_retrieve(DbmailMessage *self, uint64_t physid);
61 
62 /*
63  * attribute accessors
64  */
65 void dbmail_message_set_physid(DbmailMessage *self, uint64_t physid);
66 uint64_t dbmail_message_get_physid(const DbmailMessage *self);
67 
68 void dbmail_message_set_envelope_recipient(DbmailMessage *self, const char *envelope);
69 const char * dbmail_message_get_envelope_recipient(const DbmailMessage *self);
70 
71 void dbmail_message_set_internal_date(DbmailMessage *self, char *internal_date);
72 gchar * dbmail_message_get_internal_date(const DbmailMessage *self, int thisyear);
73 
74 int dbmail_message_set_class(DbmailMessage *self, int klass);
75 int dbmail_message_get_class(const DbmailMessage *self);
76 
77 gchar * dbmail_message_to_string(const DbmailMessage *self);
78 gchar * dbmail_message_hdrs_to_string(const DbmailMessage *self);
79 gchar * dbmail_message_body_to_string(const DbmailMessage *self);
80 
81 const char * dbmail_message_get_charset(DbmailMessage *self);
82 
83 size_t dbmail_message_get_size(const DbmailMessage *self, gboolean crlf);
84 
85 GList * dbmail_message_get_header_addresses(DbmailMessage *message, const char *field);
86 
87 
88 /*
89  * manipulate the actual message content
90  */
91 
92 void dbmail_message_set_header(DbmailMessage *self, const char *header, const char *value);
93 const gchar * dbmail_message_get_header(const DbmailMessage *self, const char *header);
94 
95 /* Get all instances of a header. */
96 GList * dbmail_message_get_header_repeated(const DbmailMessage *self, const char *header);
97 
98 void dbmail_message_cache_referencesfield(const DbmailMessage *self);
99 void dbmail_message_cache_envelope(const DbmailMessage *self);
100 
101 /*
102  * destructor
103  */
104 
105 void dbmail_message_free(DbmailMessage *self);
106 
107 
108 /* move these elsewhere: */
109 
110 unsigned find_end_of_header(const char *);
111 
112 char * g_mime_object_get_body(const GMimeObject *object);
113 
114 // from sort.h
115 dsn_class_t sort_and_deliver(DbmailMessage *self,
116 		const char *destination, uint64_t useridnr,
117 		const char *mailbox, mailbox_source source);
118 
119 dsn_class_t sort_deliver_to_mailbox(DbmailMessage *message,
120 		uint64_t useridnr, const char *mailbox, mailbox_source source,
121 		int *msgflags, GList *keywords);
122 
123 // from dm_pipe.h
124 //
125 // Either convert the message struct to a
126 // string, or send the database rows raw.
127 enum sendwhat {
128 	SENDMESSAGE     = 0,
129 	SENDRAW         = 1
130 };
131 
132 // Use the system sendmail binary.
133 #define SENDMAIL        NULL
134 
135 
136 /**
137  * \brief Inserts a message in the database.
138  * \return 0
139  */
140 int insert_messages(DbmailMessage *message, List_T dsnusers);
141 int send_mail(DbmailMessage *message,
142 		const char *to, const char *from,
143 		const char *preoutput,
144 		enum sendwhat sendwhat, char *sendmail_external);
145 
146 int send_forward_list(DbmailMessage *message, GList *targets, const char *from);
147 
148 
149 #endif
150