* fix mu-cmd-index.c, mu-store.c to honor line33

This commit is contained in:
Dirk-Jan C. Binnema
2011-03-02 23:03:24 +02:00
parent 01c9410d0f
commit 0bc10837fe
2 changed files with 63 additions and 31 deletions

View File

@ -336,28 +336,46 @@ handle_index_error_and_free (GError *err)
return code; return code;
} }
static MuIndex*
init_mu_index (MuConfig *opts, MuExitCode *code)
{
MuIndex *midx;
GError *err;
if (!check_index_or_cleanup_params (opts) ||
!database_version_check_and_update(opts)) {
*code = MU_EXITCODE_ERROR;
return NULL;
}
err = NULL;
midx = mu_index_new (mu_runtime_xapian_dir(),
mu_runtime_contacts_cache_file(),
&err);
if (!midx) {
*code = handle_index_error_and_free (err);
return NULL;
}
mu_index_set_max_msg_size (midx, opts->max_msg_size);
mu_index_set_xbatch_size (midx, opts->xbatchsize);
return midx;
}
static MuExitCode static MuExitCode
cmd_index_or_cleanup (MuConfig *opts) cmd_index_or_cleanup (MuConfig *opts)
{ {
gboolean rv;
MuIndex *midx; MuIndex *midx;
MuIndexStats stats; MuIndexStats stats;
gboolean show_progress; gboolean rv, show_progress;
GError *err; MuExitCode code;
if (!check_index_or_cleanup_params (opts) || /* create, and do error handling if needed */
!database_version_check_and_update(opts)) midx = init_mu_index (opts, &code);
return MU_EXITCODE_ERROR; if (!midx)
return code;
err = NULL;
if (!(midx = mu_index_new (mu_runtime_xapian_dir(),
mu_runtime_contacts_cache_file(),
&err)))
return handle_index_error_and_free (err);
mu_index_set_max_msg_size (midx, opts->max_msg_size);
mu_index_set_xbatch_size (midx, opts->xbatchsize);
/* we determine the maildir path only here, as it may depend on /* we determine the maildir path only here, as it may depend on
* mu_index_last_used_maildir * mu_index_last_used_maildir

View File

@ -449,26 +449,40 @@ add_terms_values (MuMsgFieldId mfid, MsgDoc* msgdoc)
} }
static void static const std::string*
each_contact_info (MuMsgContact *contact, MsgDoc *msgdoc) xapian_pfx (MuMsgContact *contact)
{ {
const std::string *pfxp; static const std::string to_pfx
static const std::string to_pfx (1, (1, mu_msg_field_xapian_prefix(MU_MSG_FIELD_ID_TO));
mu_msg_field_xapian_prefix(MU_MSG_FIELD_ID_TO)); static const std::string from_pfx
static const std::string from_pfx (1, (1, mu_msg_field_xapian_prefix(MU_MSG_FIELD_ID_FROM));
mu_msg_field_xapian_prefix(MU_MSG_FIELD_ID_FROM)); static const std::string cc_pfx
static const std::string cc_pfx (1, (1, mu_msg_field_xapian_prefix(MU_MSG_FIELD_ID_CC));
mu_msg_field_xapian_prefix(MU_MSG_FIELD_ID_CC));
/* use ptr to string to prevent copy... */ /* use ptr to string to prevent copy... */
switch (contact->type) { switch (contact->type) {
case MU_MSG_CONTACT_TYPE_TO: pfxp = &to_pfx; break; case MU_MSG_CONTACT_TYPE_TO:
case MU_MSG_CONTACT_TYPE_FROM: pfxp = &from_pfx; break; return &to_pfx;
case MU_MSG_CONTACT_TYPE_CC: pfxp = &cc_pfx; break; case MU_MSG_CONTACT_TYPE_FROM:
default: return; /* other types (like bcc) are ignored */ return &from_pfx;
case MU_MSG_CONTACT_TYPE_CC:
return &cc_pfx;
default: /* dont;t support other type (e.g, bcc) */
return 0;
} }
}
if (contact->name && strlen(contact->name) > 0) {
static void
each_contact_info (MuMsgContact *contact, MsgDoc *msgdoc)
{
const std::string *pfxp (xapian_pfx(contact));
if (!pfxp)
return; /* unsupported contact type */
if (contact->name && contact->name[0] != '\0') {
Xapian::TermGenerator termgen; Xapian::TermGenerator termgen;
termgen.set_document (*msgdoc->_doc); termgen.set_document (*msgdoc->_doc);
char *norm = mu_str_normalize (contact->name, TRUE); char *norm = mu_str_normalize (contact->name, TRUE);