summaryrefslogtreecommitdiffabout
path: root/kmicromail/libetpan/mh/mailmh.h
blob: 00199b8ccc2bcef2fdce7fb08eb714857830fc1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
 * libEtPan! -- a mail stuff library
 *
 * Copyright (C) 2001, 2002 - DINH Viet Hoa
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the libEtPan! project nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

/*
 * $Id$
 */

#ifndef MAILMH_H

#define MAILMH_H

#ifdef __cplusplus
extern "C" {
#endif

#include <sys/types.h>
#include <inttypes.h>
#include <libetpan/carray.h>
#include <libetpan/cinthash.h>
#include <libetpan/chash.h>

enum {
  MAILMH_NO_ERROR = 0,
  MAILMH_ERROR_FOLDER,
  MAILMH_ERROR_MEMORY,
  MAILMH_ERROR_FILE,
  MAILMH_ERROR_COULD_NOT_ALLOC_MSG,
  MAILMH_ERROR_RENAME,
  MAILMH_ERROR_MSG_NOT_FOUND,
};

struct mailmh {
  struct mailmh_folder * mh_main;
};

struct mailmh_msg_info {
  unsigned int msg_array_index;
  uint32_t msg_index;
  size_t msg_size;
  time_t msg_mtime;
};

struct mailmh_folder {
  char * fl_filename;
  unsigned int fl_array_index;

  char * fl_name;
  time_t fl_mtime;
  struct mailmh_folder * fl_parent;
  uint32_t fl_max_index;

  carray * fl_msgs_tab;
#if 0
  cinthash_t * fl_msgs_hash;
#endif
  chash * fl_msgs_hash;

  carray * fl_subfolders_tab;
  chash * fl_subfolders_hash;
};

struct mailmh * mailmh_new(const char * foldername);
void mailmh_free(struct mailmh * f);

struct mailmh_msg_info *
mailmh_msg_info_new(uint32_t index, size_t size, time_t mtime);
void mailmh_msg_info_free(struct mailmh_msg_info * msg_info);

struct mailmh_folder * mailmh_folder_new(struct mailmh_folder * parent,
					 const char * name);
void mailmh_folder_free(struct mailmh_folder * folder);

int mailmh_folder_add_subfolder(struct mailmh_folder * parent,
				const char * name);

struct mailmh_folder * mailmh_folder_find(struct mailmh_folder * root,
					  const char * filename);

int mailmh_folder_remove_subfolder(struct mailmh_folder * folder);

int mailmh_folder_rename_subfolder(struct mailmh_folder * src_folder,
				   struct mailmh_folder * dst_folder,
				   const char * new_name);

int mailmh_folder_get_message_filename(struct mailmh_folder * folder,
				       uint32_t index, char ** result);

int mailmh_folder_get_message_fd(struct mailmh_folder * folder,
				 uint32_t index, int flags, int * result);

int mailmh_folder_get_message_size(struct mailmh_folder * folder,
				   uint32_t index, size_t * result);

int mailmh_folder_add_message_uid(struct mailmh_folder * folder,
    const char * message, size_t size,
    uint32_t * pindex);

int mailmh_folder_add_message(struct mailmh_folder * folder,
			      const char * message, size_t size);

int mailmh_folder_add_message_file_uid(struct mailmh_folder * folder,
    int fd, uint32_t * pindex);

int mailmh_folder_add_message_file(struct mailmh_folder * folder,
				   int fd);

int mailmh_folder_remove_message(struct mailmh_folder * folder,
				 uint32_t index);

int mailmh_folder_move_message(struct mailmh_folder * dest_folder,
			       struct mailmh_folder * src_folder,
			       uint32_t index);

int mailmh_folder_update(struct mailmh_folder * folder);

unsigned int mailmh_folder_get_message_number(struct mailmh_folder * folder);

#ifdef __cplusplus
}
#endif

#endif