File: maildirlist.c

package info (click to toggle)
courier 0.60.0-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 52,288 kB
  • ctags: 12,677
  • sloc: ansic: 165,348; cpp: 24,820; sh: 16,410; perl: 6,839; makefile: 3,621; yacc: 289; sed: 16
file content (82 lines) | stat: -rw-r--r-- 1,385 bytes parent folder | download | duplicates (25)
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
/*
** Copyright 2002 Double Precision, Inc.
** See COPYING for distribution information.
*/

#if HAVE_CONFIG_H
#include "config.h"
#endif

#include <sys/types.h>
#if HAVE_DIRENT_H
#include <dirent.h>
#define NAMLEN(dirent) strlen((dirent)->d_name)
#else
#define dirent direct
#define NAMLEN(dirent) (dirent)->d_namlen
#if HAVE_SYS_NDIR_H
#include <sys/ndir.h>
#endif
#if HAVE_SYS_DIR_H
#include <sys/dir.h>
#endif
#if HAVE_NDIR_H
#include <ndir.h>
#endif
#endif
#include	<sys/types.h>
#include	<sys/stat.h>
#include	<string.h>
#include	<stdlib.h>
#include	<time.h>
#if	HAVE_UNISTD_H
#include	<unistd.h>
#endif
#include	<stdio.h>
#include	<ctype.h>
#include	<errno.h>
#include	<fcntl.h>

#include	"maildirmisc.h"

void maildir_list(const char *maildir,
		  void (*func)(const char *, void *),
		  void *voidp)
{
	DIR *dirp=opendir(maildir);
	struct dirent *de;

	while (dirp && (de=readdir(dirp)) != NULL)
	{
		char *p;

		if (strcmp(de->d_name, "..") == 0)
			continue;

		if (de->d_name[0] != '.')
			continue;

		if ((p=malloc(strlen(maildir) + strlen(de->d_name)+20))
		    == NULL)
			continue;

		strcat(strcat(strcat(strcpy(p, maildir), "/"), de->d_name),
		       "/cur/.");

		if (access(p, X_OK))
		{
			free(p);
			continue;
		}

		strcpy(p, INBOX);

		if (strcmp(de->d_name, "."))
			strcat(p, de->d_name);

		(*func)(p, voidp);
		free(p);
	}
	if (dirp)
		closedir(dirp);
}