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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
|
1/ Introduction
---------------
libEtPan! is mainly a library that will handle all kind of mailbox access.
For example: IMAPrev4, POP3, NNTP, mbox, MH.
You have two kinds of mailbox access, either using low-level functions
with a different interface for each kind of access or using higher-level
functions, using a driver to wrap the higher-level API.
2/ Low-level
------------
2.1/ IMAP4rev1 - Internet Message Access Protocol - Version 4rev1
-----------------------------------------------------------------
Each command of the IMAP4rev1 Standard (RFC 2060) is implemented in
the IMAP4rev1 module. Directory imap/.
2.1.1/ References
- RFC 2060 - INTERNET MESSAGE ACCESS PROTOCOL - VERSION 4rev1
- draft-crispin-imapv-15.txt
Not yet implemented :
- draft-crispin-imapv-20.txt
2.1.2/ Dependencies
- tools/
2.1.3/ Files descriptions
description of header files :
mailimap.[ch] -- functions that implements each IMAP4rev1 command
mailimap_helper.[ch] -- helper interface for the previous functions
mailimap_types.[ch] -- definition of types and constructors for these
types
mailimap_types_helper.[ch] -- contains function definitions that will help
to create data necessary to use IMAP4rev1 module
mailimap_socket.[ch] -- provides a function to connect to an
IMAP4rev1 server over TCP
mailimap_ssl.[ch] -- provides a function to connect to an
IMAP4rev1 server over TLS layer
2.1.4/ Interface
Include for this module is mailimap.h and includes all other headers.
The interface of IMAP4rev1 is documented in the following files :
mailimap.h
mailimap_types.h
mailimap_types_helper.h
2.2/ POP3 - Post Office Protocol - Version 3
--------------------------------------------
Each command of the POP3 Standard (RFC 1939 and RFC 2449) is implemented
in the POP3 module. Directory pop3/.
2.1.1/ References
- RFC 1939 - Post Office Protocol - Version 3
- RFC 2449 - POP3 Extension Mechanism (CAPA)
Not yet implemented :
- RFC 1734 - POP3 AUTHentication command
2.1.2/ Dependencies
- tools/
2.2.3/ Files descriptions
mailpop3.[ch] -- functions that implements each POP3 command
mailpop3_helper.[ch] -- helper interface for the previous functions
mailpop3_socket.[ch] -- provides a function to connect to a
POP3 server over TCP
mailpop3_ssl.[ch] -- provides a function to connect to a
POP3 server over TLS layer
2.2.4/ Interface
Include for this module is mailpop3.h and includes all other headers.
There is not yet documentation for POP3 module.
2.3/ NNTP - Network News Transfer Protocol
------------------------------------------
Each command of the NNTP Standard (RFC 977 and RFC 2980) is implemented
in the NNTP module. Directory nntp/.
2.3.1/ References
- RFC 977 - Network News Transfer Protocol
- RFC 2980 - Common NNTP Extensions
Not yet implemented :
- RFC 1036 - Standard for Interchange of USENET Messages
- son of RFC 1036 : FTP://zoo.toronto.edu/pub/news.txt.Z
2.3.2/ Dependencies
- tools/
2.3.3/ Files descriptions
newsnntp.[ch] -- functions that implements each NNTP command
newsnntp_socket.[ch] -- provides a function to connect to a
NNTP server over TCP
newsnntp_ssl.[ch] -- provides a function to connect to a
POP3 server over TLS layer
2.3.4/ Interface
Include for this module is newsnntp.h and includes all other headers.
There is not yet documentation for NNTP module.
2.4/ mbox
---------
The mbox module provides a set of functions to manipulate mbox mailboxes.
These functions make a safe lock on the mailbox they work with.
This module will assign to each message a unique message identifier
so that we can work with message numbers in mbox files without other
programs interfer.
Directory mbox/.
2.4.1/ References
- http://wp.netscape.com/eng/mozilla/2.0/relnotes/demo/content-length.html
- http://www.qmail.org/qmail-manual-html/man5/mbox.html
2.4.2/ Dependencies
- tools/
- imf/
2.5.3/ Specific to libEtPan!
- "X-LibEtPan-UID" header
2.5.4/ Files descriptions
mailmbox.[ch] -- functions to manipulate mbox mailboxes.
mailmbox_parse.[ch] -- this module is in charge of parsing the
mbox file content
mailmbox_types.[ch] -- definition of types and constructors for these
types
2.4.5/ Interface
Include for this module is mailmbox.h and includes all other headers.
There is not yet documentation for mbox module.
2.5/ MH
-------
The MH module provides a set of functions to manipulate MH mailboxes.
Directory mh/.
2.5.1/ References
- almost none
2.5.2/ Dependencies
- tools/
2.5.3/ Files descriptions
mailmh.[ch] -- functions to manipulate MH mailboxes.
2.5.4/ Interface
Include for this module is mailmh.h.
There is not yet documentation for MH module.
2.6/ IMF - Internet Message Format
----------------------------------
The IMF module provides functions to parse data given in RFC 2822
format (Internet Message Format).
Directory imf/.
2.6.1/ References
- RFC 2822 - Internet Message Format (Not entirely implemented)
- RFC 2076 - Common Internet Message Headers
Not yet implemented :
- RFC 2298 - An Extensible Message Format
for Message Disposition Notifications
2.6.2/ Dependencies
- tools/
2.6.3/ Files descriptions
mailimf.[ch] -- functions to parse RFC 2822 messages.
mailimf_types.[ch] -- definition of types and constructors for these
types
mailimf_types_helper.[ch] -- contains function definitions that will help
to create data necessary to use IMF module.
mailimf_write.[ch] -- functions that output RFC 2822 messages or
sub-part of the messages in a (FILE *).
2.6.4/ Interface
Include for this module is mailimf.h and includes all other headers.
The interface of IMAP4rev1 is documented in the following files :
mailimf.h
mailimf_types.h
mailimf_types_helper.h
mailimf_write.h
2.7/ MIME - Multipurpose Internet Mail Extensions
-------------------------------------------------
The MIME module provides functions to parse structure of MIME messages.
Directory mime/.
2.7.1/ References
- RFC 2045 - Multipurpose Internet Mail Extensions (MIME) Part One: Format of
Internet Message Bodies.
- RFC 2047 - MIME (Multipurpose Internet Mail Extensions) Part Three: Message
Header Extensions for Non-ASCII Text.
- RFC 2183 - Communicating Presentation Information in Internet Messages:
The Content-Disposition Header Field
Not implemented :
- RFC 2046 - Multipurpose Internet Mail Extensions (MIME) Part Two: Media
Types.
2.7.2/ Dependencies
- tools/
- imf/
2.7.3/ Files descriptions
mailmime.[ch] -- functions to parse the MIME fields (RFC 2045).
mailmime_content.[ch] -- functions to parse the MIME message. You get
the different parts and you can decode them.
mailmime_decode.[ch] -- functions to parse the MIME-encoded fields.
mailmime_disposition.[ch] -- functions to parse the Content-Disposition field
(RFC 2183)
mailmime_types.[ch] -- definition of types and constructors for these
types
mailmime_types_helper.[ch] -- contains function definitions that will help
to create data necessary to use MIME module.
mailmime_write.[ch] -- functions that output MIME messages or
sub-part of the messages in a (FILE *).
2.7.4/ Interface
Include for this module is mailmime.h and includes all other headers.
There is not yet documentation for MIME module.
2.8/ SMTP - Simple Mail Transfer Protocol
-----------------------------------------
Each command of the SMTP Standard (RFC 2821 and RFC 1891) is implemented
in the SMTP module. Directory smtp/.
2.8.1/ References
- RFC 2821 - Simple Mail Transfer Protocol (Not entirely implemented)
- RFC 1891 - SMTP Service Extension for Delivery Status Notifications
2.8.2/ Depencencies
- tools/
2.8.3/ Files descriptions
mailsmtp.[ch] -- functions that implements each SMTP command
mailsmtp_helper.[ch] -- functions to get an easier use of SMTP module
mailsmtp_socket.[ch] -- provides a function to connect to a
SMTP server over TCP
mailsmtp_ssl.[ch] -- provides a function to connect to a
SMTP server over TLS layer
mailsmtp_types.h -- definition of types
2.8.4/ Interface
Include for this module is mailsmtp.h and includes all other headers.
There is not yet documentation for MIME module.
2.9/ Miscellaneous
2.9.1/ References
- RFC 2234 - Augmented BNF for Syntax Specifications: ABNF
- RFC 2595 - Using TLS with IMAP, POP3 and ACAP
2.9.2/ Tools
tools/ directory contains some tools functions and useful data structures.
alloc.h -- a wrapper on malloc()
carray.[ch] -- an array, that grows automatically when elements
are added.
charconv.[ch] -- character set converter. For example, it will
translate an iso-8859-1 string to an utf-8 string.
chash.[ch] -- a hash table which keys can be anything
cinthash.[ch] -- a hash table which keys are integers
(should be removed and replaced with chash)
clist.[ch] -- a double-linked list
connect.[ch] -- easy interface to connect a TCP server
hmac_md5.h
md5.[ch]
md5global.h -- MD5 calculation
mail.h -- some constants
maildb_helper.[ch] -- wrappers to DB 2.x 3.x or 4.x
maillock.[ch] -- safely lock a given file
mailstream.[ch] -- stream interface - buffered reading and writing
on files/socket/SSL connection
mailstream_helper.[ch] -- useful functions for stream
(for example: read a line)
mailstream_low.[ch] -- driver interface for a stream
mailstream_socket.[ch] -- stream driver for file descriptors (includes socket)
mailstream_ssl.[ch] -- stream driver for SSL connection
mailstream_types.h -- data structure definition
mapping.[ch] -- map parts of files in memory (no more used)
mmapstring.[ch] -- a string, that grows automatically when data
are added.
3/ Higher-level
---------------
The higher level will allow us to query folder informations or to get
messages information or content.
There is four kinds of identities :
- storage
- folders
- session
- messages
In the higher-level interface, you manipulate data types from IMF and
MIME module, plus additionnal data types of higher-level.
3.1/ Objects
------------
3.1.1/ Storage
A storage (struct mail_storage) represents whether a server or
a main path, It can be an IMAP server, the root path of a MH or a mbox file.
3.1.2/ Folders
A folder can be created from a storage.
Folders (struct mail_folder) are the mailboxes we can choose in the
server or as sub-folder of the main path.
Folders for IMAP are the IMAP mailboxes, for MH this is one of the
folder of the MH storage, for mbox, there is only one folder, the
mbox file content;
3.1.3/ Session
Storage and folders communicate with the lower-layer through the
mail session data structure.
A mail session (struct mailsession) is a mail access to a server
or a mail access in the local file system. It allow us to send commands
to the mail access.
A mail storage is using a mail session to communicate.
A folder folder also uses a mail session to get information or to send
information. It can be the same session or not, depdending of the
implementation.
3.1.4/ Messages
From a session, we can get a message (struct mailmessage) to read.
3.2/ Drivers
------------
For a mail access, three drivers exist.
One for storage, one for session, one for message.
Note that the folder access rely only on session driver.
3.2.1/ storage driver interface
mail_storage_driver is the driver structure for mail storage
- name is the name of the driver
- connect() connects the storage to the remote access or to
the path in the local filesystem.
- get_folder() can have two kinds of behaviour.
Either it creates a new session and independant from the session
used by the storage and select the given mailbox or
it selects the given mailbox in the current session.
It depends on the efficiency of the mail driver.
- free_data() frees the data created with mail_storage constructor.
a constructor for each kind of access has to be implemented.
3.2.2/ session driver interface
maildriver is the driver structure for mail sessions
- name is the name of the driver
- initialize() is the function that will initializes a data structure
specific to the driver, it returns a value that will be stored
in the field data of the session.
The field data of the session is the state of the session,
the internal data structure used by the driver.
It is called when creating the mailsession structure with
mailsession_new().
- uninitialize() frees the structure created with initialize()
- parameters() implements functions specific to the given mail access
- connect_stream() connects a stream to the session
- connect_path() notify a main path to the session
- starttls() changes the current stream to a TLS stream
- login() notifies the user and the password to authenticate to the
session
- logout() exits the session and closes the stream
- noop() does no operation on the session, but it can be
used to poll for the status of the connection.
- check_folder() makes a checkpoint of the session
- select_folder() selects a mailbox
- expunge_folder() deletes all messages marked \Deleted
- status_folder() queries the status of the folder
(number of messages, number of recent messages, number of
unseen messages)
- append_message() adds a RFC 2822 message to the current
given mailbox
- get_messages_list() returns the list of message numbers
of the current mailbox.
- get_envelopes_list() fills the parsed fields in the
mailmessage structures of the mail_envelopes_list.
- remove_message() removes the given message from the mailbox.
The message is permanently deleted.
- get_message returns a mailmessage structure that corresponds
to the given message number.
3.2.3/ message driver interface
mailmessage_driver is the driver structure to get information from messages.
- name is the name of the driver
- initialize() is the function that will initializes a data structure
specific to the driver, it returns a value that will be stored
in the field data of the mailsession.
The field data of the session is the state of the session,
the internal data structure used by the driver.
It is called when initializing the mailmessage structure with
mailmessage_init().
- uninitialize() frees the structure created with initialize().
It will be called by mailmessage_free().
- flush() will free from memory all temporary structures of the message
(for example, the MIME structure of the message).
- fetch_result_free() will free all strings resulted by fetch() or
any fetch_xxx() functions that returns a string.
- fetch() returns the content of the message (headers and text).
- fetch_header() returns the content of the headers.
- fetch_body() returns the message text (message content without headers)
- fetch_size() returns the size of the message content.
- get_bodystructure() returns the MIME structure of the message.
- fetch_section() returns the content of a given MIME part
- fetch_section_header() returns the header of the message
contained by the given MIME part.
- fetch_section_mime() returns the MIME headers of the
given MIME part.
- fetch_section_body() returns the text (if this is a message, this is the
message content without headers) of the given MIME part.
- fetch_envelope() returns a mailimf_fields structure, with a list of
fields chosen by the driver.
- get_flags() returns a the flags related to the message.
When you want to get flags of a message, you have to make sure to
call get_flags() at least once before using directly message->flags.
3.3/ Higher level interface
---------------------------
3.3.1/ Files descriptions
generic_cache.[ch] -- functions that implements cache and
flags storing mechanism
imapdriver.[ch] -- IMAP driver for session
imapdriver_cached.[ch] -- IMAP driver for session, using cache,
IMAP already has flags.
imapdriver_cached_message.[ch] -- IMAP driver for message, using cache
IMAP already has flags.
imapdriver_message.[ch] -- IMAP driver for message
imapdriver_types.[ch] -- tools function for IMAP driver (types
conversion from IMAP module).
imapstorage.[ch] -- IMAP driver for storage
imfcache.[ch] -- implements cache for parsed fields
libetpan.h -- includes all necessary header files to
use libEtPan!
maildriver.[ch] -- wrappers to calls to the session driver
maildriver_tools.[ch] -- default implementation for drivers,
when the driver does not parse the
messages.
maildriver_types.[ch] -- data types declaration and constructors
maildriver_types_helper.[ch] -- easy data creation
mailmessage.[ch] -- wrappers to calls to the message driver
mailstorage.[ch] -- storage creation, calls to the storage
driver and implementation of folders.
mailstorage_tools.[ch] -- tools for storage (connection)
mailthread.[ch] -- threading: collection of the mails
into a treee
mboxdriver.[ch] -- mbox driver for session
mboxdriver_cached.[ch] -- mbox driver for session, using flags
and cache
mboxdriver_cached_message.[ch] -- mbox driver for message, using flags
and cache
mboxdriver_message.[ch] -- mbox driver for message
mboxdriver_tools.[ch] -- mbox driver common functions
mboxstorage.[ch] -- mbox driver for storage
mhdriver.[ch] -- MH driver for session
mhdriver_cached.[ch] -- MH driver for session, using flags
and cache
mhdriver_cached_message.[ch] -- MH driver for message, using flags
and cache.
mhdriver_message.[ch] -- MH driver for message
mhdriver_tools.[ch] -- MH driver common functions
mhstorage.[ch] -- MH driver for storage
nntpdriver.[ch] -- NNTP driver for session
nntpdriver_cached.[ch] -- NNTP driver for session, using flags
and cache
nntpdriver_cached_message.[ch] -- NNTP driver for message, using flags
and cache
nntpdriver_message.[ch] -- NNTP driver for message
nntpdriver_tools.[ch] -- NNTP driver common functions
nntpstorage.[ch] -- NNTP driver for storage
pop3driver.[ch] -- POP3 driver for session
pop3driver_cached.[ch] -- POP3 driver for session, using flags
and cache
pop3driver_cached_message.[ch] -- POP3 driver for message, using flags
and cache
pop3driver_message.[ch] -- POP3 driver for message
pop3driver_tools.[ch] -- POP3 driver common functions
pop3storage.[ch] -- POP3 driver for storage
3.3.2/ Interfaces
Include for this module is libetpan.h and includes all other headers.
The interface of higher layer is documented in the following files :
maildriver.h
maildriver_types.h
maildriver_types_helper.h
mailmessage.h
mailstorage.h
mailstorage_types.[h]
mailthread.h
4/ Architecture
---------------
(see layer.fig)
5/ Example of use
-----------------
You can find some example in tests/
6/ Constraints
--------------
- libEtPan! must run on a system where mmap() is available.
- for mbox particularly, libEtPan! make assumption on the fact that a
file can be entirely mapped into memory. But if you don't read
mailboxes of 1 Go, it should be fine.
|