pop3-proxy.c revision ba90e657bc68a72ab3b3021e2f4a874fac9965ba
bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (C) 2004 Timo Sirainen */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen#include "common.h"
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen#include "ioloop.h"
0536ccb51d41e3078c3a9fa33e509fb4b2420f95Timo Sirainen#include "base64.h"
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen#include "str.h"
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen#include "client.h"
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen#include "login-proxy.h"
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen#include "pop3-proxy.h"
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainenint pop3_proxy_new(struct pop3_client *client, const char *host,
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen unsigned int port, const char *user, const char *password)
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen{
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen string_t *auth, *str;
e3678f7bfba87b5aa1446a1a7b9928272b4f72a3Timo Sirainen
e3678f7bfba87b5aa1446a1a7b9928272b4f72a3Timo Sirainen i_assert(user != NULL);
e3678f7bfba87b5aa1446a1a7b9928272b4f72a3Timo Sirainen
e3678f7bfba87b5aa1446a1a7b9928272b4f72a3Timo Sirainen if (password == NULL) {
e3678f7bfba87b5aa1446a1a7b9928272b4f72a3Timo Sirainen i_error("proxy(%s): password not given",
e3678f7bfba87b5aa1446a1a7b9928272b4f72a3Timo Sirainen client->common.virtual_user);
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen return -1;
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen }
8b247780e911909a9fdc47f69ce6d1478902ad98Timo Sirainen
8b247780e911909a9fdc47f69ce6d1478902ad98Timo Sirainen auth = t_str_new(128);
8b247780e911909a9fdc47f69ce6d1478902ad98Timo Sirainen str_append_c(auth, '\0');
8b247780e911909a9fdc47f69ce6d1478902ad98Timo Sirainen str_append(auth, user);
8b247780e911909a9fdc47f69ce6d1478902ad98Timo Sirainen str_append_c(auth, '\0');
862ec874f9373e3e499e237d3b9f71fdf1413feeTimo Sirainen str_append(auth, password);
862ec874f9373e3e499e237d3b9f71fdf1413feeTimo Sirainen
862ec874f9373e3e499e237d3b9f71fdf1413feeTimo Sirainen str = t_str_new(128);
862ec874f9373e3e499e237d3b9f71fdf1413feeTimo Sirainen str_append(str, "AUTH ");
862ec874f9373e3e499e237d3b9f71fdf1413feeTimo Sirainen base64_encode(str_data(auth), str_len(auth), str);
862ec874f9373e3e499e237d3b9f71fdf1413feeTimo Sirainen str_append(str, "\r\n");
862ec874f9373e3e499e237d3b9f71fdf1413feeTimo Sirainen
862ec874f9373e3e499e237d3b9f71fdf1413feeTimo Sirainen if (login_proxy_new(&client->common, host, port, str_c(str)) < 0)
862ec874f9373e3e499e237d3b9f71fdf1413feeTimo Sirainen return -1;
862ec874f9373e3e499e237d3b9f71fdf1413feeTimo Sirainen
862ec874f9373e3e499e237d3b9f71fdf1413feeTimo Sirainen if (client->io != NULL) {
862ec874f9373e3e499e237d3b9f71fdf1413feeTimo Sirainen io_remove(client->io);
862ec874f9373e3e499e237d3b9f71fdf1413feeTimo Sirainen client->io = NULL;
862ec874f9373e3e499e237d3b9f71fdf1413feeTimo Sirainen }
862ec874f9373e3e499e237d3b9f71fdf1413feeTimo Sirainen
862ec874f9373e3e499e237d3b9f71fdf1413feeTimo Sirainen return 0;
862ec874f9373e3e499e237d3b9f71fdf1413feeTimo Sirainen}
862ec874f9373e3e499e237d3b9f71fdf1413feeTimo Sirainen