Esempio n. 1
0
static int
mailimf_resent_msg_id_write(FILE * f, int * col,
			    struct mailimf_message_id * message_id)
{
  int r;

  r = mailimf_string_write(f, col, "Resent-Message-ID: ", 19);
  if (r != MAILIMF_NO_ERROR)
    return r;

  r = mailimf_string_write(f, col, "<", 1);
  if (r != MAILIMF_NO_ERROR)
    return r;

  r = mailimf_string_write(f, col,
      message_id->mid_value, strlen(message_id->mid_value));
  if (r != MAILIMF_NO_ERROR)
    return r;

  r = mailimf_string_write(f, col, ">", 1);
  if (r != MAILIMF_NO_ERROR)
    return r;

  r = mailimf_string_write(f, col, "\r\n", 2);
  if (r != MAILIMF_NO_ERROR)
    return r;
#if 0
  * col = 0;
#endif

  return MAILIMF_NO_ERROR;
}
Esempio n. 2
0
static int mailimf_group_write(FILE * f, int * col,
			       struct mailimf_group * group)
{
  int r;

  r = mailimf_header_string_write(f, col, group->grp_display_name,
      strlen(group->grp_display_name));
  if (r != MAILIMF_NO_ERROR)
    return r;

  r = mailimf_string_write(f, col, ": ", 2);
  if (r != MAILIMF_NO_ERROR)
    return r;
  
  if (group->grp_mb_list != NULL) {
    r = mailimf_mailbox_list_write(f, col, group->grp_mb_list);
    if (r != MAILIMF_NO_ERROR)
      return r;
  }

  r = mailimf_string_write(f, col, ";", 1);
  if (r != MAILIMF_NO_ERROR)
    return r;

  return MAILIMF_NO_ERROR;
}
Esempio n. 3
0
static int mailimf_optional_field_write(FILE * f, int * col,
					struct mailimf_optional_field * field)
{
  int r;

  if (strlen(field->fld_name) + 2 > MAX_VALID_IMF_LINE)
    return MAILIMF_ERROR_INVAL;
  
  r = mailimf_string_write(f, col, field->fld_name, strlen(field->fld_name));
  if (r != MAILIMF_NO_ERROR)
    return r;

  r = mailimf_string_write(f, col, ": ", 2);
  if (r != MAILIMF_NO_ERROR)
    return r;

  r = mailimf_header_string_write(f, col, field->fld_value,
      strlen(field->fld_value));
  if (r != MAILIMF_NO_ERROR)
    return r;

#if 0
  /* XXX parsing debug */
  mailimf_string_write(f, col, " (X)", 4);
#endif

  r = mailimf_string_write(f, col, "\r\n", 2);
  if (r != MAILIMF_NO_ERROR)
    return r;
#if 0
  * col = 0;
#endif

  return MAILIMF_NO_ERROR;
}
Esempio n. 4
0
static int mailimf_keywords_write(FILE * f, int * col,
				  struct mailimf_keywords * keywords)
{
  int r;
  clistiter * cur;
  int first;
  
  r = mailimf_string_write(f, col, "Keywords: ", 10);
  if (r != MAILIMF_NO_ERROR)
    return r;

  first = TRUE;

  for(cur = clist_begin(keywords->kw_list) ; cur != NULL ;
      cur = clist_next(cur)) {
    char * keyword;
    size_t len;

    keyword = clist_content(cur);
    len = strlen(keyword);

    if (!first) {
      r = mailimf_string_write(f, col, ", ", 2);
      if (r != MAILIMF_NO_ERROR)
	return r;
    }
    else {
      first = FALSE;
    }

#if 0
    if (* col > 1) {
      
      if (* col + len >= MAX_MAIL_COL) {
	r = mailimf_string_write(f, col, "\r\n ", 3);
	if (r != MAILIMF_NO_ERROR)
	  return r;
#if 0
	* col = 1;
#endif
      }
    }
#endif

    r = mailimf_header_string_write(f, col, keyword, len);
    if (r != MAILIMF_NO_ERROR)
      return r;
  }

  r = mailimf_string_write(f, col, "\r\n", 2);
  if (r != MAILIMF_NO_ERROR)
    return r;
#if 0
  * col = 0;
#endif

