1 /*
2  * libEtPan! -- a mail stuff library
3  *
4  * Copyright (C) 2001, 2005 - DINH Viet Hoa
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. Neither the name of the libEtPan! project nor the names of its
16  *    contributors may be used to endorse or promote products derived
17  *    from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  */
31 
32 /*
33  * $Id: mailmh.h,v 1.27 2008/02/20 22:15:52 hoa Exp $
34  */
35 
36 #ifndef MAILMH_H
37 
38 #define MAILMH_H
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 #include <sys/types.h>
45 
46 #include <libetpan/libetpan-config.h>
47 #include <libetpan/carray.h>
48 #include <libetpan/chash.h>
49 
50 enum {
51   MAILMH_NO_ERROR = 0,
52   MAILMH_ERROR_FOLDER,
53   MAILMH_ERROR_MEMORY,
54   MAILMH_ERROR_FILE,
55   MAILMH_ERROR_COULD_NOT_ALLOC_MSG,
56   MAILMH_ERROR_RENAME,
57   MAILMH_ERROR_MSG_NOT_FOUND
58 };
59 
60 struct mailmh {
61   struct mailmh_folder * mh_main;
62 };
63 
64 struct mailmh_msg_info {
65   unsigned int msg_array_index;
66   uint32_t msg_index;
67   size_t msg_size;
68   time_t msg_mtime;
69 };
70 
71 struct mailmh_folder {
72   char * fl_filename;
73   unsigned int fl_array_index;
74 
75   char * fl_name;
76   time_t fl_mtime;
77   struct mailmh_folder * fl_parent;
78   uint32_t fl_max_index;
79 
80   carray * fl_msgs_tab;
81   chash * fl_msgs_hash;
82 
83   carray * fl_subfolders_tab;
84   chash * fl_subfolders_hash;
85 };
86 
87 struct mailmh * mailmh_new(const char * foldername);
88 void mailmh_free(struct mailmh * f);
89 
90 struct mailmh_msg_info *
91 mailmh_msg_info_new(uint32_t indx, size_t size, time_t mtime);
92 void mailmh_msg_info_free(struct mailmh_msg_info * msg_info);
93 
94 struct mailmh_folder * mailmh_folder_new(struct mailmh_folder * parent,
95 					 const char * name);
96 void mailmh_folder_free(struct mailmh_folder * folder);
97 
98 int mailmh_folder_add_subfolder(struct mailmh_folder * parent,
99 				const char * name);
100 
101 struct mailmh_folder * mailmh_folder_find(struct mailmh_folder * root,
102 					  const char * filename);
103 
104 int mailmh_folder_remove_subfolder(struct mailmh_folder * folder);
105 
106 int mailmh_folder_rename_subfolder(struct mailmh_folder * src_folder,
107 				   struct mailmh_folder * dst_folder,
108 				   const char * new_name);
109 
110 int mailmh_folder_get_message_filename(struct mailmh_folder * folder,
111 				       uint32_t indx, char ** result);
112 
113 int mailmh_folder_get_message_fd(struct mailmh_folder * folder,
114 				 uint32_t indx, int flags, int * result);
115 
116 int mailmh_folder_get_message_size(struct mailmh_folder * folder,
117 				   uint32_t indx, size_t * result);
118 
119 int mailmh_folder_add_message_uid(struct mailmh_folder * folder,
120     const char * message, size_t size,
121     uint32_t * pindex);
122 
123 int mailmh_folder_add_message(struct mailmh_folder * folder,
124 			      const char * message, size_t size);
125 
126 int mailmh_folder_add_message_file_uid(struct mailmh_folder * folder,
127     int fd, uint32_t * pindex);
128 
129 int mailmh_folder_add_message_file(struct mailmh_folder * folder,
130 				   int fd);
131 
132 int mailmh_folder_remove_message(struct mailmh_folder * folder,
133 				 uint32_t indx);
134 
135 int mailmh_folder_move_message(struct mailmh_folder * dest_folder,
136 			       struct mailmh_folder * src_folder,
137 			       uint32_t indx);
138 
139 int mailmh_folder_update(struct mailmh_folder * folder);
140 
141 unsigned int mailmh_folder_get_message_number(struct mailmh_folder * folder);
142 
143 #ifdef __cplusplus
144 }
145 #endif
146 
147 #endif
148