2004-09-01 03:05:39 +08:00
|
|
|
|
|
|
|
#include <ngx_config.h>
|
|
|
|
#include <ngx_core.h>
|
|
|
|
#include <ngx_event.h>
|
2004-09-07 23:29:22 +08:00
|
|
|
#include <ngx_imap.h>
|
|
|
|
#include <nginx.h>
|
|
|
|
|
|
|
|
|
2004-09-09 23:40:48 +08:00
|
|
|
static void ngx_imap_init_session(ngx_event_t *rev);
|
2004-09-07 23:29:22 +08:00
|
|
|
|
|
|
|
|
|
|
|
static char pop3_greeting[] = "+OK " NGINX_VER " ready" CRLF;
|
|
|
|
static char imap_greeting[] = "* OK " NGINX_VER " ready" CRLF;
|
2004-09-01 03:05:39 +08:00
|
|
|
|
|
|
|
|
2004-09-06 03:54:02 +08:00
|
|
|
void ngx_imap_init_connection(ngx_connection_t *c)
|
2004-09-01 03:05:39 +08:00
|
|
|
{
|
2004-09-09 23:40:48 +08:00
|
|
|
char *greeting;
|
|
|
|
ssize_t size;
|
|
|
|
ngx_int_t n;
|
2004-09-07 23:29:22 +08:00
|
|
|
|
2004-09-01 03:05:39 +08:00
|
|
|
ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0,
|
2004-09-06 03:54:02 +08:00
|
|
|
"imap init connection");
|
2004-09-01 03:05:39 +08:00
|
|
|
|
2004-09-07 23:29:22 +08:00
|
|
|
c->log_error = NGX_ERROR_INFO;
|
2004-09-01 03:05:39 +08:00
|
|
|
|
2004-09-09 23:40:48 +08:00
|
|
|
greeting = pop3_greeting;
|
|
|
|
size = sizeof(pop3_greeting) - 1;
|
2004-09-01 03:05:39 +08:00
|
|
|
|
2004-09-09 23:40:48 +08:00
|
|
|
n = ngx_send(c, greeting, size);
|
|
|
|
|
|
|
|
if (n < size) {
|
|
|
|
/*
|
|
|
|
* we treat the incomplete sending as NGX_ERROR
|
|
|
|
* because it is very strange here
|
|
|
|
*/
|
2004-09-07 23:29:22 +08:00
|
|
|
ngx_imap_close_connection(c);
|
|
|
|
return;
|
2004-09-01 03:05:39 +08:00
|
|
|
}
|
2004-09-07 23:29:22 +08:00
|
|
|
|
2004-09-09 23:40:48 +08:00
|
|
|
c->read->event_handler = ngx_imap_init_session;
|
|
|
|
|
|
|
|
ngx_add_timer(c->read, /* STUB */ 60000);
|
2004-09-07 23:29:22 +08:00
|
|
|
|
|
|
|
if (ngx_handle_read_event(c->read, 0) == NGX_ERROR) {
|
|
|
|
ngx_imap_close_connection(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-09 23:40:48 +08:00
|
|
|
static void ngx_imap_init_session(ngx_event_t *rev)
|
2004-09-07 23:29:22 +08:00
|
|
|
{
|
2004-09-09 23:40:48 +08:00
|
|
|
ngx_connection_t *c;
|
|
|
|
ngx_imap_session_t *s;
|
2004-09-07 23:29:22 +08:00
|
|
|
|
|
|
|
c = rev->data;
|
|
|
|
|
2004-09-09 23:40:48 +08:00
|
|
|
if (!(s = ngx_pcalloc(c->pool, sizeof(ngx_imap_session_t)))) {
|
|
|
|
ngx_imap_close_connection(c);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
c->data = s;
|
|
|
|
s->connection = c;
|
|
|
|
|
|
|
|
if (ngx_array_init(&s->args, c->pool, 2, sizeof(ngx_str_t)) == NGX_ERROR) {
|
|
|
|
ngx_imap_close_connection(s->connection);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
s->buffer = ngx_create_temp_buf(s->connection->pool, /* STUB */ 4096);
|
|
|
|
if (s->buffer == NULL) {
|
|
|
|
ngx_imap_close_connection(s->connection);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ngx_imap_proxy_init(s);
|
2004-09-07 23:29:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
2004-09-01 03:05:39 +08:00
|
|
|
}
|