mbox-index.c revision c04cafc1cdd093afcb32e313bcefbc9bb8972d9e
/* Copyright (C) 2002 Timo Sirainen */
#include "lib.h"
#include "ibuffer.h"
#include "rfc822-tokenize.h"
#include "mbox-index.h"
#include "mbox-lock.h"
#include "mail-index-util.h"
#include "mail-index-data.h"
#include "mail-custom-flags.h"
#include <unistd.h>
#include <fcntl.h>
extern MailIndex mbox_index;
{
return FALSE;
}
{
int fd;
if (fd == -1) {
return FALSE;
}
return FALSE;
}
return TRUE;
}
{
switch (lock_type) {
case MAIL_LOCK_SHARED:
case MAIL_LOCK_EXCLUSIVE:
/* don't drop exclusive lock, it may be there for a reason */
return NULL;
}
break;
default:
if (!mbox_file_open(index))
return NULL;
}
break;
}
index->mbox_inbuf =
MAIL_MMAP_BLOCK_SIZE, 0, 0, FALSE);
}
return index->mbox_inbuf;
}
{
}
}
{
}
}
{
}
{
}
{
size_t i;
flags = 0;
for (i = 0; i < len; i++) {
switch (value[i]) {
case 'A':
flags |= MAIL_ANSWERED;
break;
case 'F':
flags |= MAIL_FLAGGED;
break;
case 'D':
flags |= MAIL_DRAFT;
break;
case 'R':
break;
case 'T':
flags |= MAIL_DELETED;
break;
}
}
return flags;
}
{
if (index >= 0)
}
static MailFlags
const char *custom_flags[MAIL_CUSTOM_FLAGS_COUNT])
{
flags = 0;
return flags;
}
{
const char **custom_flags, **old_flags;
/* skip <uid validity> and <last uid> fields */
spaces = 0;
if (++spaces == 2)
break;
}
}
return TRUE;
t_push();
/* we're at the 3rd field now, which begins the list of custom flags */
/* need more memory */
max *= 2;
sizeof(const char *) * idx);
}
custom_flags[idx++] =
}
break;
}
}
custom_flags, idx);
t_pop();
return ret > 0;
}
void *context)
{
size_t i;
/* Pretty much copy&pasted from popa3d by Solar Designer */
switch (*name) {
case '\0':
/* End of headers */
if (!ctx->set_read_limit)
break;
/* a) use Content-Length, b) search for "From "-line */
if (ctx->content_length == 0 ||
if (ctx->content_length != 0)
}
break;
case 'R':
case 'r':
}
break;
case 'C':
case 'c':
/* manual parsing, so we can deal with uoff_t */
ctx->content_length = 0;
for (i = 0; i < value_len; i++) {
/* invalid */
ctx->content_length = 0;
break;
}
(value[i] - '0');
}
}
break;
case 'D':
case 'd':
if (name_len == 12)
else if (name_len == 4) {
/* Received-header contains date too,
and more trusted one */
}
break;
case 'M':
case 'm':
if (name_len == 10) {
/* Received-header contains unique ID too,
and more trusted one */
}
break;
case 'S':
case 's':
/* update message flags */
}
break;
case 'X':
case 'x':
if (name_len == 13) {
/* Let the local delivery agent help generate unique
ID's but don't blindly trust this header alone as
it could just as easily come from the remote. */
} else if (name_len == 8 &&
/* update message flags */
} else if (name_len == 10 &&
/* update custom message flags */
ctx->custom_flags);
} else if (name_len == 10 &&
/* update list of custom message flags */
}
break;
}
if (fixed)
}
const char *custom_flags[MAIL_CUSTOM_FLAGS_COUNT],
void *context)
{
int i;
/* the value is often empty, so check that first */
value++;
len--;
}
if (len == 0)
return;
for (i = 0; i < MAIL_CUSTOM_FLAGS_COUNT; i++) {
strlen(custom_flags[i]) : 0;
}
for (;;) {
/* skip whitespace */
value++;
len--;
}
if (len == 0)
break;
/* find the length of the item */
break;
}
/* check if it's found */
for (i = 0; i < MAIL_CUSTOM_FLAGS_COUNT; i++) {
if (custom_len[i] == item_len &&
break;
}
if (i == MAIL_CUSTOM_FLAGS_COUNT)
i = -1;
}
}
{
const unsigned char *data;
pos = 0;
if (pos == 0) {
if (data[0] == '\n') {
return TRUE;
}
if (data[0] != '\r')
return FALSE;
pos++;
}
return FALSE;
return TRUE;
}
}
/* end of file */
return TRUE;
}
{
const unsigned char *data;
/* skip empty lines at beginning */
for (i = 0; i < size; i++) {
break;
}
i_buffer_skip(inbuf, i);
if (i < size)
break;
}
}
{
const unsigned char *msg;
i = startpos;
for (; i < size; i++) {
if (msg[i] == '\n') {
i -= startpos;
return mbox_from_parse_date((const char *) msg,
}
}
}
return FALSE;
}
{
const unsigned char *msg;
/* read until "[\r]\nFrom " is found. assume '\n' at beginning of
buffer */
state = '\n';
new_state = 0;
switch (state) {
case '\n':
if (msg[i] == 'F')
new_state = 'F';
else if (header) {
if (msg[i] == '\n') {
/* \n\n */
return;
}
if (msg[i] == '\r')
new_state = '\r';
}
break;
case '\r':
if (msg[i] == '\n') {
/* \n\r\n */
return;
}
break;
case 'F':
if (msg[i] == 'r')
new_state = 'r';
break;
case 'r':
if (msg[i] == 'o')
new_state = 'o';
break;
case 'o':
if (msg[i] == 'm')
new_state = 'm';
break;
case 'm':
if (msg[i] == ' ') {
/* Go back "From" */
i -= 4;
/* Go back \n, unless we're at
beginning of buffer */
if (i > 0)
i--;
/* Go back \r if it's there */
i--;
i_buffer_skip(inbuf, i);
return;
}
}
break;
}
state = '\n';
else
}
/* Leave enough space to go back "\r\nFrom" */
i -= startpos;
i_buffer_skip(inbuf, i);
}
/* end of file, leave the last [\r]\n */
startpos--;
startpos--;
}
}
{
}
{
}
{
const unsigned char *data;
/* missing data */
return FALSE;
}
/* end of file. a bit unexpected though,
since \n is missing. */
return TRUE;
}
/* read forward a bit */
return FALSE;
/* either there should be the next From-line,
or [\r]\n at end of file */
}
if (size > 0) {
if (data[0] != '\n')
return FALSE;
}
return size == 0 ||
}
{
"Missing location field for record %u",
return FALSE;
"Invalid location field for record %u",
return FALSE;
}
}
return FALSE;
}
return FALSE;
}
return FALSE;
}
}
return TRUE;
}
{
int len;
}
{
}
int external_change)
{
return FALSE;
if (!external_change) {
}
return TRUE;
}
MailIndex mbox_index = {
};