diff --git a/src/librmb/tools/rmb/rmb-commands.cpp b/src/librmb/tools/rmb/rmb-commands.cpp index 97371709..bb28d0c4 100644 --- a/src/librmb/tools/rmb/rmb-commands.cpp +++ b/src/librmb/tools/rmb/rmb-commands.cpp @@ -171,25 +171,43 @@ int RmbCommands::configuration(bool confirmed, librmb::RadosCephConfig &ceph_cfg bool RmbCommands::sort_uid(librmb::RadosMailObject *i, librmb::RadosMailObject *j) { std::string::size_type sz; // alias of size_t std::string t = i->get_metadata(librmb::RBOX_METADATA_MAIL_UID); - long i_uid = std::stol(t, &sz); - long j_uid = std::stol(j->get_metadata(librmb::RBOX_METADATA_MAIL_UID), &sz); - return i_uid < j_uid; + try { + long i_uid = std::stol(t, &sz); + long j_uid = std::stol(j->get_metadata(librmb::RBOX_METADATA_MAIL_UID), &sz); + return i_uid < j_uid; + } catch (std::exception &e) { + std::cerr << " sort_uid: " << t << "(" << i->get_oid() << ") or " << j->get_metadata(librmb::RBOX_METADATA_MAIL_UID) + << " (" << j->get_oid() << ") is not a number" << std::endl; + return false; + } } bool RmbCommands::sort_recv_date(librmb::RadosMailObject *i, librmb::RadosMailObject *j) { std::string::size_type sz; // alias of size_t std::string t = i->get_metadata(librmb::RBOX_METADATA_RECEIVED_TIME); - long i_uid = std::stol(t, &sz); - long j_uid = std::stol(j->get_metadata(librmb::RBOX_METADATA_RECEIVED_TIME), &sz); - return i_uid < j_uid; + try { + long i_uid = std::stol(t, &sz); + long j_uid = std::stol(j->get_metadata(librmb::RBOX_METADATA_RECEIVED_TIME), &sz); + return i_uid < j_uid; + } catch (std::exception &e) { + std::cerr << " sort_recv_date: " << t << " or " << j->get_metadata(librmb::RBOX_METADATA_RECEIVED_TIME) + << " is not a number" << std::endl; + return false; + } } bool RmbCommands::sort_phy_size(librmb::RadosMailObject *i, librmb::RadosMailObject *j) { std::string::size_type sz; // alias of size_t std::string t = i->get_metadata(librmb::RBOX_METADATA_PHYSICAL_SIZE); - long i_uid = std::stol(t, &sz); - long j_uid = std::stol(j->get_metadata(librmb::RBOX_METADATA_PHYSICAL_SIZE), &sz); - return i_uid < j_uid; + try { + long i_uid = std::stol(t, &sz); + long j_uid = std::stol(j->get_metadata(librmb::RBOX_METADATA_PHYSICAL_SIZE), &sz); + return i_uid < j_uid; + } catch (std::exception &e) { + std::cerr << " sort_physical_size: " << t << " or " << j->get_metadata(librmb::RBOX_METADATA_PHYSICAL_SIZE) + << " is not a number" << std::endl; + return false; + } } bool RmbCommands::sort_save_date(librmb::RadosMailObject *i, librmb::RadosMailObject *j) { @@ -273,7 +291,6 @@ int RmbCommands::print_mail(std::map *mailb std::cout << " error initializing output dir : " << output_dir << std::endl; break; } - for (std::vector::iterator it_mail = it->second->get_mails().begin(); it_mail != it->second->get_mails().end(); ++it_mail) { const std::string oid = (*it_mail)->get_oid(); diff --git a/src/storage-rbox/rbox-mail.cpp b/src/storage-rbox/rbox-mail.cpp index 5b84afe7..5db9f22c 100644 --- a/src/storage-rbox/rbox-mail.cpp +++ b/src/storage-rbox/rbox-mail.cpp @@ -390,8 +390,11 @@ static int rbox_mail_get_stream(struct mail *_mail, bool get_body ATTR_UNUSED, s return -1; } } else if (physical_size == 0) { - i_warning("trying to read a mail (size = 0) which is currently copied, moved or stored, returning with error. "); + i_error( + "trying to read a mail (size = 0) which is currently copied, moved or stored, returning with error. " + "expunging mail"); FUNC_END_RET("ret == 0"); + rbox_mail_set_expunged(rmail); return -1; } else if (physical_size == INT_MAX) { i_error("trying to read a mail with INT_MAX size. ");