-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpop3.c
50 lines (44 loc) · 1016 Bytes
/
pop3.c
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
// SPDX-License-Identifier: GPL-3.0-or-later
/*
* Copyright (C) 2019-2022 Junjiro R. Okajima
*/
#include <errno.h>
#include <stddef.h>
#include <stdio.h>
#include "xoauth2.h"
int xoauth2_pop3(char *buf, unsigned int *status)
{
int err, n;
/*
* USER user
* PASS password
*/
err = 0;
n = sscanf(buf, " %s %s ", g.cmd, g.user);
if (n != 2)
goto out;
if (!strncasecmp(g.cmd, "USER", 4)) {
if (!strchr(g.user, '@'))
strcat(g.user, "@gmail.com");
err = gmail_xoauth2(&g.arg, g.res, sizeof(g.res));
if (err)
goto out;
/* +OK Welcome. */
if (*g.res != '+')
goto out;
*status = XOAUTH2_SKIP | XOAUTH2_PASSED;
printf("+OK Accepted via %s.\r\n",
program_invocation_short_name);
fflush(stdout);
} else if (!strncasecmp(g.cmd, "PASS", 4)) {
/* ignore the command */
*status |= XOAUTH2_SKIP;
if (*status & XOAUTH2_PASSED)
*status |= XOAUTH2_DONE;
printf("+OK Ignored by %s.\r\n",
program_invocation_short_name);
fflush(stdout);
}
out:
return err;
}