maildir-filename.c revision 538303a216166f3526c0ae9658c9978275cfa100
/* Copyright (C) 2002-2007 Timo Sirainen */
#include "lib.h"
#include "ioloop.h"
#include "array.h"
#include "str.h"
#include "hostpid.h"
#include "maildir-storage.h"
#include "maildir-keywords.h"
#include "maildir-filename.h"
#include <stdlib.h>
const char *maildir_filename_generate(void)
{
/* use secs + usecs to guarantee uniqueness within this process. */
tv = ioloop_timeval;
else {
}
}
return t_strdup_printf("%s.M%sP%s.%s",
}
{
const char *info;
*flags_r = 0;
return;
switch (*info) {
case 'R': /* replied */
*flags_r |= MAIL_ANSWERED;
break;
case 'S': /* seen */
break;
case 'T': /* trashed */
*flags_r |= MAIL_DELETED;
break;
case 'D': /* draft */
*flags_r |= MAIL_DRAFT;
break;
case 'F': /* flagged */
*flags_r |= MAIL_FLAGGED;
break;
default:
if (*info >= MAILDIR_KEYWORD_FIRST &&
*info <= MAILDIR_KEYWORD_LAST) {
int idx;
if (idx < 0) {
/* unknown keyword. */
break;
}
(unsigned int *)&idx, 1);
break;
}
/* unknown flag - ignore */
break;
}
}
}
{
}
static void
{
const unsigned int *indexes;
char chr;
for (i = 0; i < count; i++) {
if (chr != '\0')
}
}
{
enum mail_flags flags_left;
int nextflag;
/* remove the old :info from file name, and get the old flags */
oldflags = "";
}
/* insert the new flags between old flags. flags must be sorted by
their ASCII code. unknown flags are kept. */
flags_left = flags;
for (;;) {
/* skip all known flags */
*oldflags == 'T' ||
(*oldflags >= MAILDIR_KEYWORD_FIRST &&
*oldflags <= MAILDIR_KEYWORD_LAST))
oldflags++;
256 : (unsigned char) *oldflags;
flags_left &= ~MAIL_DRAFT;
}
flags_left &= ~MAIL_FLAGGED;
}
flags_left &= ~MAIL_ANSWERED;
}
flags_left &= ~MAIL_SEEN;
}
flags_left &= ~MAIL_DELETED;
}
}
break;
oldflags++;
}
if (*oldflags == MAILDIR_FLAGS_SEP) {
/* another flagset, we don't know about these, just keep them */
while (*oldflags != '\0')
}
}
{
fname += 3;
break;
}
}
if (*fname == '\0')
return FALSE;
fname++;
}
if (*fname != MAILDIR_INFO_SEP &&
*fname != MAILDIR_EXTRA_SEP &&
*fname != '\0')
return FALSE;
return TRUE;
}
/* a char* hash function from ASU -- from glib */
unsigned int maildir_filename_base_hash(const void *p)
{
const unsigned char *s = p;
unsigned int g, h = 0;
while (*s != MAILDIR_INFO_SEP && *s != '\0') {
i_assert(*s != '/');
h = (h << 4) + *s;
if ((g = h & 0xf0000000UL)) {
h = h ^ (g >> 24);
h = h ^ g;
}
s++;
}
return h;
}
{
}
return 0;
}
{
int usecs = 0;
/* Assume we already read the timestamp. Next up is
".<uniqueness>.<host>". Find usecs inside the uniqueness. */
if (*fname != '.')
return FALSE;
fname++;
if (*fname++ == 'M') {
fname++;
}
return TRUE;
}
}
return FALSE;
}
{
/* sort primarily by the timestamp in file name */
if (ret == 0) {
/* sort secondarily by microseconds, if they exist */
if (ret == 0) {
/* fallback to comparing the base file name */
}
}
return ret;
}