File: m_maildir.c

package info (click to toggle)
nmh 1.3-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 4,056 kB
  • ctags: 4,531
  • sloc: ansic: 50,788; sh: 3,141; makefile: 965; awk: 74
file content (98 lines) | stat: -rw-r--r-- 1,910 bytes parent folder | download | duplicates (4)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98

/*
 * m_maildir.c -- get the path for the mail directory
 *
 * $Id: m_maildir.c,v 1.2 2002/07/02 22:09:14 kenh Exp $
 *
 * This code is Copyright (c) 2002, by the authors of nmh.  See the
 * COPYRIGHT file in the root directory of the nmh distribution for
 * complete copyright information.
 */

#include <h/mh.h>

#define	CWD	"./"
#define	NCWD	(sizeof(CWD) - 1)
#define	DOT	"."
#define	DOTDOT	".."
#define	PWD	"../"
#define	NPWD	(sizeof(PWD) - 1)

static char mailfold[BUFSIZ];

/*
 * static prototypes
 */
static char *exmaildir (char *);


char *
m_maildir (char *folder)
{
    register char *cp, *ep;

    if ((cp = exmaildir (folder))
	    && (ep = cp + strlen (cp) - 1) > cp
	    && *ep == '/')
	*ep = '\0';

    return cp;
}


char *
m_mailpath (char *folder)
{
    register char *cp;
    char maildir[BUFSIZ];

    if (*folder != '/'
	    && strncmp (folder, CWD, NCWD)
	    && strcmp (folder, DOT)
	    && strcmp (folder, DOTDOT)
	    && strncmp (folder, PWD, NPWD)) {
	strncpy (maildir, mailfold, sizeof(maildir));	/* preserve... */
	cp = getcpy (m_maildir (folder));
	strncpy (mailfold, maildir, sizeof(mailfold));
    } else {
	cp = path (folder, TFOLDER);
    }

    return cp;
}


static char *
exmaildir (char *folder)
{
    register char *cp, *pp;

    /* use current folder if none is specified */
    if (folder == NULL)
	folder = getfolder(1);

    if (!(*folder != '/'
	    && strncmp (folder, CWD, NCWD)
	    && strcmp (folder, DOT)
	    && strcmp (folder, DOTDOT)
	    && strncmp (folder, PWD, NPWD))) {
	strncpy (mailfold, folder, sizeof(mailfold));
	return mailfold;
    }

    cp = mailfold;
    if ((pp = context_find ("path")) && *pp) {
	if (*pp != '/') {
	    sprintf (cp, "%s/", mypath);
	    cp += strlen (cp);
	}
	cp = copy (pp, cp);
    } else {
	cp = copy (path ("./", TFOLDER), cp);
    }
    if (cp[-1] != '/')
	*cp++ = '/';
    strcpy (cp, folder);

    return mailfold;
}