Skip to content

Commit

Permalink
Add (some) name mapping to XML import. Add verified badge to HTML export
Browse files Browse the repository at this point in the history
  • Loading branch information
bepaald committed Jan 26, 2025
1 parent 36c441f commit 7fa4e98
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 19 deletions.
19 changes: 19 additions & 0 deletions arg/arg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ Arg::Arg(int argc, char *argv[])
d_selectxmlchats(std::vector<std::string>()),
d_linkify(true),
d_setchatcolors(std::vector<std::pair<long long int, std::string>>()),
d_mapxmlcontactnames(std::vector<std::pair<std::string, std::string>>()),
d_input_required(false)
{
// vector to hold arguments
Expand Down Expand Up @@ -1818,6 +1819,24 @@ bool Arg::parseArgs(std::vector<std::string> const &arguments)
}
continue;
}
if (option == "--mapxmlcontactnames")
{
if (i < argsize - 1)
{
std::string error;
if (!parsePairList(arguments[++i], "=", &d_mapxmlcontactnames, &error))
{
std::cerr << "[ Error parsing command line option `" << option << "': " << error << " ]" << std::endl;
ok = false;
}
}
else
{
std::cerr << "[ Error parsing command line option `" << option << "': Missing argument. ]" << std::endl;
ok = false;
}
continue;
}
if (option[0] != '-')
{
if (d_positionals >= 2)
Expand Down
9 changes: 8 additions & 1 deletion arg/arg.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
class Arg
{
bool d_ok;
std::array<std::string, 185> const d_alloptions{"-i", "--input", "-p", "--passphrase", "--importthreads", "--importthreadsbyname", "--limittothreads", "--limittothreadsbyname", "-o", "--output", "-op", "--opassphrase", "-s", "--source", "-sp", "--sourcepassphrase", "--croptothreads", "--croptothreadsbyname", "--croptodates", "--mergerecipients", "--mergegroups", "--exportcsv", "--exportxml", "--querymode", "--runsqlquery", "--runprettysqlquery", "--rundtsqlquery", "--rundtprettysqlquery", "--limitcontacts", "--assumebadframesizeonbadmac", "--no-assumebadframesizeonbadmac", "--editattachmentsize", "--dumpdesktopdb", "--desktopdir", "--desktopdirs", "--rawdesktopdb", "--desktopkey", "--showdesktopkey", "--no-showdesktopkey", "--dumpmedia", "--excludestickers", "--no-excludestickers", "--dumpavatars", "--devcustom", "--no-devcustom", "--importcsv", "--mapcsvfields", "--setselfid", "--onlydb", "--no-onlydb", "--overwrite", "--no-overwrite", "--listthreads", "--no-listthreads", "--listrecipients", "--no-listrecipients", "--showprogress", "--no-showprogress", "--removedoubles", "--reordermmssmsids", "--no-reordermmssmsids", "--stoponerror", "--no-stoponerror", "-v", "--verbose", "--no-verbose", "--dbusverbose", "--no-dbusverbose", "--strugee", "--strugee3", "--ashmorgan", "--no-ashmorgan", "--strugee2", "--no-strugee2", "--arc", "--deleteattachments", "--no-deleteattachments", "--onlyinthreads", "--onlyolderthan", "--onlynewerthan", "--onlylargerthan", "--onlytype", "--appendbody", "--prependbody", "--replaceattachments", "-h", "--help", "--no-help", "--scanmissingattachments", "--no-scanmissingattachments", "--showdbinfo", "--no-showdbinfo", "--scramble", "--no-scramble", "--importfromdesktop", "--no-importfromdesktop", "--limittodates", "--autolimitdates", "--no-autolimitdates", "--ignorewal", "--no-ignorewal", "--includemms", "--no-includemms", "--checkdbintegrity", "--no-checkdbintegrity", "--interactive", "--no-interactive", "--exporthtml", "--exportdesktophtml", "--exportplaintextbackuphtml", "--importplaintextbackup", "--addexportdetails", "--no-addexportdetails", "--includecalllog", "--no-includecalllog", "--includeblockedlist", "--no-includeblockedlist", "--includesettings", "--no-includesettings", "--includefullcontactlist", "--no-includefullcontactlist", "--themeswitching", "--no-themeswitching", "--searchpage", "--no-searchpage", "--stickerpacks", "--no-stickerpacks", "--includereceipts", "--no-includereceipts", "--chatfolders", "--no-chatfolders", "--allhtmlpages", "--split", "--split-by", "--originalfilenames", "--no-originalfilenames", "--addincompletedataforhtmlexport", "--no-addincompletedataforhtmlexport", "--importdesktopcontacts", "--no-importdesktopcontacts", "--light", "--no-light", "--exporttxt", "--exportdesktoptxt", "--append", "--no-append", "--desktopdbversion", "--migratedb", "--no-migratedb", "--importstickers", "--no-importstickers", "--findrecipient", "--importtelegram", "--listjsonchats", "--selectjsonchats", "--mapjsoncontacts", "--preventjsonmapping", "--jsonprependforward", "--no-jsonprependforward", "--jsonmarkdelivered", "--no-jsonmarkdelivered", "--jsonmarkread", "--no-jsonmarkread", "--xmlmarkdelivered", "--no-xmlmarkdelivered", "--xmlmarkread", "--no-xmlmarkread", "--fulldecode", "--no-fulldecode", "-l", "--logfile", "--custom_hugogithubs", "--no-custom_hugogithubs", "--truncate", "--no-truncate", "--skipmessagereorder", "--no-skipmessagereorder", "--migrate_to_191", "--no-migrate_to_191", "--mapxmlcontacts", "--listxmlcontacts", "--selectxmlchats", "--linkify", "--no-linkify", "--setchatcolors"};
std::array<std::string, 186> const d_alloptions{"-i", "--input", "-p", "--passphrase", "--importthreads", "--importthreadsbyname", "--limittothreads", "--limittothreadsbyname", "-o", "--output", "-op", "--opassphrase", "-s", "--source", "-sp", "--sourcepassphrase", "--croptothreads", "--croptothreadsbyname", "--croptodates", "--mergerecipients", "--mergegroups", "--exportcsv", "--exportxml", "--querymode", "--runsqlquery", "--runprettysqlquery", "--rundtsqlquery", "--rundtprettysqlquery", "--limitcontacts", "--assumebadframesizeonbadmac", "--no-assumebadframesizeonbadmac", "--editattachmentsize", "--dumpdesktopdb", "--desktopdir", "--desktopdirs", "--rawdesktopdb", "--desktopkey", "--showdesktopkey", "--no-showdesktopkey", "--dumpmedia", "--excludestickers", "--no-excludestickers", "--dumpavatars", "--devcustom", "--no-devcustom", "--importcsv", "--mapcsvfields", "--setselfid", "--onlydb", "--no-onlydb", "--overwrite", "--no-overwrite", "--listthreads", "--no-listthreads", "--listrecipients", "--no-listrecipients", "--showprogress", "--no-showprogress", "--removedoubles", "--reordermmssmsids", "--no-reordermmssmsids", "--stoponerror", "--no-stoponerror", "-v", "--verbose", "--no-verbose", "--dbusverbose", "--no-dbusverbose", "--strugee", "--strugee3", "--ashmorgan", "--no-ashmorgan", "--strugee2", "--no-strugee2", "--arc", "--deleteattachments", "--no-deleteattachments", "--onlyinthreads", "--onlyolderthan", "--onlynewerthan", "--onlylargerthan", "--onlytype", "--appendbody", "--prependbody", "--replaceattachments", "-h", "--help", "--no-help", "--scanmissingattachments", "--no-scanmissingattachments", "--showdbinfo", "--no-showdbinfo", "--scramble", "--no-scramble", "--importfromdesktop", "--no-importfromdesktop", "--limittodates", "--autolimitdates", "--no-autolimitdates", "--ignorewal", "--no-ignorewal", "--includemms", "--no-includemms", "--checkdbintegrity", "--no-checkdbintegrity", "--interactive", "--no-interactive", "--exporthtml", "--exportdesktophtml", "--exportplaintextbackuphtml", "--importplaintextbackup", "--addexportdetails", "--no-addexportdetails", "--includecalllog", "--no-includecalllog", "--includeblockedlist", "--no-includeblockedlist", "--includesettings", "--no-includesettings", "--includefullcontactlist", "--no-includefullcontactlist", "--themeswitching", "--no-themeswitching", "--searchpage", "--no-searchpage", "--stickerpacks", "--no-stickerpacks", "--includereceipts", "--no-includereceipts", "--chatfolders", "--no-chatfolders", "--allhtmlpages", "--split", "--split-by", "--originalfilenames", "--no-originalfilenames", "--addincompletedataforhtmlexport", "--no-addincompletedataforhtmlexport", "--importdesktopcontacts", "--no-importdesktopcontacts", "--light", "--no-light", "--exporttxt", "--exportdesktoptxt", "--append", "--no-append", "--desktopdbversion", "--migratedb", "--no-migratedb", "--importstickers", "--no-importstickers", "--findrecipient", "--importtelegram", "--listjsonchats", "--selectjsonchats", "--mapjsoncontacts", "--preventjsonmapping", "--jsonprependforward", "--no-jsonprependforward", "--jsonmarkdelivered", "--no-jsonmarkdelivered", "--jsonmarkread", "--no-jsonmarkread", "--xmlmarkdelivered", "--no-xmlmarkdelivered", "--xmlmarkread", "--no-xmlmarkread", "--fulldecode", "--no-fulldecode", "-l", "--logfile", "--custom_hugogithubs", "--no-custom_hugogithubs", "--truncate", "--no-truncate", "--skipmessagereorder", "--no-skipmessagereorder", "--migrate_to_191", "--no-migrate_to_191", "--mapxmlcontacts", "--listxmlcontacts", "--selectxmlchats", "--linkify", "--no-linkify", "--setchatcolors", "--mapxmlcontactnames"};
size_t d_positionals;
size_t d_maxpositional;
std::string d_progname;
Expand Down Expand Up @@ -164,6 +164,7 @@ class Arg
std::vector<std::string> d_selectxmlchats;
bool d_linkify;
std::vector<std::pair<long long int, std::string>> d_setchatcolors;
std::vector<std::pair<std::string, std::string>> d_mapxmlcontactnames;
bool d_input_required;
public:
Arg(int argc, char *argv[]);
Expand Down Expand Up @@ -300,6 +301,7 @@ class Arg
inline std::vector<std::string> const &selectxmlchats() const;
inline bool linkify() const;
inline std::vector<std::pair<long long int, std::string>> const &setchatcolors() const;
inline std::vector<std::pair<std::string, std::string>> const &mapxmlcontactnames() const;
inline bool input_required() const;
private:
template <typename T>
Expand Down Expand Up @@ -962,6 +964,11 @@ inline std::vector<std::pair<long long int, std::string>> const &Arg::setchatcol
return d_setchatcolors;
}

inline std::vector<std::pair<std::string, std::string>> const &Arg::mapxmlcontactnames() const
{
return d_mapxmlcontactnames;
}

inline bool Arg::input_required() const
{
return d_input_required;
Expand Down
2 changes: 1 addition & 1 deletion autoversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
#ifndef VERSION_H_
#define VERSION_H_

#define VERSIONDATE "20250126.112829"
#define VERSIONDATE "20250126.161438"

#endif
2 changes: 1 addition & 1 deletion main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ int main(int argc, char *argv[])
auto initPlaintextDatabase = [&](std::string const &xmlfile)
{
if (!ptdb)
ptdb.reset(new SignalPlaintextBackupDatabase(xmlfile, arg.truncate(), arg.verbose()));
ptdb.reset(new SignalPlaintextBackupDatabase(xmlfile, arg.truncate(), arg.verbose(), arg.mapxmlcontactnames()));
return ptdb->ok();
};

Expand Down
27 changes: 19 additions & 8 deletions signalbackup/htmlwrite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ bool SignalBackup::HTMLwriteStart(std::ofstream &file, long long int thread_reci
.shared-contact-avatar input[type=checkbox],
.msg-img-container input[type=checkbox],
.msg-linkpreview-img-container input[type=checkbox],
#thread-subtitle input[type=checkbox] {
.thread-subtitle input[type=checkbox] {
display: none;
}
Expand Down Expand Up @@ -1080,6 +1080,7 @@ bool SignalBackup::HTMLwriteStart(std::ofstream &file, long long int thread_reci
filter: var(--icon-f);
}
.thread-subtitle .msg-security-icon,
.msg-status .msg-security-icon {
background-image: url('data:image/svg+xml;utf-8,<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="white" stroke="none"><path d="M21.793,7.888A19.35,19.35 0,0 1,12 23C7.6,20.4 2,15.5 2,4.5 9,4.5 12,1 12,1s2.156,2.5 7.05,3.268L17.766,5.553A14.7,14.7 0,0 1,12 3,15.653 15.653,0 0,1 3.534,5.946c0.431,8.846 4.8,12.96 8.458,15.29A17.39,17.39 0,0 0,19.983 9.7ZM22.53,5.03 L21.47,3.97 12,13.439 8.53,9.97 7.47,11.03 12,15.561Z"/></svg>');
filter: var(--icon-f);
Expand Down Expand Up @@ -1168,6 +1169,7 @@ bool SignalBackup::HTMLwriteStart(std::ofstream &file, long long int thread_reci
.msg-status .msg-call-outgoing,
.msg-status .msg-info-icon,
.msg-status .msg-security-icon,
.thread-subtitle .msg-security-icon,
.msg-status .msg-pencil-icon,
.msg-status .msg-thread-icon,
.msg-status .msg-megaphone-icon,
Expand All @@ -1191,6 +1193,10 @@ bool SignalBackup::HTMLwriteStart(std::ofstream &file, long long int thread_reci
position: relative;
}
.thread-subtitle .msg-security-icon {
margin-right: 3px;
}
#menu {
display: flex;
flex-direction: column;
Expand Down Expand Up @@ -1447,19 +1453,19 @@ bool SignalBackup::HTMLwriteStart(std::ofstream &file, long long int thread_reci
padding-left: 1%;
}
#thread-subtitle input[type=checkbox]:checked ~ label > .groupdetails {
.thread-subtitle input[type=checkbox]:checked ~ label > .groupdetails {
max-height: none;
padding-top: 5px;
padding-bottom: 5px;
overflow: visible;
transition: padding-top 0.2s ease, padding-bottom 0.2s ease, max-height 0.4s ease;
}
#thread-subtitle input[type=checkbox] ~ label > small::before {
.thread-subtitle input[type=checkbox] ~ label > small::before {
content: '(show';
}
#thread-subtitle input[type=checkbox]:checked ~ label > small::before {
.thread-subtitle input[type=checkbox]:checked ~ label > small::before {
content: '(hide';
}
Expand All @@ -1482,7 +1488,7 @@ bool SignalBackup::HTMLwriteStart(std::ofstream &file, long long int thread_reci
display: none;
}
#thread-subtitle > label > small {
.thread-subtitle > label > small {
display: none;
}
Expand Down Expand Up @@ -1784,9 +1790,14 @@ file << R"(
file << "</pre>";
if (isnotetoself || isreleasechannel)
file << "<div class=\"official\"></div>";
file << R"(</div>
<div id="thread-subtitle">
)";
file << "</div>\n";
if (!isnotetoself && getRecipientInfoFromMap(recipient_info, thread_recipient_id).verified)
file <<
" <div class=\"thread-subtitle\">\n"
" <span class=\"msg-security-icon\"></span>verified\n"
" </div>\n";
file <<
" <div class=\"thread-subtitle\">\n";
if (isgroup)
{
file << groupmembers.size() << " member" << (groupmembers.size() != 1 ? "s" : "") << '\n';
Expand Down
6 changes: 4 additions & 2 deletions signalbackup/importfromplaintextbackup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ bool SignalBackup::importFromPlaintextBackup(std::unique_ptr<SignalPlaintextBack
SqliteDB::QueryResults pt_messages;
if (!ptdb->d_database.exec("SELECT "
"rowid, "
"date, type, read, body, contact_name, address, numattachments, COALESCE(sourceaddress, address) AS sourceaddress, numaddresses, ismms "
//", CONCAT(address, contact_name) AS identifier "
"date, type, read, body, contact_name, address, numattachments, COALESCE(sourceaddress, address) AS sourceaddress, numaddresses, ismms, skip "
"FROM smses" + datewhereclause + chatselectionclause + " ORDER BY date", &pt_messages))
return false;

Expand All @@ -134,6 +133,9 @@ bool SignalBackup::importFromPlaintextBackup(std::unique_ptr<SignalPlaintextBack
if (i % 100 == 0)
Logger::message_overwrite("Importing messages into backup... ", i, "/", pt_messages.rows());

if (pt_messages.valueAsInt(i, "skip") == 1) [[unlikely]]
continue;

std::string body = pt_messages(i, "body");
if (body.empty() && pt_messages.valueAsInt(i, "numattachments") <= 0)
{
Expand Down
7 changes: 6 additions & 1 deletion signalbackup/setrecipientinfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ void SignalBackup::setRecipientInfo(std::set<long long int> const &recipients,
(d_database.tableContainsColumn("recipient", "blocked") ? "blocked, " : "") +
(d_database.tableContainsColumn("recipient", "mention_setting") ? "mention_setting, " : "") +
(d_database.tableContainsColumn("recipient", "message_expiration_time") ? "message_expiration_time, " : "") +
"identities.verified, "
"recipient.wallpaper "
"FROM recipient "
"LEFT JOIN groups ON recipient.group_id = groups.group_id " +
"LEFT JOIN identities ON recipient." + d_recipient_aci + " = identities.address " +
(d_database.containsTable("distribution_list") ? "LEFT JOIN distribution_list ON recipient._id = distribution_list.recipient_id " : "") +
"WHERE recipient._id = ?",
rid, &results);
Expand Down Expand Up @@ -148,6 +150,8 @@ void SignalBackup::setRecipientInfo(std::set<long long int> const &recipients,
bool hasavatar = (std::find_if(d_avatars.begin(), d_avatars.end(),
[rid](auto const &p) { return p.first == bepaald::toString(rid); }) != d_avatars.end());

bool verified = (results.valueAsInt(0, "verified") == 1);

recipientinfo->emplace(rid, RecipientInfo{display_name,
initial,
initial_is_emoji,
Expand All @@ -162,7 +166,8 @@ void SignalBackup::setRecipientInfo(std::set<long long int> const &recipients,
color,
wall_light,
wall_dark,
hasavatar});
hasavatar,
verified});
}
}

Expand Down
1 change: 1 addition & 0 deletions signalbackup/signalbackup.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ class SignalBackup
std::string wall_light;
std::string wall_dark;
bool hasavatar;
bool verified;
};

static std::vector<DatabaseLink> const s_databaselinks;
Expand Down
Loading

0 comments on commit 7fa4e98

Please sign in to comment.