コード例 #1
0
ファイル: pop_lib.c プロジェクト: BackupTheBerlios/mutt-win32
/*
 * Send data from buffer and receive answer to the same buffer
 *  0 - successful,
 * -1 - conection lost,
 * -2 - invalid command or execution error.
*/
int pop_query_d (POP_DATA *pop_data, char *buf, size_t buflen, char *msg)
{
  int dbg = M_SOCK_LOG_CMD;
  char *c;

  if (pop_data->status != POP_CONNECTED)
    return -1;

#ifdef DEBUG
    /* print msg instaed of real command */
    if (msg)
    {
      dbg = M_SOCK_LOG_FULL;
      dprint (M_SOCK_LOG_CMD, (debugfile, "> %s", msg));
    }
#endif

  mutt_socket_write_d (pop_data->conn, buf, -1, dbg);

  c = strpbrk (buf, " \r\n");
  *c = '\0';
  snprintf (pop_data->err_msg, sizeof (pop_data->err_msg), "%s: ", buf);

  if (mutt_socket_readln (buf, buflen, pop_data->conn) < 0)
  {
    pop_data->status = POP_DISCONNECTED;
    return -1;
  }
  if (!mutt_strncmp (buf, "+OK", 3))
    return 0;

  pop_error (pop_data, buf);
  return -2;
}
コード例 #2
0
ファイル: smtp.c プロジェクト: tejux/mutt-hacks
static int
smtp_data (CONNECTION * conn, const char *msgfile)
{
        char buf[1024];
        FILE *fp = 0;
        progress_t progress;
        struct stat st;
        int r, term = 0;
        size_t buflen = 0;

        fp = fopen (msgfile, "r");
        if (!fp) {
                mutt_error (_("SMTP session failed: unable to open %s"), msgfile);
                return -1;
        }
        stat (msgfile, &st);
        unlink (msgfile);
        mutt_progress_init (&progress, _("Sending message..."), M_PROGRESS_SIZE,
                NetInc, st.st_size);

        snprintf (buf, sizeof (buf), "DATA\r\n");
        if (mutt_socket_write (conn, buf) == -1) {
                safe_fclose (&fp);
                return smtp_err_write;
        }
        if ((r = smtp_get_resp (conn))) {
                safe_fclose (&fp);
                return r;
        }

        while (fgets (buf, sizeof (buf) - 1, fp)) {
                buflen = mutt_strlen (buf);
                term = buf[buflen-1] == '\n';
                if (buflen && buf[buflen-1] == '\n'
                        && (buflen == 1 || buf[buflen - 2] != '\r'))
                        snprintf (buf + buflen - 1, sizeof (buf) - buflen + 1, "\r\n");
                if (buf[0] == '.') {
                        if (mutt_socket_write_d (conn, ".", -1, M_SOCK_LOG_FULL) == -1) {
                                safe_fclose (&fp);
                                return smtp_err_write;
                        }
                }
                if (mutt_socket_write_d (conn, buf, -1, M_SOCK_LOG_FULL) == -1) {
                        safe_fclose (&fp);
                        return smtp_err_write;
                }
                mutt_progress_update (&progress, ftell (fp), -1);
        }
        if (!term && buflen &&
        mutt_socket_write_d (conn, "\r\n", -1, M_SOCK_LOG_FULL) == -1) {
                safe_fclose (&fp);
                return smtp_err_write;
        }
        safe_fclose (&fp);

/* terminate the message body */
        if (mutt_socket_write (conn, ".\r\n") == -1)
                return smtp_err_write;

        if ((r = smtp_get_resp (conn)))
                return r;

        return 0;
}