summaryrefslogtreecommitdiff
path: root/mailbox/pop/folder.c
blob: 673fac8b9244f2bc23adcc3f50c1ab458ac1971b (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
140
141
/* GNU Mailutils -- a suite of utilities for electronic mail
   Copyright (C) 1999, 2000, 2001, 2003, 2005 Free Software Foundation, Inc.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General
   Public License along with this library; if not, write to the
   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301 USA */

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#ifdef ENABLE_POP

#include <errno.h>
#include <stdlib.h>
#include <string.h>

#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif

#include <mailutils/auth.h>
#include <mailutils/errno.h>
#include <mailutils/mailbox.h>

#include <folder0.h>
#include <registrar0.h>
#include <url0.h>

/* We export url parsing and the initialisation of
   the mailbox, via the register entry/record.  */

static struct _record _pop_record =
{
  MU_POP_PRIO,
  MU_POP_SCHEME,
  _url_pop_init, /* Url init.  */
  _mailbox_pop_init, /* Mailbox init.  */
  NULL, /* Mailer init.  */
  _folder_pop_init, /* Folder init.  */
  NULL, /* No need for an back pointer.  */
  NULL, /* _is_scheme method.  */
  NULL, /* _get_url method.  */
  NULL, /* _get_mailbox method.  */
  NULL, /* _get_mailer method.  */
  NULL  /* _get_folder method.  */
};
record_t pop_record = &_pop_record;

static int folder_pop_open  (folder_t, int);
static int folder_pop_close (folder_t);
static int folder_pop_get_authority (folder_t, authority_t *);
extern int _pop_user         (authority_t);
extern int _pop_apop         (authority_t);

/* XXX: The way, the POP folder is handled is not clean at all.
   the I/O functions should have been here on folder, not in  mbx_pop.c  */
int
_folder_pop_init (folder_t folder)
{
  int status;

  /* Set the authority early:
     (1) so we can check for errors.
     (2) allow the client to get the authority for setting the ticket
     before the open.  */
  status = folder_pop_get_authority (folder, NULL);
  if (status != 0)
    return status;

  folder->_open = folder_pop_open;
  folder->_close = folder_pop_close;
  return 0;
}

static int
folder_pop_open (folder_t folder, int flags)
{
  mailbox_t mbox = folder->data;
  return mailbox_open (mbox, flags);
}

static int
folder_pop_close (folder_t folder)
{
  mailbox_t mbox = folder->data;
  return mailbox_close (mbox);
}

static int
folder_pop_get_authority (folder_t folder, authority_t *pauth)
{
  int status = 0;
  if (folder->authority == NULL)
    {
      /* assert (folder->url); */
      if (folder->url == NULL)
	return EINVAL;

      if (folder->url->auth == NULL
	  || strcasecmp (folder->url->auth, "*") == 0)
	{
	  status = authority_create (&folder->authority, NULL, folder);
	  authority_set_authenticate (folder->authority, _pop_user, folder);
	}
      /*
	"+apop" could be supported.
	Anything else starting with "+" is an extension mechanism.
	Without a "+" it's a SASL mechanism.
      */
      else if (strcasecmp (folder->url->auth, "+APOP") == 0)
	{
	  status = authority_create (&folder->authority, NULL, folder);
	  authority_set_authenticate (folder->authority, _pop_apop, folder);
	}
      else
	{
	  status = MU_ERR_BAD_AUTH_SCHEME;
	}
    }
  if (pauth)
    *pauth = folder->authority;
  return status;
}

#else
#include <stdio.h>
#include <registrar0.h>
record_t pop_record = NULL;
#endif

Return to:

Send suggestions and report system problems to the System administrator.