summaryrefslogtreecommitdiffstats
path: root/imap/capability.c
blob: 2a83bb8b86da0b3d7385ce5ea1d0f9163db28521 (plain)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
** Copyright 1998 - 2008 Double Precision, Inc.
** See COPYING for distribution information.
*/

#if	HAVE_CONFIG_H
#include	"config.h"
#endif
#include	<stdio.h>
#include	<stdlib.h>
#include	<string.h>
#if	HAVE_UNISTD_H
#include	<unistd.h>
#endif
#include	"imapwrite.h"


static int capa_keywords=0;

extern const char *externalauth();

void initcapability()
{
	const char *p=getenv("IMAP_KEYWORDS");

	if (p) capa_keywords=atoi(p);
}

int have_starttls()
{
const char *p;

	if ((p=getenv("IMAP_STARTTLS")) == 0)	return (0);
	if (*p != 'y' && *p != 'Y')		return (0);

	p=getenv("COURIERTLS");
	if (!p || !*p)	return (0);
	if (access(p, X_OK))	return (0);
	return (1);
}


int tlsrequired()
{
const char *p=getenv("IMAP_TLS_REQUIRED");

	if (p && atoi(p))       return (1);
	return (0);
}

int keywords()
{
	return capa_keywords != 0;
}

int fastkeywords()
{
	return capa_keywords == 1;
}

int magictrash()
{
	const char *p;

	p=getenv("IMAP_MOVE_EXPUNGE_TO_TRASH");

	if (p && atoi(p))
		return 1;
	return 0;
}

const char *imap_externalauth()
{
	const char *p;

	if ((p=getenv("IMAP_TLS")) && atoi(p))
		return externalauth();

	return NULL;
}


void imapcapability()
{
	const char *p;

	if ((p=getenv("IMAP_TLS")) && atoi(p) &&
	    (p=getenv("IMAP_CAPABILITY_TLS")) && *p)
		writes(p);
	else if ((p=getenv("IMAP_CAPABILITY")) != 0 && *p)
		writes(p);
	else
		writes("IMAP4rev1");

#if SMAP
	p=getenv("SMAP_CAPABILITY");

	if (p && *p)
	{
		writes(" ");
		writes(p);

		if (keywords())
			writes(" KEYWORDS");
	}
#endif

	if ((p=getenv("IMAP_ACL")) && atoi(p))
		writes(" ACL ACL2=UNION");

	if (getenv("IMAP_ID_FIELDS"))
		writes(" ID");

	if (have_starttls())
	{
		writes(" STARTTLS");
		if (tlsrequired())
			writes(" LOGINDISABLED");
	}
	else
	{
		if (imap_externalauth())
			writes(" AUTH=EXTERNAL");
	}


	p=getenv("OUTBOX");

	if (p && *p)
	{
		writes(" XCOURIEROUTBOX=INBOX");
		writes(p);
	}

	if (magictrash())
		writes(" XMAGICTRASH");

	writes(" ENABLE UTF8=ACCEPT");
}