aboutsummaryrefslogtreecommitdiff
path: root/src/imap/ngx_imap_handler.c
blob: 61c59c98da1787ba9a5b860de93180f6b41703be (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
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_event.h>
#include <ngx_imap.h>
#include <nginx.h>


static void ngx_imap_auth_state(ngx_event_t *rev);


static char pop3_greeting[] = "+OK " NGINX_VER " ready" CRLF;
static char imap_greeting[] = "* OK " NGINX_VER " ready" CRLF;


void ngx_imap_init_connection(ngx_connection_t *c)
{
    ngx_int_t  n;

    ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0,
                   "imap init connection");

    c->log_error = NGX_ERROR_INFO;

    n = ngx_send(c, pop3_greeting, sizeof(pop3_greeting) - 1);

    if (n == NGX_ERROR) {
        ngx_imap_close_connection(c);
        return;
    }

    c->read->event_handler = ngx_imap_auth_state;

    if (ngx_handle_read_event(c->read, 0) == NGX_ERROR) {
        ngx_imap_close_connection(c);
        return;
    }
}


static void ngx_imap_auth_state(ngx_event_t *rev)
{
    ngx_connection_t  *c;

    c = rev->data;

    ngx_imap_close_connection(c);
}


void ngx_imap_close_connection(ngx_connection_t *c)
{
    ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0,
                   "close imap connection: %d", c->fd);

    ngx_close_connection(c);
}