[pim/libkleo] src/utils: Simplify code for finding sender user ID

Ingo Klöcker <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit d441b1b0522d6b218d472b663be6a19ae13956ed by Ingo Klöcker, on behalf of Ingo Klöcker.
Committed on 23/07/2026 at 15:55.
Pushed by kloecker into branch 'master'.

Simplify code for finding sender user ID

We can safely assume that a not-null key always has a not-null primary
user ID.

GnuPG-bug-id: 7786

M  +3    -7    src/utils/formatting.cpp

https://invent.kde.org/pim/libkleo/-/commit/d441b1b0522d6b218d472b663be6a19ae13956ed

diff --git a/src/utils/formatting.cpp b/src/utils/formatting.cpp
index 5479137a..3d0f1fc6 100644
--- a/src/utils/formatting.cpp
+++ b/src/utils/formatting.cpp
@@ -1653,14 +1653,10 @@ QString Kleo::Formatting::prettySignature(const GpgME::Signature &sig, const QSt
     if (!sender.isEmpty()) {
         senderUid = findUserIDByMailbox(key, sender);
     }
-    if (senderUid.isNull()) {
-        for (int i = 0, count = key.userIDs().size(); i < count; i++) {
-            senderUid = key.userID(i);
-            if (!senderUid.isNull()) {
-                break;
-            }
-        }
+    if (senderUid.isNull() && !key.isNull()) {
+        senderUid = key.userID(0);
     }
+
     const QString text = formatSigningInformation(sig, key, senderUid) + QLatin1StringView("<br/>");
 
     // Green
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.