예제 #1
0
static int nntp_fetch_header(mailmessage * msg_info,
			     char ** result,
			     size_t * result_len)
{
  struct generic_message_t * msg;
  char * headers;
  size_t headers_length;
  struct nntp_cached_session_state_data * cached_data;
  struct nntp_session_state_data * ancestor_data;
  int r;
  char filename[PATH_MAX];

  msg = msg_info->msg_data;

  if (msg->msg_message != NULL)
    return mailmessage_generic_fetch_header(msg_info,
        result, result_len);
  
  /* we try the cached message */
  
  cached_data = get_cached_session_data(msg_info);

  ancestor_data = get_ancestor_session_data(msg_info);

  snprintf(filename, PATH_MAX, "%s/%s/%i-header",
      cached_data->nntp_cache_directory,
      ancestor_data->nntp_group_name, msg_info->msg_index);

  r = generic_cache_read(filename, &headers, &headers_length);
  if (r == MAIL_NO_ERROR) {
    * result = headers;
    * result_len = headers_length;

    return MAIL_NO_ERROR;
  }

  /* we get the message through the network */

  r = nntpdriver_head(get_ancestor_session(msg_info), msg_info->msg_index,
		      &headers, &headers_length);
  if (r != MAIL_NO_ERROR)
    return r;

  /* we write the message cache */

  generic_cache_store(filename, headers, headers_length);

  * result = headers;
  * result_len = headers_length;

  return MAIL_NO_ERROR;
}
예제 #2
0
static int nntp_prefetch(mailmessage * msg_info)
{
  char * msg_content;
  size_t msg_length;
  struct generic_message_t * msg;
  int r;
  struct nntp_cached_session_state_data * cached_data;
  struct nntp_session_state_data * ancestor_data;
  char filename[PATH_MAX];

  /* we try the cached message */

  cached_data = get_cached_session_data(msg_info);

  ancestor_data = get_ancestor_session_data(msg_info);

  snprintf(filename, PATH_MAX, "%s/%s/%i", cached_data->nntp_cache_directory,
      ancestor_data->nntp_group_name, msg_info->msg_index);
  
  r = generic_cache_read(filename, &msg_content, &msg_length);
  if (r == MAIL_NO_ERROR) {
    msg = msg_info->msg_data;

    msg->msg_message = msg_content;
    msg->msg_length = msg_length;

    return MAIL_NO_ERROR;
  }

  /* we get the message through the network */

  r = nntpdriver_article(get_ancestor_session(msg_info),
      msg_info->msg_index, &msg_content,
      &msg_length);

  if (r != MAIL_NO_ERROR)
    return r;

  /* we write the message cache */

  generic_cache_store(filename, msg_content, msg_length);

  msg = msg_info->msg_data;

  msg->msg_message = msg_content;
  msg->msg_length = msg_length;

  return MAIL_NO_ERROR;
}
예제 #3
0
static int nntp_get_flags(mailmessage * msg_info,
    struct mail_flags ** result)
{
  int r;
  struct mail_flags * flags;
  struct mail_cache_db * cache_db_flags;
  char filename_flags[PATH_MAX];
  int res;
  MMAPString * mmapstr;

  if (msg_info->msg_flags != NULL) {
    * result = msg_info->msg_flags;
    
    return MAIL_NO_ERROR;
  }

  flags = mail_flags_store_get(get_cached_session_data(msg_info)->nntp_flags_store, msg_info->msg_index);

  if (flags == NULL) {
    struct nntp_cached_session_state_data * cached_data;
    struct nntp_session_state_data * ancestor_data;
    
    cached_data = get_cached_session_data(msg_info);
    
    ancestor_data = get_ancestor_session_data(msg_info);
    if (ancestor_data->nntp_group_name == NULL) {
      res = MAIL_ERROR_BAD_STATE;
      goto err;
    }
    
    snprintf(filename_flags, PATH_MAX, "%s/%s/%s",
        cached_data->nntp_flags_directory,
        ancestor_data->nntp_group_name, FLAGS_NAME);
    
    r = mail_cache_db_open_lock(filename_flags, &cache_db_flags);
    if (r < 0) {
      res = MAIL_ERROR_FILE;
      goto err;
    }
    
    mmapstr = mmap_string_new("");
    if (mmapstr == NULL) {
      res = MAIL_ERROR_MEMORY;
      goto close_db_flags;
    }
    
    r = nntpdriver_get_cached_flags(cache_db_flags, mmapstr,
        msg_info->msg_index, &flags);
    if (r != MAIL_NO_ERROR) {
      flags = mail_flags_new_empty();
      if (flags == NULL) {
	res = MAIL_ERROR_MEMORY;
	goto free_mmapstr;
      }
    }

    mmap_string_free(mmapstr);
    mail_cache_db_close_unlock(filename_flags, cache_db_flags);
  }

  msg_info->msg_flags = flags;

  * result = flags;

  return MAIL_NO_ERROR;

 free_mmapstr:
  mmap_string_free(mmapstr);
 close_db_flags:
  mail_cache_db_close_unlock(filename_flags, cache_db_flags);
 err:
  return res;
}
예제 #4
0
static inline newsnntp *
get_nntp_session(mailmessage * msg)
{
  return get_ancestor_session_data(msg)->nntp_session;
}
static inline struct mailmh_folder *
get_mh_cur_folder(mailmessage * msg)
{
  return get_ancestor_session_data(msg)->mh_cur_folder;
}
static inline struct mailmh *
get_mh_session(mailmessage * msg)
{
  return get_ancestor_session_data(msg)->mh_session;
}
static inline struct mailmbox_folder *
get_mbox_session(mailmessage * msg)
{
  return get_ancestor_session_data(msg)->mbox_folder;
}