pulb / mailnag

An extensible mail notification daemon
GNU General Public License v2.0
250 stars 32 forks source link

Mailnag won't authenticate on first start #213

Open mecrider opened 3 years ago

mecrider commented 3 years ago

Running the latest mailnag and GNOME-Shell extension from the PPA on Ubuntu 20.04, mailnag fails to authenticate mail accounts until after I open Mailnag Settings and close it (I don't have to do anything while it is open). Both accounts are POP3 (one SSL and one not) using Dovecot on Ubuntu Server in my control. Here is the system log: -- Logs begin at Fri 2020-09-11 07:40:30 CDT, end at Fri 2020-09-11 07:46:41 CDT. -- Sep 11 07:45:58 itsuper mailnag[4704]: INFO (2020-09-11 07:45:58): Checking 2 email account(s). Sep 11 07:46:01 itsuper mailnag[4704]: ERROR (2020-09-11 07:46:01): Failed to open mailbox for account 'Michael' (b'-ERR [AUTH] Authentication failed.'). Sep 11 07:46:05 itsuper mailnag[4704]: ERROR (2020-09-11 07:46:05): Failed to open mailbox for account 'Intra' (b'-ERR [AUTH] Authentication failed.'). Sep 11 07:46:25 itsuper mailnag[4704]: INFO (2020-09-11 07:46:25): Shutting down... Sep 11 07:46:25 itsuper mailnag[4704]: INFO (2020-09-11 07:46:25): Polling thread exited successfully. Sep 11 07:46:25 itsuper mailnag[4704]: INFO (2020-09-11 07:46:25): Plugins disabled successfully. Sep 11 07:46:27 itsuper mailnag-config.desktop[8971]: Shutting down existing Mailnag process...INFO (2020-09-11 07:46:27): Successfully enabled plugin 'libnotifyplugin'. Sep 11 07:46:27 itsuper mailnag[8971]: INFO (2020-09-11 07:46:27): Successfully enabled plugin 'libnotifyplugin'. Sep 11 07:46:27 itsuper mailnag-config.desktop[8971]: INFO (2020-09-11 07:46:27): Checking 2 email account(s). Sep 11 07:46:27 itsuper mailnag[8971]: INFO (2020-09-11 07:46:27): Checking 2 email account(s). Sep 11 07:46:29 itsuper mailnag-config.desktop[8971]: DEBUG (2020-09-11 07:46:29): Couldn't get Message-ID from message. Sep 11 07:46:29 itsuper mailnag[8971]: DEBUG (2020-09-11 07:46:29): Couldn't get Message-ID from message.

poperigby commented 3 years ago

I'm having the same issue on ArchLinux. Here's my configuration: Swappshot Tue Jan 12 10:29:26 2021

Here's the output of mailnag:

INFO (2021-01-12 10:30:26): Successfully enabled plugin 'soundplugin'.
INFO (2021-01-12 10:30:26): Successfully enabled plugin 'libnotifyplugin'.
INFO (2021-01-12 10:30:26): Checking 1 email account(s).
ERROR (2021-01-12 10:30:30): Failed to open mailbox for account 'Mailbox' (b'[AUTHENTICATIONFAILED] Authentication failed.').
pulb commented 3 years ago

What mail provider are you using? If Gmail, please have a look at the troubleshooting section of the readme.

poperigby commented 3 years ago

I'm using mailbox.org. Forgot to specify that, sorry.

pulb commented 3 years ago

Did you already try one of the suggested solutions of the Gmail troubleshooting section? Esp. the goa plugin?

poperigby commented 3 years ago

I figured it out. My configuration was wrong. Sorry for the trouble.

niraami commented 3 years ago

I've got this same issue (and have had for a month now). I start mailnag via the .desktop file using dex on startup of my WM (i3), but I have to restart it, either by killing it, or by starting the configuration for it to actually start working.

The error is the same as described above in the previous comments, repeating every 5 minutes, nothing changes even after hours of runtime.

Apr 05 01:25:20 mia-arch mailnag[814]: INFO (2021-04-05 01:25:20): Successfully enabled plugin 'libnotifyplugin'.
Apr 05 01:25:20 mia-arch mailnag[814]: INFO (2021-04-05 01:25:20): Successfully enabled plugin 'userscriptplugin'.
Apr 05 01:25:20 mia-arch mailnag[814]: INFO (2021-04-05 01:25:20): Checking 1 email account(s).
Apr 05 01:25:22 mia-arch mailnag[814]: ERROR (2021-04-05 01:25:22): Failed to open mailbox for account '<REDACTED> (Gmail)' (b'Empty username or password. y19mb556476533wmm').
Apr 05 01:25:23 mia-arch mailnag[814]: ERROR (2021-04-05 01:25:23): Failed to open mailbox for account '<REDACTED> (Gmail)' (b'Empty username or password. g16mb528799895wmq').
Apr 05 01:25:23 mia-arch mailnag[814]: INFO (2021-04-05 01:25:23): Trying to reconnect Idler thread for account '<REDACTED> (Gmail)' in 5 minutes
Apr 05 01:30:23 mia-arch mailnag[814]: ERROR (2021-04-05 01:30:23): Failed to open mailbox for account '<REDACTED> (Gmail)' (b'Empty username or password. t12mb268542899wrn').
Apr 05 01:30:23 mia-arch mailnag[814]: INFO (2021-04-05 01:30:23): Trying to reconnect Idler thread for account '<REDACTED> (Gmail)' in 5 minutes

After restarting mailnag, everything is fine:

Apr 05 01:39:09 mia-arch mailnag[814]: INFO (2021-04-05 01:39:09): Shutting down...
Apr 05 01:39:10 mia-arch mailnag[814]: INFO (2021-04-05 01:39:10): Idler closed
Apr 05 01:39:10 mia-arch mailnag[814]: INFO (2021-04-05 01:39:10): Plugins disabled successfully.
Apr 05 01:39:11 mia-arch mailnag[6008]: INFO (2021-04-05 01:39:11): Successfully enabled plugin 'libnotifyplugin'.
Apr 05 01:39:11 mia-arch mailnag[6008]: INFO (2021-04-05 01:39:11): Successfully enabled plugin 'userscriptplugin'.
Apr 05 01:39:11 mia-arch mailnag[6008]: INFO (2021-04-05 01:39:11): Checking 1 email account(s).

As the password is stored in the keyring, I tried locking it, and then starting mailnag (manually & using the .desktop entry), but when it showed the prompt, and I entered my credentials, mailnag worked just fine. So I don't really know what else to try, can I help resolve this issue anyhow?

Mailnag version: Latest AUR package (mailnag 2.2.0)

pulb commented 3 years ago

@niraami thank you very much for this very detailed and helpful information. It looks like this is a keyring/libsecret issue. Maybe the keyring is not available via dbus right upon startup on your system or on non-gnome systems in general. Can you try to delay the startup of mailnag by a few seconds?

pulb commented 3 years ago

Or maybe try to run /usr/bin/gnome-keyring-daemon --daemonize --login in a script before starting mailnag.

pulb commented 3 years ago

if this fixes the issue i can try to make sure that the daemon is running in mailnag itself.

niraami commented 3 years ago

I'll try to delay the startup somehow, I'll have to look into how to do that though.

Or maybe try to run /usr/bin/gnome-keyring-daemon --daemonize --login in a script before starting mailnag.

This already should be the case, as the execution should be senquenced like this:

.xinitrc is executed on Xorg-server startup (after login), and indeed contains the line that you mention:

❯ cat ~/.xinitrc
if [ -d /etc/X11/xinit/xinitrc.d ] ; then
        for f in /etc/X11/xinit/xinitrc.d/?*.sh ; do
                [ -x "$f" ] && . "$f"
        done
        unset f
fi

# Start gnome-keyring daemon with extra components
eval $(/usr/bin/gnome-keyring-daemon --start -c pkcs11,secrets,ssh)
export SSH_AUTH_SOCK

xset -dpms
xset s off

exec i3

edit: actually looking at it again, I do not have the -d & -l parameters as you do, I'll see if those change anything, but I believe i did remove them manually for some reason a while back

In my i3 config, there is a section that then runs dex - this should execute all .desktop files in the ~/.config/autostart directory - which also includes mailnag.desktop

❯ cat ~/.config/i3/config
...
# Launch dex - this will in turn start all programs & applications
exec        --no-startup-id  dex -a

The contents of the .desktop file are as follows:

❯ cat ~/.config/autostart/mailnag.desktop

[Desktop Entry]
Name=Mailnag
Comment=An extensible mail notification daemon
Comment[de]=Ein erweiterbarer Mail-Benachrichtigungs-Dämon
Keywords=mail;notify;notification;
Exec=/usr/bin/mailnag --quiet
Icon=mailnag
Type=Application
NoDisplay=true
Categories=Network;Email;
X-GNOME-Autostart-enabled=true
X-GNOME-UsesNotifications=true
Categories=Network;Email;

I will try to add X-GNOME-Autostart-Delay to the .desktop, but I've got no idea if dex supports it. I'll also try a few more things and report back.

niraami commented 3 years ago

Unfortunately X-GNOME-Autostart-Delay didn't work, so I disabled dex on startup all together, and launched mailnag manually, and, even much later after startup, it still didn't work correctly. I believe it has something to do with the keyring not being unlocked, but also in a weird pre-initialized state or something. Here is the symptoms:

I've got no idea what the issue is... and I know that my explanation might be confusing, so feel free to ask for any clarification.
tbh this might be an issue in my setup, as I'm also having another keyring-related unexplainable issue. But the fact that other applications can prompt for keyring unlock on boot kinda disproves that. And the fact that even after the keyring is unlocked, mailnag fails to work correctly is definitely an issue.

Oh yeah, and the --daemonize & --login flags seemingly didn't do anything.

shejialuo commented 2 years ago

@niraami Hi, I am also using ArchLinux i3wm, you could solve this just simple change /usr/lib/python3.10/site-packages/Mailnag/common/secretstore.py's 40 line. Change Secret.SchemaFlags.NONE to Secret.SchemaFlags.DONT_MATCH_NAME. You can also see the PR.

mecrider commented 2 years ago

I discovered after submitting this bug that it does not affect most other users in our organization, so I decided it might be something unique to my configuration. However @shejialuo, after applying your change to my Ubuntu 20.04/GNOME workstation I have not had any further issues. Only difference was I installed from @pulb's PPA and the file was in /usr/lib/python3/dist-packages/Mailnag/common.