diff --git a/src/mu-cmd-index.c b/src/mu-cmd-index.c index dfd05b71..1d11c798 100644 --- a/src/mu-cmd-index.c +++ b/src/mu-cmd-index.c @@ -336,28 +336,46 @@ handle_index_error_and_free (GError *err) 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 cmd_index_or_cleanup (MuConfig *opts) { - gboolean rv; MuIndex *midx; MuIndexStats stats; - gboolean show_progress; - GError *err; - - if (!check_index_or_cleanup_params (opts) || - !database_version_check_and_update(opts)) - return MU_EXITCODE_ERROR; - - 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); + gboolean rv, show_progress; + MuExitCode code; + + /* create, and do error handling if needed */ + midx = init_mu_index (opts, &code); + if (!midx) + return code; /* we determine the maildir path only here, as it may depend on * mu_index_last_used_maildir diff --git a/src/mu-store.cc b/src/mu-store.cc index 58be103e..4fc485fa 100644 --- a/src/mu-store.cc +++ b/src/mu-store.cc @@ -449,26 +449,40 @@ add_terms_values (MuMsgFieldId mfid, MsgDoc* msgdoc) } +static const std::string* +xapian_pfx (MuMsgContact *contact) +{ + static const std::string to_pfx + (1, mu_msg_field_xapian_prefix(MU_MSG_FIELD_ID_TO)); + static const std::string from_pfx + (1, mu_msg_field_xapian_prefix(MU_MSG_FIELD_ID_FROM)); + static const std::string cc_pfx + (1, mu_msg_field_xapian_prefix(MU_MSG_FIELD_ID_CC)); + + /* use ptr to string to prevent copy... */ + switch (contact->type) { + case MU_MSG_CONTACT_TYPE_TO: + return &to_pfx; + case MU_MSG_CONTACT_TYPE_FROM: + return &from_pfx; + case MU_MSG_CONTACT_TYPE_CC: + return &cc_pfx; + default: /* dont;t support other type (e.g, bcc) */ + return 0; + } +} + + + static void each_contact_info (MuMsgContact *contact, MsgDoc *msgdoc) { - const std::string *pfxp; - static const std::string to_pfx (1, - mu_msg_field_xapian_prefix(MU_MSG_FIELD_ID_TO)); - static const std::string from_pfx (1, - mu_msg_field_xapian_prefix(MU_MSG_FIELD_ID_FROM)); - static const std::string cc_pfx (1, - mu_msg_field_xapian_prefix(MU_MSG_FIELD_ID_CC)); - /* use ptr to string to prevent copy... */ - switch (contact->type) { - case MU_MSG_CONTACT_TYPE_TO: pfxp = &to_pfx; break; - case MU_MSG_CONTACT_TYPE_FROM: pfxp = &from_pfx; break; - case MU_MSG_CONTACT_TYPE_CC: pfxp = &cc_pfx; break; - default: return; /* other types (like bcc) are ignored */ - } + const std::string *pfxp (xapian_pfx(contact)); + if (!pfxp) + return; /* unsupported contact type */ - if (contact->name && strlen(contact->name) > 0) { + if (contact->name && contact->name[0] != '\0') { Xapian::TermGenerator termgen; termgen.set_document (*msgdoc->_doc); char *norm = mu_str_normalize (contact->name, TRUE);