  return MAILIMF_NO_ERROR;
}
Esempio n. 5
0
static int mailimf_msg_id_list_write(FILE * f, int * col, clist * mid_list)
{
  clistiter * cur;
  int r;
  int first;

  first = TRUE;

  for(cur = clist_begin(mid_list) ; cur != NULL ; cur = clist_next(cur)) {
    char * msgid;
    size_t len;

    msgid = clist_content(cur);
    len = strlen(msgid);
    
    /*
      XXX - if this is the first message ID, don't fold.
      This is a workaround for a bug of old versions of INN.
    */
    if (!first) {
      if (* col > 1) {
        
        if (* col + len >= MAX_MAIL_COL) {
          r = mailimf_string_write(f, col, "\r\n ", 3);
          if (r != MAILIMF_NO_ERROR)
            return r;
#if 0
          * col = 1;
#endif
          first = TRUE;
        }
      }
    }
    
    if (!first) {
      r = mailimf_string_write(f, col, " ", 1);
      if (r != MAILIMF_NO_ERROR)
	return r;
    }
    else {
      first = FALSE;
    }

    r = mailimf_string_write(f, col, "<", 1);
    if (r != MAILIMF_NO_ERROR)
      return r;

    r = mailimf_string_write(f, col, msgid, len);
    if (r != MAILIMF_NO_ERROR)
      return r;

    r = mailimf_string_write(f, col, ">", 1);
    if (r != MAILIMF_NO_ERROR)
      return r;
  }

  return MAILIMF_NO_ERROR;
}
Esempio n. 6
0
int mailimf_mailbox_list_write(FILE * f, int * col,
    struct mailimf_mailbox_list * mb_list)
{
  clistiter * cur;
  int r;
  int first;

  first = TRUE;

  for(cur = clist_begin(mb_list->mb_list) ; cur != NULL ;
      cur = clist_next(cur)) {
    struct mailimf_mailbox * mb;

    mb = clist_content(cur);

    if (!first) {
      r = mailimf_string_write(f, col, ", ", 2);
      if (r != MAILIMF_NO_ERROR)
	return r;
    }
    else {
      first = FALSE;
    }

    r = mailimf_mailbox_write(f, col, mb);
    if (r != MAILIMF_NO_ERROR)
      return r;
  }

  return MAILIMF_NO_ERROR;
}
Esempio n. 7
0
int mailimf_address_list_write(FILE * f, int * col,
    struct mailimf_address_list * addr_list)
{
  clistiter * cur;
  int r;
  int first;

  first = TRUE;

  for(cur = clist_begin(addr_list->ad_list) ; cur != NULL ;
      cur = clist_next(cur)) {
    struct mailimf_address * addr;

    addr = clist_content(cur);

    if (!first) {
      r = mailimf_string_write(f, col, ", ", 2);
      if (r != MAILIMF_NO_ERROR)
	return r;
    }
    else {
      first = FALSE;
    }

    r = mailimf_address_write(f, col, addr);
    if (r != MAILIMF_NO_ERROR)
      return r;
  }

