#ifndef _MESSAGE_H_5d27aba9_ #define _MESSAGE_H_5d27aba9_ #include struct mm_message; typedef struct mm_message MESSAGE; /* Wait flags for message_lock() */ #define MSG_WAIT 0x00000001 #define MSG_NOWAIT 0x00000002 #define MSG_SHARED 0x00000004 #define MSG_EXCLUSIVE 0x00000008 #include "folder.h" /* Returns the filesystem pathname of a message's file. */ extern const char *message_path(MESSAGE *); /* Returns the FILE * for an open message. */ extern FILE *message_fp(MESSAGE *); /* Creates and returns a MESSAGE for the given folder and message number. The message is neither opened nor locked. */ extern MESSAGE *message_make(FOLDER *, int); /* Locks a message, waiting or not according as MSG_WAIT or MSG_NOWAIT is specified, for shared or exclusive access as MSG_SHARED or MSG_EXCLUSIVE is specified. */ extern int message_lock(MESSAGE *, unsigned int); /* Unlocks a message. "Cannot fail". If the message is not locked, nop. */ extern void message_unlock(MESSAGE *); /* Closes a message. "Cannot fail". If the message is not open, nop. */ extern void message_close(MESSAGE *); /* Frees a message. "Cannot fail". If the message is locked, unlocks it; if it's open, closes it. The argument becomes invalid. */ extern void message_free(MESSAGE *); /* Opens the message. Returns syscall-style return status. Second and third arguments are as for open(2). */ extern int message_open(MESSAGE *, int, int); /* Returns a message's number within its folder. */ extern int message_number(MESSAGE *); /* Returns a message's folder. */ extern FOLDER *message_folder(MESSAGE *); /* Returns the contents of one of a message's headers. If the message has multiple headers with the same name, one of them will be picked, but which one it will be is unspecified. The first time this routine is called on a given message, it reads the headers; the message's fd's seek pointer will be moved (and left pointing somewhere near the beginning of the body). The message must be open and locked. */ extern const char *message_header_val(MESSAGE *, const char *); /* Iterates over the message's headers, calling (*fn) for each one. Calls are made in the order the headers appear in the message. If (*fn) returns nonzero for any call, that nonzero value is immediately returned from message_header_scan; if all (*fn) calls return zero, message_header_scan returns zero after scanning the entire header. Remarks similar to those for message_header_val about the message seek pointer apply. Second arg to (*fn) is header name, third is header value, fourth is last arg to message_header_scan. The message must be open and locked. */ extern int message_header_scan(MESSAGE *, int (*)(MESSAGE *, const char *, const char *, void *), void *); /* Reads the next body line, starting wherever the seek pointer is. Returned value is malloc()ed and must be freed. The message must be open and locked. At end of body, returns nil. */ extern char *message_body_line(MESSAGE *); /* Seeks to the beginning of the body. The message must be open and locked. */ extern void message_body_begin(MESSAGE *); /* Returns the message's From_ line, or 0 if none. Return value is owned by message.c and is not to be freed by the caller. */ extern const char *message_unix_from(MESSAGE *); #endif