f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen#ifndef MESSAGE_PART_H
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen#define MESSAGE_PART_H
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen#include "message-size.h"
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen
c59d22d58cd0bbeeac4622b99088a1cb7d2fde20Stephan Boschstruct message_part_data;
c59d22d58cd0bbeeac4622b99088a1cb7d2fde20Stephan Bosch
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen/* Note that these flags are used directly by message-parser-serialize, so
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen existing flags can't be changed without breaking backwards compatibility */
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainenenum message_part_flags {
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen MESSAGE_PART_FLAG_MULTIPART = 0x01,
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen MESSAGE_PART_FLAG_MULTIPART_DIGEST = 0x02,
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen MESSAGE_PART_FLAG_MESSAGE_RFC822 = 0x04,
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen /* content-type: text/... */
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen MESSAGE_PART_FLAG_TEXT = 0x08,
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen MESSAGE_PART_FLAG_UNUSED = 0x10,
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen /* message part header or body contains NULs */
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen MESSAGE_PART_FLAG_HAS_NULS = 0x20,
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen /* Mime-Version header exists. */
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen MESSAGE_PART_FLAG_IS_MIME = 0x40
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen};
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainenstruct message_part {
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen struct message_part *parent;
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen struct message_part *next;
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen struct message_part *children;
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen uoff_t physical_pos; /* absolute position from beginning of message */
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen struct message_size header_size;
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen struct message_size body_size;
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen
c59d22d58cd0bbeeac4622b99088a1cb7d2fde20Stephan Bosch struct message_part_data *data;
c59d22d58cd0bbeeac4622b99088a1cb7d2fde20Stephan Bosch
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen /* total number of message_parts under children */
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen unsigned int children_count;
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen enum message_part_flags flags;
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen void *context;
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen};
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen/* Return index number for the message part. The indexes are in the same order
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen as they exist in the flat RFC822 message. The root part is 0, its first
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen child is 1 and so on. */
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainenunsigned int message_part_to_idx(const struct message_part *part);
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen/* Find message part by its index number, or return NULL if the index
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen doesn't exist. */
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainenstruct message_part *
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainenmessage_part_by_idx(struct message_part *parts, unsigned int idx);
6b8d5b8d02bd888609f06366ffb5a5a1e6e7d251Timo Sirainen
f684e87d4e2d192efdf5984d18fcede3f5a33771Timo Sirainen#endif