  return MAILIMF_NO_ERROR;
}
Esempio n. 8
0
char * mailprivacy_dup_imf_file(struct mailprivacy * privacy,
    char * source_filename)
{
  char filename[PATH_MAX];
  FILE * dest_f;
  int r;
  struct stat stat_info;
  char * dest_filename;
  char * mapping;
  int fd;
  int col;
  
  dest_f = mailprivacy_get_tmp_file(privacy,
      filename, sizeof(filename));
  if (dest_f == NULL)
    goto err;
  
  dest_filename = strdup(filename);
  if (dest_filename == NULL)
    goto close_dest;
  
  fd = open(source_filename, O_RDONLY);
  if (fd < 0)
    goto free_dest;
  
  r = fstat(fd, &stat_info);
  if (r < 0)
    goto close_src;
  
  mapping = mmap(NULL, stat_info.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
  if (mapping == (char *)MAP_FAILED)
    goto close_src;
  
  col = 0;
  r = mailimf_string_write(dest_f, &col, mapping, stat_info.st_size);
  if (r != MAILIMF_NO_ERROR)
    goto unmap;
  
  munmap(mapping, stat_info.st_size);
  close(fd);
  fclose(dest_f);
  
  return dest_filename;
  
 unmap:
  munmap(mapping, stat_info.st_size);
 close_src:
  close(fd);
 free_dest:
  free(dest_filename);
 close_dest:
  fclose(dest_f);
 err:
  return NULL;
}
Esempio n. 9
0
static int mailimf_path_write(FILE * f, int * col,
			      struct mailimf_path * path)
{
  int r;

  r = mailimf_string_write(f, col, "<", 1);
  if (r != MAILIMF_NO_ERROR)
    return r;

  r = mailimf_string_write(f, col, path->pt_addr_spec,
      strlen(path->pt_addr_spec));
  if (r != MAILIMF_NO_ERROR)
    return r;

  r = mailimf_string_write(f, col, ">", 1);
  if (r != MAILIMF_NO_ERROR)
    return r;

  return MAILIMF_NO_ERROR;
}
Esempio n. 10
0
static int mailimf_from_write(FILE * f, int * col,
			      struct mailimf_from * from)
{
  int r;

  r = mailimf_string_write(f, col, "From: ", 6);
  if (r != MAILIMF_NO_ERROR)
    return r;

  r = mailimf_mailbox_list_write(f, col, from->frm_mb_list);
  if (r != MAILIMF_NO_ERROR)
    return r;

  r = mailimf_string_write(f, col, "\r\n", 2);
  if (r != MAILIMF_NO_ERROR)
    return r;
#if 0
  * col = 0;
#endif

  return MAILIMF_NO_ERROR;
}
Esempio n. 11
0
static int mailimf_in_reply_to_write(FILE * f, int * col,
				     struct mailimf_in_reply_to * in_reply_to)
{
  int r;

  r = mailimf_string_write(f, col, "In-Reply-To: ", 13);
  if (r != MAILIMF_NO_ERROR)
    return r;

  r = mailimf_msg_id_list_write(f, col, in_reply_to->mid_list);
  if (r != MAILIMF_NO_ERROR)
    return r;

  r = mailimf_string_write(f, col, "\r\n", 2);
  if (r != MAILIMF_NO_ERROR)
    return r;
#if 0
  * col = 0;
#endif

  return MAILIMF_NO_ERROR;
}
Esempio n. 12
0
static int mailimf_sender_write(FILE * f, int * col,
				struct mailimf_sender * sender)
{
  int r;

  r = mailimf_string_write(f, col, "Sender: ", 8);
  if (r != MAILIMF_NO_ERROR)
    return r;

  r = mailimf_mailbox_write(f, col, sender->snd_mb);
  if (r != MAILIMF_NO_ERROR)
    return r;

  r = mailimf_string_write(f, col, "\r\n", 2);
  if (r != MAILIMF_NO_ERROR)
    return r;
#if 0
  * col = 0;
#endif

  return MAILIMF_NO_ERROR;
}
Esempio n. 13
0
static int mailimf_resent_cc_write(FILE * f, int * col,
				   struct mailimf_cc * cc)
{
  int r;

  r = mailimf_string_write(f, col, "Resent-Cc: ", 11);
  if (r != MAILIMF_NO_ERROR)
    return r;

  r = mailimf_address_list_write(f, col, cc->cc_addr_list);
  if (r != MAILIMF_NO_ERROR)
    return r;

  r = mailimf_string_write(f, col, "\r\n", 2);
  if (r != MAILIMF_NO_ERROR)
    return r;
#if 0
  * col = 0;
#endif

  return MAILIMF_NO_ERROR;
}
Esempio n. 14
0
static int mailimf_reply_to_write(FILE * f, int * col,
				  struct mailimf_reply_to * reply_to)
{
  int r;

  r = mailimf_string_write(f, col, "Reply-To: ", 10);
  if (r != MAILIMF_NO_ERROR)
    return r;

  r = mailimf_address_list_write(f, col, reply_to->rt_addr_list);
  if (r != MAILIMF_NO_ERROR)
    return r;

  r = mailimf_string_write(f, col, "\r\n", 2);
  if (r != MAILIMF_NO_ERROR)
    return r;
#if 0
  * col = 0;
#endif

  return MAILIMF_NO_ERROR;
}
Esempio n. 15
0
static int mailimf_references_write(FILE * f, int * col,
				    struct mailimf_references * references)
{
  int r;

  r = mailimf_string_write(f, col, "References: ", 12);
  if (r != MAILIMF_NO_ERROR)
    return r;

  r = mailimf_msg_id_list_write(f, col, references->mid_list);
  if (r != MAILIMF_NO_ERROR)
    return r;

  r = mailimf_string_write(f, col, "\r\n", 2);
  if (r != MAILIMF_NO_ERROR)
    return r;
#if 0
  * col = 0;
#endif

  return MAILIMF_NO_ERROR;
}
Esempio n. 16
0
static int mailimf_return_write(FILE * f, int * col,
				struct mailimf_return * return_path)
{
  int r;

  r = mailimf_string_write(f, col, "Return-Path: ", 13);
  if (r != MAILIMF_NO_ERROR)
    return r;

  r = mailimf_path_write(f, col, return_path->ret_path);
  if (r != MAILIMF_NO_ERROR)
    return r;

  r = mailimf_string_write(f, col, "\r\n", 2);
  if (r != MAILIMF_NO_ERROR)
    return r;
#if 0
  * col = 0;
#endif

  return MAILIMF_NO_ERROR;
}
Esempio n. 17
0
static int mailimf_orig_date_write(FILE * f, int * col,
				   struct mailimf_orig_date * date)
{
  int r;

  r = mailimf_string_write(f, col, "Date: ", 6);
  if (r != MAILIMF_NO_ERROR)
    return r;

  r = mailimf_date_time_write(f, col, date->dt_date_time);
  if (r != MAILIMF_NO_ERROR)
    return r;

  r = mailimf_string_write(f, col, "\r\n", 2);
  if (r != MAILIMF_NO_ERROR)
    return r;
#if 0
  * col = 0;
#endif

  return MAILIMF_NO_ERROR;
}
Esempio n. 18
0
static int mailimf_to_write(FILE * f, int * col,
			    struct mailimf_to * to)
{
  int r;

  r = mailimf_string_write(f, col, "To: ", 4);
  if (r != MAILIMF_NO_ERROR)
    return r;

  r = mailimf_address_list_write(f, col, to->to_addr_list);
  if (r != MAILIMF_NO_ERROR)
    return r;

  r = mailimf_string_write(f, col, "\r\n", 2);
  if (r != MAILIMF_NO_ERROR)
    return r;
#if 0
  * col = 0;
#endif

  return MAILIMF_NO_ERROR;
}
Esempio n. 19
0
static int mailimf_subject_write(FILE * f, int * col,
				 struct mailimf_subject * subject)
{
  int r;

  r = mailimf_string_write(f, col, "Subject: ", 9);
  if (r != MAILIMF_NO_ERROR)
    return r;

  r = mailimf_header_string_write(f, col,
      subject->sbj_value, strlen(subject->sbj_value));
  if (r != MAILIMF_NO_ERROR)
    return r;

  r = mailimf_string_write(f, col, "\r\n", 2);
  if (r != MAILIMF_NO_ERROR)
    return r;
#if 0
  * col = 0;
#endif

  return MAILIMF_NO_ERROR;
}
Esempio n. 20
0
static int mailimf_comments_write(FILE * f, int * col,
				  struct mailimf_comments * comments)
{
  int r;

  r = mailimf_string_write(f, col, "Comments: ", 10);
  if (r != MAILIMF_NO_ERROR)
    return r;

  r = mailimf_header_string_write(f, col,
      comments->cm_value, strlen(comments->cm_value));
  if (r != MAILIMF_NO_ERROR)
    return r;

  r = mailimf_string_write(f, col, "\r\n", 2);
  if (r != MAILIMF_NO_ERROR)
    return r;
#if 0
  * col = 0;
#endif

  return MAILIMF_NO_ERROR;
}
Esempio n. 21
0
static int mailimf_resent_bcc_write(FILE * f, int * col,
				    struct mailimf_bcc * bcc)
{
  int r;

  r = mailimf_string_write(f, col, "Resent-Bcc: ", 12);
  if (r != MAILIMF_NO_ERROR)
    return r;

  if (bcc->bcc_addr_list != NULL) {
    r =  mailimf_address_list_write(f, col, bcc->bcc_addr_list);
    if (r != MAILIMF_NO_ERROR)
      return r;
  }

  r = mailimf_string_write(f, col, "\r\n", 2);
  if (r != MAILIMF_NO_ERROR)
    return r;
#if 0
  * col = 0;
#endif

  return MAILIMF_NO_ERROR;
}
Esempio n. 22
0
static int mailimf_date_time_write(FILE * f, int * col,
				   struct mailimf_date_time * date_time)
{
  int r;
  char date_str[MAX_DATE_STR];
#if 0
  struct tm tmval;
  time_t timeval;
#endif
  int wday;
  
#if 0
  tmval.tm_sec  = date_time->sec;
  tmval.tm_min  = date_time->min;
  tmval.tm_hour  = date_time->hour;
  tmval.tm_sec  = date_time->sec;
  tmval.tm_mday = date_time->day;
  tmval.tm_mon = date_time->month - 1;
  tmval.tm_year = date_time->year - 1900;
  tmval.tm_isdst = 1;

  timeval = mktime(&tmval);
  
  localtime_r(&timeval, &tmval);
#endif

  wday = dayofweek(date_time->dt_year, date_time->dt_month, date_time->dt_day);

  snprintf(date_str, MAX_DATE_STR, "%s, %i %s %i %02i:%02i:%02i %+05i",
      week_of_day_str[wday], date_time->dt_day,
      month_str[date_time->dt_month - 1],
      date_time->dt_year, date_time->dt_hour,
      date_time->dt_min, date_time->dt_sec,
      date_time->dt_zone);

  r = mailimf_string_write(f, col, date_str, strlen(date_str));

  if (r != MAILIMF_NO_ERROR)
    return r;

  return MAILIMF_NO_ERROR;
}
Esempio n. 23
0
int mailimf_header_string_write(FILE * f, int * col,
    const char * str, size_t length)
{
  int state;
  const char * p;
  const char * block_begin;
  size_t size;
  const char * cut;
  int r;
  
  if (* col < MAX_MAIL_COL)
    state = STATE_LOWER_72_CUT;
  else if (* col == MAX_MAIL_COL)
    state = STATE_EQUAL_72;
  else if (* col < MAX_VALID_IMF_LINE)
    state = STATE_LOWER_998;
  else
    state = STATE_EQUAL_998;
  
  p = str;
  block_begin = p;
  size = * col;
  cut = p;
  
  while (length > 0) {
    switch (state) {
    case STATE_LOWER_72:
      switch (* p) {
      case '\r':
      case '\n':
        p ++;
        length --;
        size = 0;
        break;
      
      case ' ':
      case '\t':
        cut = p;
        p ++;
        length --;
        size ++;
        state = STATE_LOWER_72_CUT;
        break;
      
      default:
        if (size < MAX_MAIL_COL - 1) {
          p ++;
          length --;
          size ++;
        }
        else {
          state = STATE_EQUAL_72;
          p ++;
          length --;
          size ++;
        }
        break;
      }
      break; /* end of STATE_LOWER_72 */
    
    case STATE_LOWER_72_CUT:
      switch (* p) {
      case '\r':
      case '\n':
        p ++;
        length --;
        size = 0;
        state = STATE_LOWER_72;
        break;
      
      case ' ':
      case '\t':
        cut = p;
        p ++;
        length --;
        size ++;
        break;
      
      default:
        if (size < MAX_MAIL_COL) {
          p ++;
          length --;
          size ++;
        }
        else {
          r = mailimf_string_write(f, col, block_begin, cut - block_begin);
          if (r != MAILIMF_NO_ERROR)
            return r;
          r = mailimf_string_write(f, col, HEADER_FOLD,
              sizeof(HEADER_FOLD) - 1);
          if (r != MAILIMF_NO_ERROR)
            return r;
          p ++;
          length --;
          block_begin = cut;
          if ((* block_begin == ' ') || (* block_begin == '\t'))
            block_begin ++;
          size = p - block_begin + * col;
          state = STATE_LOWER_72;
        }
        break;
      }
      break; /* end of STATE_LOWER_72_CUT */

    case STATE_EQUAL_72:
      switch (* p) {
      case '\r':
      case '\n':
        p ++;
        length --;
        size = 0;
        state = STATE_LOWER_72;
        break;
      
      case ' ':
      case '\t':
        r = mailimf_string_write(f, col, block_begin, p - block_begin);
        if (r != MAILIMF_NO_ERROR)
          return r;
        r = mailimf_string_write(f, col, HEADER_FOLD,
            sizeof(HEADER_FOLD) - 1);
        if (r != MAILIMF_NO_ERROR)
          return r;
        p ++;
        length --;
        block_begin = p;
        size = p - block_begin + * col;
        state = STATE_LOWER_72;
        break;
      
      default:
        p ++;
        length --;
        size ++;
        state = STATE_LOWER_998;
        break;
      }
      break; /* end of STATE_EQUAL_72 */

    case STATE_LOWER_998:
      switch (* p) {
      case '\r':
      case '\n':
        p ++;
        length --;
        size = 0;
        state = STATE_LOWER_72;
        break;
      
      case ' ':
      case '\t':
        r = mailimf_string_write(f, col, block_begin, p - block_begin);
        if (r != MAILIMF_NO_ERROR)
          return r;
        r = mailimf_string_write(f, col, HEADER_FOLD,
            sizeof(HEADER_FOLD) - 1);
        if (r != MAILIMF_NO_ERROR)
          return r;
        p ++;
        length --;
        block_begin = p;
        size = p - block_begin + * col;
        state = STATE_LOWER_72;
        break;
      
      default:
        if (size < MAX_VALID_IMF_LINE - 1) {
          p ++;
          length --;
          size ++;
        }
        else {
          p ++;
          length --;
          size = 0;
          state = STATE_EQUAL_998;
        }
        break;
      }
      break; /* end of STATE_LOWER_998 */

    case STATE_EQUAL_998:
      switch (* p) {
      case '\r':
      case '\n':
        p ++;
        length --;
        size = 0;
        state = STATE_LOWER_72;
        break;
      
      case ' ':
      case '\t':
        r = mailimf_string_write(f, col, block_begin, p - block_begin);
        if (r != MAILIMF_NO_ERROR)
          return r;
        r = mailimf_string_write(f, col, HEADER_FOLD,
            sizeof(HEADER_FOLD) - 1);
        if (r != MAILIMF_NO_ERROR)
          return r;
        p ++;
        length --;
        block_begin = p;
        size = p - block_begin + * col;
        state = STATE_LOWER_72;
        break;
      
      default:
#ifdef CUT_AT_MAX_VALID_IMF_LINE
        r = mailimf_string_write(f, col, block_begin, p - block_begin);
        if (r != MAILIMF_NO_ERROR)
          return r;
        r = mailimf_string_write(f, col, HEADER_FOLD,
            sizeof(HEADER_FOLD) - 1);
        if (r != MAILIMF_NO_ERROR)
          return r;
        p ++;
        length --;
        block_begin = p;
        size = p - block_begin + * col;
        state = STATE_LOWER_72;
#else
        p ++;
        length --;
        size ++;
#endif
        break;
      }
      break; /* end of STATE_EQUAL_998 */
    }
  }
  
  r = mailimf_string_write(f, col, block_begin, p - block_begin);
  if (r != MAILIMF_NO_ERROR)
    return r;
  
  return MAILIMF_NO_ERROR;
}
Esempio n. 24
0
int mailprivacy_fetch_mime_body_to_file(struct mailprivacy * privacy,
    char * filename, size_t size,
    mailmessage * msg, struct mailmime * mime)
{
  int r;
  int res;
  FILE * f;
  char * content;
  size_t content_len;
  int col;
  
  if (mime->mm_parent_type == MAILMIME_NONE) {
    res = MAIL_ERROR_INVAL;
    goto err;
  }
  
  f = mailprivacy_get_tmp_file(privacy, filename, size);
  if (f == NULL) {
    res = MAIL_ERROR_FETCH;
    goto err;
  }
  
  r = mailprivacy_msg_fetch_section_mime(privacy, msg, mime,
      &content, &content_len);
  if (r != MAIL_NO_ERROR) {
    res = MAIL_ERROR_FETCH;
    goto close;
  }
  
  col = 0;
  r = mailimf_string_write(f, &col, content, content_len);
  mailprivacy_msg_fetch_result_free(privacy, msg, content);
  if (r != MAILIMF_NO_ERROR) {
    res = r;
    goto close;
  }
  
  r = mailprivacy_msg_fetch_section(privacy, msg, mime,
      &content, &content_len);
  if (r != MAIL_NO_ERROR) {
    res = MAIL_ERROR_FETCH;
    goto close;
  }
  
  r = mailimf_string_write(f, &col, content, content_len);
  mailprivacy_msg_fetch_result_free(privacy, msg, content);
  if (r != MAILIMF_NO_ERROR) {
    res = r;
    goto close;
  }
  
  fclose(f);
  
  return MAIL_NO_ERROR;
  
 close:
  fclose(f);
  unlink(filename);
 err:
  return res;
}
Esempio n. 25
0
int mailimf_header_string_write(FILE * f, int * col,
    char * str, size_t length)
{
  char * p;
  char * block_begin;
  int current_col;
  char * last_cut;
  int r;
  int first;
  
  if (* col + length < MAX_MAIL_COL)
    return mailimf_string_write(f, col, str, length);
  
  first = 1;
  p = str;
  block_begin = p;
  last_cut = block_begin;
  current_col = * col;
  
  while (1) {
    if (current_col >= MAX_MAIL_COL) {
      /* if we reach the maximum recommanded size of line */
      if (last_cut == block_begin) {
        /* if we could not find any place to cut */
        if (first) {
          /* fold the header */
          r = mailimf_string_write(f, col, HEADER_FOLD,
              sizeof(HEADER_FOLD) - 1);
          if (r != MAILIMF_NO_ERROR)
            return r;
          current_col = * col + p - block_begin;
          first = 0;
        }
        else {
          /* cut the header */
          r = mailimf_string_write(f, col, block_begin, p - block_begin);
          if (r != MAILIMF_NO_ERROR)
            return r;
          r = mailimf_string_write(f, col, HEADER_FOLD,
              sizeof(HEADER_FOLD) - 1);
          if (r != MAILIMF_NO_ERROR)
            return r;
          first = 0;
          block_begin = p;
          last_cut = block_begin;
          current_col = * col + p - block_begin;
        }
      }
      else {
        /* if we found a place to cut */
        r = mailimf_string_write(f, col, block_begin, last_cut - block_begin);
        if (r != MAILIMF_NO_ERROR)
          return r;
        r = mailimf_string_write(f, col, HEADER_FOLD,
            sizeof(HEADER_FOLD) - 1);
        if (r != MAILIMF_NO_ERROR)
          return r;
        first = 0;
        block_begin = last_cut;
        last_cut = block_begin;
        current_col = * col + p - block_begin;
        continue;
      }
    }
    else {
      if (length == 0)
        break;
      
      switch (* p) {
      case ' ':
      case '\t':
        last_cut = p;
        current_col ++;
        break;
        
      case '\r':
      case '\n':
        current_col = 0;
        break;
        
      default:
        current_col ++;
        break;
      }
      
      p ++;
      length --;
    }
  }
  
  return mailimf_string_write(f, col, block_begin, p - block_begin);
}
Esempio n. 26
0
static int mailimf_mailbox_write(FILE * f, int * col,
				 struct mailimf_mailbox * mb)
{
  int r;
  int do_fold;
  
#if 0
  if (* col > 1) {
    
    if (mb->mb_display_name != NULL) {
      if (* col + strlen(mb->mb_display_name) >= MAX_MAIL_COL) {
        r = mailimf_string_write(f, col, "\r\n ", 3);
        if (r != MAILIMF_NO_ERROR)
          return r;
#if 0
        * col = 1;
#endif
      }
    }
  }
#endif
  
  if (mb->mb_display_name) {

    if (is_atext(mb->mb_display_name)) {
      r = mailimf_header_string_write(f, col, mb->mb_display_name,
          strlen(mb->mb_display_name));
      if (r != MAILIMF_NO_ERROR)
        return r;
    }
    else {
      if (mb->mb_display_name != NULL) {
        if (* col + strlen(mb->mb_display_name) >= MAX_MAIL_COL) {
          r = mailimf_string_write(f, col, "\r\n ", 3);
          if (r != MAILIMF_NO_ERROR)
            return r;
        }
      }
      
      if (strlen(mb->mb_display_name) > MAX_VALID_IMF_LINE / 2)
        return MAILIMF_ERROR_INVAL;
      
      r = mailimf_quoted_string_write(f, col, mb->mb_display_name,
          strlen(mb->mb_display_name));
      if (r != MAILIMF_NO_ERROR)
        return r;
    }
    
    do_fold = 0;
    if (* col > 1) {
      
      if (* col + strlen(mb->mb_addr_spec) + 3 >= MAX_MAIL_COL) {
	r = mailimf_string_write(f, col, "\r\n ", 3);
	if (r != MAILIMF_NO_ERROR)
	  return r;
#if 0
	* col = 1;
#endif
        do_fold = 1;
      }
    }
    
    if (do_fold)
      r = mailimf_string_write(f, col, "<", 1);
    else
      r = mailimf_string_write(f, col, " <", 2);
    if (r != MAILIMF_NO_ERROR)
      return r;

    r = mailimf_string_write(f, col, mb->mb_addr_spec,
        strlen(mb->mb_addr_spec));
    if (r != MAILIMF_NO_ERROR)
      return r;

    r = mailimf_string_write(f, col, ">", 1);
    if (r != MAILIMF_NO_ERROR)
      return r;
  }
  else {
    if (* col + strlen(mb->mb_addr_spec) >= MAX_MAIL_COL) {
      r = mailimf_string_write(f, col, "\r\n ", 3);
      if (r != MAILIMF_NO_ERROR)
        return r;
    }
    
    r = mailimf_string_write(f, col,
        mb->mb_addr_spec, strlen(mb->mb_addr_spec));
    if (r != MAILIMF_NO_ERROR)
      return r;
  }


  return MAILIMF_NO_ERROR;
}
Esempio n. 27
0
int mailimf_header_string_write(FILE * f, int * col,
    const char * str, size_t length)
{
  int state;
  const char * p;
  const char * word_begin;
  int first;
  
  state = STATE_BEGIN;
  
  p = str;
  word_begin = p;
  first = 1;
  
  while (length > 0) {
    switch (state) {
    case STATE_BEGIN:
      switch (* p) {
      case '\r':
      case '\n':
      case ' ':
      case '\t':
        p ++;
        length --;
        break;
      
      default:
        word_begin = p;
        state = STATE_WORD;
        break;
      }
      break;
      
    case STATE_SPACE:
      switch (* p) {
      case '\r':
      case '\n':
      case ' ':
      case '\t':
        p ++;
        length --;
        break;
      
      default:
        word_begin = p;
        state = STATE_WORD;
        break;
      }
      break;

    case STATE_WORD:
      switch (* p) {
      case '\r':
      case '\n':
      case ' ':
      case '\t':
        if (p - word_begin + (* col) + 1 > MAX_MAIL_COL)
          mailimf_string_write(f, col, HEADER_FOLD,
              sizeof(HEADER_FOLD) - 1);
        else {
          if (!first)
            mailimf_string_write(f, col, " ", 1);
        }
        first = 0;
        mailimf_string_write(f, col, word_begin, p - word_begin);
        state = STATE_SPACE;
        break;
        
      default:
        if (p - word_begin + (* col) >= MAX_VALID_IMF_LINE) {
          mailimf_string_write(f, col, word_begin, p - word_begin);
          mailimf_string_write(f, col, HEADER_FOLD,
              sizeof(HEADER_FOLD) - 1);
          word_begin = p;
        }
        p ++;
        length --;
        break;
      }
      break;
    }
  }
  
  if (state == STATE_WORD) {
    if (p - word_begin + (* col) >= MAX_MAIL_COL)
      mailimf_string_write(f, col, HEADER_FOLD,
          sizeof(HEADER_FOLD) - 1);
    else {
      if (!first)
        mailimf_string_write(f, col, " ", 1);
    }
    first = 0;
    mailimf_string_write(f, col, word_begin, p - word_begin);
  }
  
  return MAILIMF_NO_ERROR;
}