Ejemplo n.º 1
0
Archivo: pop3.c Proyecto: dinny/curl
static
CURLcode pop3_perform(struct connectdata *conn,
                     bool *connected,  /* connect status after PASV / PORT */
                     bool *dophase_done)
{
  /* this is POP3 and no proxy */
  CURLcode result=CURLE_OK;
  struct pop3_conn *pop3c = &conn->proto.pop3c;

  DEBUGF(infof(conn->data, "DO phase starts\n"));

  if(conn->data->set.opt_no_body) {
    /* requested no body means no transfer... */
    struct FTP *pop3 = conn->data->state.proto.pop3;
    pop3->transfer = FTPTRANSFER_INFO;
  }

  *dophase_done = FALSE; /* not done yet */

  /* start the first command in the DO phase */
  /* If mailbox is empty, then assume user wants listing for mail IDs,
   * otherwise, attempt to retrieve the mail-id stored in mailbox
   */
  if(strlen(pop3c->mailbox) && !conn->data->set.ftp_list_only)
    result = pop3_retr(conn);
  else
    result = pop3_list(conn);
  if(result)
    return result;

  /* run the state-machine */
  if(conn->data->state.used_interface == Curl_if_multi)
    result = pop3_multi_statemach(conn, dophase_done);
  else {
    result = pop3_easy_statemach(conn);
    *dophase_done = TRUE; /* with the easy interface we are done here */
  }
  *connected = conn->bits.tcpconnect[FIRSTSOCKET];

  if(*dophase_done)
    DEBUGF(infof(conn->data, "DO phase is complete\n"));

  return result;
}
Ejemplo n.º 2
0
void pop3_client::rpc_run()
{
	UP_CTX* up;
	struct timeval begin, last, now;
	gettimeofday(&begin, NULL);

	//////////////////////////////////////////////////////////////////
	// 域名解析过程

	gettimeofday(&last, NULL);
	if (get_ip() == false)
	{
		up = new UP_CTX;
		up->curr = 0;
		up->total = 0;
		up->msg.format("解析 pop3 域名:%s 失败!",
			pop3_addr_.c_str());
		rpc_signal(up);
		return;
	}
	gettimeofday(&now, NULL);
	meter_.pop3_nslookup_elapsed = util::stamp_sub(&now, &last);
	acl::string pop3_addr;
	pop3_addr.format("%s:%d", pop3_ip_.c_str(), pop3_port_);

	//////////////////////////////////////////////////////////////////
	// 远程连接 SMTP 服务器

	up = new UP_CTX;
	up->curr = 0;
	up->total = 0;
	up->msg.format("连接 POP3 服务器 ...");
	rpc_signal(up);

	acl::socket_stream conn;
	if (conn.open(pop3_addr.c_str(), connect_timeout_,
		rw_timeout_) == false)
	{
		logger_error("connect pop3 server(%s) error", pop3_addr);
		up = new UP_CTX;
		up->curr = 0;
		up->total = 0;
		up->msg.format("连接 pop3 服务器:%s 失败!",
			pop3_addr.c_str());
		rpc_signal(up);
		return;
	}

	gettimeofday(&now, NULL);
	meter_.pop3_connect_elapsed = util::stamp_sub(&now, &last);

	//////////////////////////////////////////////////////////////////
	// 获得 POP3 服务器的欢迎信息

	up = new UP_CTX;
	up->curr = 0;
	up->total = 0;
	up->msg.format("接收 POP3 服务器欢迎信息(连接耗时 %.2f 毫秒) ...",
		meter_.pop3_connect_elapsed);
	rpc_signal(up);

	gettimeofday(&last, NULL);
	if (pop3_get_banner(conn) == false)
		return;
	gettimeofday(&now, NULL);
	meter_.pop3_banner_elapsed = util::stamp_sub(&now, &last);

	up = new UP_CTX;
	up->curr = 0;
	up->total = 0;
	up->msg.format("获得 banner 耗时 %.2f 毫秒,开始认证账号信息 ...",
		meter_.pop3_banner_elapsed);
	rpc_signal(up);

	//////////////////////////////////////////////////////////////////
	// 认证用户的身份

	gettimeofday(&last, NULL);
	if (pop3_auth(conn, auth_account_.c_str(),
		auth_passwd_.c_str()) == false)
	{
		return;
	}
	gettimeofday(&now, NULL);
	meter_.pop3_auth_elapsed = util::stamp_sub(&now, &last);
	up = new UP_CTX;
	up->curr = 0;
	up->total = 0;
	up->msg.format("用户认证成功(耗时 %.2f 毫秒)",
		meter_.pop3_auth_elapsed);
	rpc_signal(up);

	//////////////////////////////////////////////////////////////////
	// uidl 用户收件箱的邮件列表

	up = new UP_CTX;
	up->curr = 0;
	up->total = 0;
	up->msg.format("列用户收件箱邮件(UIDL) ...");
	rpc_signal(up);

	std::vector<acl::string> uidl_list;
	gettimeofday(&last, NULL);
	if (pop3_uidl(conn, uidl_list) == false)
		return;
	gettimeofday(&now, NULL);
	meter_.pop3_uidl_elapsed = util::stamp_sub(&now, &last);

	up = new UP_CTX;
	up->curr = 0;
	up->total = 0;
	up->msg.format("用户收件箱邮件列表结束(耗时 %.2f 毫秒)",
		meter_.pop3_uidl_elapsed);
	rpc_signal(up);

	//////////////////////////////////////////////////////////////////
	// LIST 用户收件箱邮件列表

	up = new UP_CTX;
	up->curr = 0;
	up->total = 0;
	up->msg.format("列用户收件箱邮件尺寸(LIST) ...");
	rpc_signal(up);

	std::vector<size_t> size_list_;
	gettimeofday(&last, NULL);
	if (pop3_list(conn, size_list_) == false)
	{
		logger_error("pop3_list failed for %s", auth_account_.c_str());
		return;
	}
	gettimeofday(&now, NULL);
	meter_.pop3_list_elapsed = util::stamp_sub(&now, &last);

	up = new UP_CTX;
	up->curr = 0;
	up->total = 0;
	up->msg.format("列用户收件箱邮件尺寸(LIST) 耗时 %.2f",
		meter_.pop3_list_elapsed);
	rpc_signal(up);

	//////////////////////////////////////////////////////////////////
	// 收取用户收件里的邮件

	up = new UP_CTX;
	up->curr = 0;
	up->total = size_list_.size();
	up->msg.format("开始接收收件箱邮件 ...");
	rpc_signal(up);

	gettimeofday(&last, NULL);
	if (pop3_retr(conn, size_list_) == false)
	{
		logger_error("pop3_retr failed for %s", auth_account_.c_str());
		return;
	}
	gettimeofday(&now, NULL);
	meter_.pop3_recv_elapsed = util::stamp_sub(&now, &last);

	up = new UP_CTX;
	up->curr = 0;
	up->total = size_list_.size();
	up->msg.format("接收收件箱邮件完成,耗时 %0.2f",
		meter_.pop3_recv_elapsed);
	rpc_signal(up);

	//////////////////////////////////////////////////////////////////
	// 退出邮箱

	gettimeofday(&last, NULL);
	pop3_quit(conn);
	gettimeofday(&now, NULL);
	meter_.pop3_quit_elapsed = util::stamp_sub(&now, &last);

	//////////////////////////////////////////////////////////////////
	// 统计总共耗费的时间

	gettimeofday(&now, NULL);
	meter_.pop3_total_elapsed = util::stamp_sub(&now, &begin);

	up = new UP_CTX;
	up->curr = 0;
	up->total = size_list_.size();
	up->msg.format("收件过程共耗时 %0.2f",
		meter_.pop3_recv_elapsed);
	rpc_signal(up);
}