예제 #1
0
static inline int send_data_crlf_progress(mailstream * s, const char * message,
                                          size_t size,
                                          int quoted,
                                          size_t progr_rate,
                                          progress_function * progr_fun,
                                          mailprogress_function * progr_context_fun,
                                          void * context)
{
  const char * current;
  size_t count;
  size_t last;
  size_t remaining;

  count = 0;
  last = 0;

  current = message;
  remaining = size;

  while (remaining > 0) {
    ssize_t length;
    
    if (quoted) {
      if (current[0] == '.')
        if (mailstream_write(s, ".", 1) == -1)
          goto err;
    }
    
    length = send_data_line(s, current, remaining);
    if (length < 0)
      goto err;

    current += length;

    count += length;
    if (progr_rate != 0) {
      if (count - last >= progr_rate) {
        if (progr_fun != NULL) {
          (* progr_fun)(count, size);
        }
        if (progr_context_fun != NULL) {
          (* progr_context_fun)(count, size, context);
        }
        last = count;
      }
    }
    
    remaining -= length;
  }
  
  return 0;
  
 err:
  return -1;
}
예제 #2
0
파일: mailpop3.c 프로젝트: CodaFi/etPanKit
static int send_command_private(mailpop3 * f, char * command, int can_be_published)
{
  ssize_t r;

  mailstream_set_privacy(f->pop3_stream, can_be_published);
  r = mailstream_write(f->pop3_stream, command, strlen(command));
  if (r == -1)
    return -1;

  r = mailstream_flush(f->pop3_stream);
  if (r == -1)
    return -1;

  return 0;
}
예제 #3
0
static inline int mailstream_send_data_progress(mailstream * s, const char * message,
                                                size_t size,
                                                size_t progr_rate,
                                                progress_function * progr_fun,
                                                mailprogress_function * progr_ctx_fun,
                                                void * context)
{
  if (send_data_crlf_progress(s, message, size, 1, progr_rate, progr_fun,
                              progr_ctx_fun, context) == -1)
    goto err;
  
  if (mailstream_write(s, "\r\n.\r\n", 5) == -1)
    goto err;
  
  if (mailstream_flush(s) == -1)
    goto err;
  
  return 0;
  
err:
  return -1;
}
예제 #4
0
static inline ssize_t send_data_line(mailstream * s,
    const char * line, size_t length)
{
  int fix_eol;
  const char * start;
  size_t count;

  start = line;

  fix_eol = 0;
  count = 0;

  while (1) {
    if (length == 0)
      break;

    if (* line == '\r') {
      line ++;

      count ++;
      length --;

      if (length == 0) {
        fix_eol = 1;
        break;
      }
      
      if (* line == '\n') {
	line ++;

	count ++;
	length --;
	
	break;
      }
      else {
        fix_eol = 1;
        break;
      }
    }
    else if (* line == '\n') {
      line ++;

      count ++;
      length --;

      fix_eol = 1;
      break;
    }

    line ++;
    length --;
    count ++;
  }

  if (fix_eol) {
    if (mailstream_write(s, start, count - 1) == -1)
      goto err;
    if (mailstream_write(s, "\r\n", 2) == -1)
      goto err;
  }
  else {
    if (mailstream_write(s, start, count) == -1)
      goto err;
  }
  

#if 0
  while (* line != '\n') {
    if (* line == '\r')
      pos = line;
    if (* line == '\0')
      return line;
    if (mailstream_write(s, line, 1) == -1)
      goto err;
    line ++;
  }
  if (pos + 1 == line) {
    if (mailstream_write(s, line, 1) == -1)
      goto err;
  }
  else {
    if (mailstream_write(s, "\r\n", 2) == -1)
      goto err;
  }
  line ++;
#endif

  return count;
  
 err:
  return -1;
}