mautrix / imessage

A Matrix-iMessage puppeting bridge
https://go.mau.fi/mautrix-imessage/
GNU Affero General Public License v3.0
332 stars 36 forks source link

[bluebubbles] Incorrect contact returned by matchHandleToContact() in api.go #182

Closed alexmarkley closed 4 months ago

alexmarkley commented 4 months ago

This bug report applies to commit e1f79bc in the bluebubbles branch.

When I run this version of mautrix_imessage on my system, it loops through all of my conversations and sets every contact to same name

The root cause is line 728 in api.go.

While matchedContact is only set one time, it is set as a reference to c (defined on line 692). By the time the loop is finished, the contents of c will always be the last entry in the bb.contacts list.

My workaround for this issue (not a general solution):

diff --git a/imessage/bluebubbles/api.go b/imessage/bluebubbles/api.go
index 6fb6e4d..fe4636d 100644
--- a/imessage/bluebubbles/api.go
+++ b/imessage/bluebubbles/api.go
@@ -725,7 +725,8 @@ func (bb *blueBubbles) matchHandleToContact(address string) *Contact {

                // Contacts with a source type of "api" are stored on the mac and can be used as fallback in case an imported one isn't found
                if contact != nil && matchedContact == nil {
-                       matchedContact = contact
+                       return contact
+                       //matchedContact = contact
                }
        }

Sorry, I would come up with a PR, but I've never written any Go before. I poked at it for a bit, but I didn't get anywhere.

trek-boldly-go commented 4 months ago

The pointer issue was solved already, thanks for reporting!