Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic mailsync script readded/improved. Should actually work on *most* cron setups. #607

Closed
LukeSmithxyz opened this issue Dec 31, 2020 · 13 comments

Comments

@LukeSmithxyz
Copy link
Owner

LukeSmithxyz commented Dec 31, 2020

In f589cd4 I have added back the mailsync script with two main improvements:

  • It tries to find environmental variables manually.
  • It tries to find Xorg displays manually.

You can set mailsync as a cronjob now and it should actually work and display "New Mail" notifications without anything too funky. There have also been added options like mw -t 40 to set up an automatic sync as a cronjob every 40 minutes. This means that it actually should work and give notifications on many, I hope, most Linux machines (and I think it should still work with Mac).

Several things I am still doubtful about, so your help would be nice. I don't use soystemd obviously and things often work differently. I seem to remember systemd requiring a line like export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus to function with the cronjob, but this line breaks the functionality on runit. Systemd-users, please tell me what your experience is. The line is currently commented out. It will now run only on systemd machines.

@BachoSeven
Copy link
Contributor

@LukeSmithxyz
I'm on Arch with systemd, and I have gathered the following:

  • the export DBUS... line is needed with systemd in order to be able to actually display the notifications

  • a minor issue with mailsync's new method for finding environmental variables is indentation. For instance, I like to keep my export statements tabbed, and

eval `grep -h -- \
	"^\(export \)\?\(MBSYNCRC (...)

is failing because the export is not at the very beginning of the line, but indented.
Thus MBSYNCRC is not exported and mail cannot be synced with the cronjob. To fix this, the following works(simply added a check for eventual indentation with tabs OR spaces, this is where I got the trick for checking for tabs, which should be posix):

grep -h -- "^$(printf '\t')* *\(export \)\?\(MBSYNCRC (...)

@LukeSmithxyz
Copy link
Owner Author

Okay. In aa4fb99 I now have it check for systemd and run the DBUS line. I also changed the regex to match whitespace at the beginning of the variable export lines.

@nghiapq77
Copy link

displays="$(ps axo user,cmd | grep "^$USER\s\+.*Xorg" | grep -wo "[0-9]*:[0-9]\+")"

This line doesn't work for me. Have to substitute "$USER" with "root" or manually export $DISPLAY.
https://github.com/LukeSmithxyz/mutt-wizard/blob/master/bin/mailsync#L45

@LukeSmithxyz
Copy link
Owner Author

Your Xorg is running as root? What distro/WM are you using?

@nghiapq77
Copy link

Yes. I'm using Arch + dwm. I followed this link and set needs_root_rights = no in /etc/X11/Xwrapper.config and fixed it.

@LukeSmithxyz
Copy link
Owner Author

Okay. Since I assume that only one graphical user will be logged in at once, I suppose I could just remove the user specification and avoid this issue.

@Shane-XB-Qian
Copy link
Contributor

@LukeSmithxyz looks had some flaw in the notification script...

displays="$(pgrep -a Xorg | grep -wo "[0-9]*:[0-9]\+")"

e.g:
1042 /usr/lib/xorg/Xorg -core :0 -seat seat0 -auth /var/run/lightdm/root/:0 -nolisten tcp vt7 -novtswitch
displays was: :0 :0
looks dup and wrong result..

  1. from of messageinfo() looks was incorrect, massive irrelevant chars sent into notification message, a bit annoyed. (subject looks fine).

@Shane-XB-Qian
Copy link
Contributor

if difficult to parse messageinfo(), i think only notify() perhaps was good enough, since users can check mutt inside without notification message telling the new mail summary..

@LukeSmithxyz
Copy link
Owner Author

The from line is working fine for me. Could you show me the erroneous results?

I've push a commit that will fix your first issue.

@Shane-XB-Qian
Copy link
Contributor

i did not get that first awk, i think awk '/^From: .* \<.*\>$/' "$file" perhaps was ok ouough, then parse the third column of this output was the mail address of 'from'.

@Shane-XB-Qian
Copy link
Contributor

Shane-XB-Qian commented Jan 14, 2021

awk '/^From: .* \<.*\>$/' "$file" | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)' | awk '{ $1=""; if (NF>=3)$NF=""; print $0 }' | tr -d '"'
// something like this.. perhaps ok enough..

@Shane-XB-Qian
Copy link
Contributor

@LukeSmithxyz perhaps i mis-read your comment, but looks displays="$(pgrep -a Xorg | grep -wo "[0-9]*:[0-9]\+")" is your latest commit...
// as for 'from' of 'messageinfo', it's ok or whatever i can comment out at my local...

@Shane-XB-Qian
Copy link
Contributor

@Maugrift thx (#640) and fyi, now dup displays looks fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants