Example #1
0
static int feed_prefetch(mailmessage * msg_info)
{
  struct generic_message_t * msg;
  int r;
  MMAPString * str;
  const char * text;
  int col;
  struct newsfeed * feed;
  struct newsfeed_item * item;
  int res;
  
  feed = get_feed_session(msg_info);
  item = newsfeed_get_item(feed, msg_info->msg_index);
  
  str = mmap_string_new("");
  if (str == NULL) {
    res = MAIL_ERROR_MEMORY;
    goto err;
  }
  
  col = 0;
  r = mailimf_fields_write_mem(str, &col,
      msg_info->msg_fields);
  if (r != MAILIMF_NO_ERROR) {
    res = MAIL_ERROR_MEMORY;
    goto free_str;
  }
  
  if (mmap_string_append(str, "\r\n") == NULL) {
    res = MAIL_ERROR_MEMORY;
    goto free_str;
  }
  
  text = newsfeed_item_get_text(item);
  if (text == NULL) {
    /* if no content, fallback on summary */
    text = newsfeed_item_get_summary(item);
  }
  if (mmap_string_append(str, text) == NULL) {
    res = MAIL_ERROR_MEMORY;
    goto free_str;
  }
  
  msg = msg_info->msg_data;
  msg->msg_message = str->str;
  msg->msg_length = str->len;
  
  mmap_string_ref(str);
  
  return MAIL_NO_ERROR;
  
 free_str:
  mmap_string_free(str);
 err:
  return res;
}
static int fetch_section_header(mailmessage * msg_info,
    struct mailmime * mime,
    char ** result, size_t * result_len)
{
  int r;
  int res;
  int col;
  MMAPString * str;
  
  if (msg_info->msg_mime == NULL)
    return MAIL_ERROR_INVAL;
  
  str = mmap_string_new("");
  if (str == NULL) {
    res = MAIL_ERROR_MEMORY;
    goto err;
  }
  
  col = 0;
  if (mime->mm_type == MAILMIME_MESSAGE) {
    if (mime->mm_data.mm_message.mm_fields != NULL) {
      r = mailimf_fields_write_mem(str, &col, mime->mm_data.mm_message.mm_fields);
      if (r != MAILIMF_NO_ERROR) {
        res = maildriver_imf_error_to_mail_error(r);
        goto free;
      }
      mailimf_string_write_mem(str, &col, "\r\n", 2);
    }
  }
  
  r = mmap_string_ref(str);
  if (r < 0) {
    res = MAIL_ERROR_MEMORY;
    goto free;
  }
  
  * result = str->str;
  * result_len = str->len;
  
  return MAIL_NO_ERROR;

 free:
  mmap_string_free(str);
 err:
  return res;
}