User Tools

Site Tools


user:sachy:lakatux

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
user:sachy:lakatux [2023/02/04 17:52] – external edit 127.0.0.1user:sachy:lakatux [2023/09/10 09:16] (current) – novy patch sachy
Line 209: Line 209:
  
 <code diff mutt_save_file_perm.patch> <code diff mutt_save_file_perm.patch>
---- PATCHES~    Mon Jul 27 21:36:10 CEST 2020 +diff -Naru /s/mutt-2.2.12/globals.h ./globals.h 
-+++ PATCHES     Mon Jul 27 21:36:10 CEST 2020 +--- /s/mutt-2.2.12/globals.h 2023-09-01 08:32:23.000000000 +0200 
-@@ -1,+@@ ++++ ./globals.h 2023-09-10 10:13:54.320014522 +0200 
-+patch.1.14.6.ms.sfp.1 +@@ -250,+250,8 @@ 
-diff /s/mutt-1.14.6/globals.h ./globals.h + WHERE short ScoreThresholdRead; 
-234a235 + WHERE short ScoreThresholdFlag; 
-> WHERE short SaveFilePerm; +  
-diff /s/mutt-1.14.6/init.h ./init.h ++WHERE short SaveFilePerm; 
-3138a3139,3143 +
-  { "save_file_perm", DT_NUM, R_NONE, {.p=&SaveFilePerm}, {.l=0600} }, + #ifdef USE_SIDEBAR 
->   /* + WHERE short SidebarWidth; 
->   ** This variable controls the permissions of saved attachments. + WHERE LIST *SidebarWhitelist; 
->   ** Use standard POSIX permissions in octal notation, i.e. 0644. +diff -Naru /s/mutt-2.2.12/init.h ./init.h 
->   */ +--- /s/mutt-2.2.12/init.h 2023-09-01 08:32:23.000000000 +0200 
-diff /s/mutt-1.14.6/main.c ./main.c ++++ ./init.h 2023-09-10 10:18:22.900015368 +0200 
-669c669,672 +@@ -3460,6 +3460,11 @@ 
-  umask (077); +   ** \fBNote:\fP This only applies to mbox and MMDF folders, Mutt does not 
---- +   ** delete MH and Maildir directories. 
->   if(SaveFilePerm==600) +   */ 
->     umask (077); ++  { "save_file_perm", DT_NUM, R_NONE, {.p=&SaveFilePerm}, {.l=0600} }, 
->   else ++  /* 
->     umask (000); ++  ** This variable controls the permissions of saved attachments. 
-diff /s/mutt-1.14.6/muttlib.c ./muttlib.c ++  ** Use standard POSIX permissions in octal notation, i.e. 0644. 
-2498a2499,2514 ++  */ 
-  /* Convert file permission from decadic to octal */ +   { "save_history",     DT_NUM,  R_NONE, {.p=&SaveHist}, {.l=0} }, 
->   unsigned short own=0; +   /* 
->   unsigned short grp=0; +   ** .pp 
->   unsigned short oth=0; +diff -Naru /s/mutt-2.2.12/main.c ./main.c 
->   unsigned short SFPoct=0; +--- /s/mutt-2.2.12/main.c 2023-09-01 08:32:23.000000000 +0200 
->   own=SaveFilePerm/100; ++++ ./main.c 2023-09-10 10:15:20.128014792 +0200 
->   grp=(SaveFilePerm-own*100)/10; +@@ -690,7 +690,10 @@ 
->   oth=SaveFilePerm-(own*100)-(grp*10); +   mutt_error = mutt_nocurses_error; 
->   if(own>7||grp>7||oth>7) +   mutt_message = mutt_nocurses_error; 
->   +   SRAND (time (NULL)); 
->     SFPoct=0600; +-  umask (077); 
->     dprint(1,(debugfile,"safe_open: Value %d is not valid octal permission mask.\n",SaveFilePerm)); ++  if(SaveFilePerm==600) 
->   ++    umask (077); 
->   else ++  else 
->     SFPoct=own<<6|grp<<3|oth; ++    umask (000); 
- +  
-2510c2526 +   memset (Options, 0, sizeof (Options)); 
-    if ((fd = open (mutt_b2s (safe_file), flags, 0600)) < 0) +   memset (QuadOptions, 0, sizeof (QuadOptions)); 
---- +diff -Naru /s/mutt-2.2.12/muttlib.c ./muttlib.c 
->     if ((fd = open (mutt_b2s (safe_file), flags, SFPoct)) < 0) +--- /s/mutt-2.2.12/muttlib.c 2023-08-18 05:03:18.000000000 +0200 
-2525c2541 ++++ ./muttlib.c 2023-09-10 10:36:18.872018760 +0200 
-  if ((fd = open (path, flags & ~O_EXCL, 0600)) < 0) +@@ -2562,6 +2562,22 @@ 
---- +   BUFFER *safe_file = NULL; 
->   if ((fd = open (path, flags & ~O_EXCL, SFPoct)) < 0)+   BUFFER *safe_dir = NULL; 
 +  
 ++  /* Convert file permission from decadic to octal */ 
 ++  unsigned short own=0; 
 ++  unsigned short grp=0; 
 ++  unsigned short oth=0; 
 ++  unsigned short SFPoct=0; 
 ++  own=SaveFilePerm/100; 
 ++  grp=(SaveFilePerm-own*100)/10; 
 ++  oth=SaveFilePerm-(own*100)-(grp*10); 
 ++  if(own>7||grp>7||oth>7) 
 ++  
 ++    SFPoct=0600; 
 ++    dprint(1,(debugfile,"safe_open: Value %d is not valid octal permission mask.\n",SaveFilePerm)); 
 ++  
 ++  else 
 ++    SFPoct=own<<6|grp<<3|oth; 
 ++ 
 +   if (flags & O_EXCL) 
 +   { 
 +     safe_file = mutt_buffer_pool_get (); 
 +@@ -2573,7 +2589,7 @@ 
 +       goto cleanup; 
 +     } 
 +  
 +-    if ((fd = open (mutt_b2s (safe_file), flags, 0600)) < 0) 
 ++    if ((fd = open (mutt_b2s (safe_file), flags, SFPoct)) < 0) 
 +     { 
 +       rmdir (mutt_b2s (safe_dir)); 
 +       goto cleanup; 
 +@@ -2588,7 +2604,7 @@ 
 +     } 
 +   
 +  
 +-  if ((fd = open (path, flags & ~O_EXCL, 0600)) < 0) 
 ++  if ((fd = open (path, flags & ~O_EXCL, SFPoct)) < 0) 
 +     goto cleanup; 
 +  
 +   /* make sure the file is not symlink */
 </code> </code>
  
Line 985: Line 1023:
   View=%view{ascii} prettyjson.py %f 2>&1   View=%view{ascii} prettyjson.py %f 2>&1
 </code> </code>
 +
 +
 +===== mutt vs Oauth2 =====
 +
 +Oauth2 protocol is more and more popular auth mechanism, so mutt - as the least wrong mail client - have support too. Yet the support is a bit tricky...
 +
 +First, download [[https://gitlab.com/muttmua/mutt/-/blob/master/contrib/mutt_oauth2.py|mutt_oauth2.py]] to the .mutt/ and read [[https://gitlab.com/muttmua/mutt/-/blob/master/contrib/mutt_oauth2.py.README|official README]].
 +
 +Then generate new PGP key for encryption of the Oauth secrets. "gpg --gen-key". Set the name/email to something mutty, like "mutt@mutt.mutt" to clearly distinguish it and never use in daily life. Also --edit-key to set neverending validity (default one year).
 +
 +Edit the downloaded mutt_oauth2.py and change the following:
 +
 +<code python>
 +ENCRYPTION_PIPE = ['gpg', '--encrypt', '--recipient', 'mutt@mutt.mutt'] # the name of the gpgkey in last param
 +...
 +'client_id': '9e5f94bc-e8a4-4e73-b8be-63364c29d753', # generic client_id for Thunderbird. Valid (almost?) everywhere
 +</code>
 +
 +If you want to use your own client_id, search faculty/company/google/MS support for help how to create one.
 +
 +Make first contact:
 +<code bash>
 +./mutt_oauth2.py LOGIN_NAME@DOMAIN.tokens --verbose --authorize # Just a file keeping the secrets...
 +</code>
 +
 +Follow the instructions, I recommend to pick "authcode" when asked. Copy generated URL (whole!!!) to the browser (with JS), accept all permissions for Thunderbird (remember the fake client-id we used?) and blank page will appear. DO NOT PANIC!
 +
 +Copy the whole URL to text editor and copy out the content of code= parameter back to the mutt_oauth2 prompt. Its long, invalid, base64 stuff ending prior "&session_state=". Example:
 +
 +<code>
 +0.AQIABsRF82hSsEOxn1hi-mgz-LyUX56k6HNOuL5j-LOTOFGARBAGE-REALLYLOTOFGARBAGE-EVENMOREGARBAGE-vUFlgHtUs6n5bmmRQgQ7AMH8zojnZWycMA
 +</code>
 +
 +Be sure not to copy newlines from vim/nano. Its one string, no newlines. NO NEWLINES!
 +
 +If done correctly, the script will respond:
 +<code>
 +Exchanging the authorization code for an access token
 +NOTICE: Obtained new access token, expires 2023-03-23T12:30:00.00000.
 +Access Token: lot-of-garbage
 +</code>
 +
 +Now is time to test the Oauth2 SMTP/IMAP connection:
 +<code>
 +$ /mutt_oauth2.py LOGIN_NAME@DOMAIN.tokens --verbose --test # the token file
 +Access Token: garbage...
 +IMAP authentication succeeded
 +POP authentication succeeded
 +SMTP authentication succeeded
 +</code>
 +
 +Good, the last thing is to edit the .mutt/muttrc (use your provider instead of Utlouk)
 +
 +<code muttrc>
 +set imap_user="userid@myschool.edu"
 +set folder="imap://outlook.office365.com/"
 +set smtp_url="smtp://${imap_user}@smtp.office365.com:587/"
 +set imap_authenticators="oauthbearer:xoauth2"
 +set imap_oauth_refresh_command="/home/USER/.mutt/mutt_oauth2.py /home/USER/.mutt/LOGIN_NAME@DOMAIN.tokens"
 +set smtp_authenticators=${imap_authenticators}
 +set smtp_oauth_refresh_command=${imap_oauth_refresh_command}
 +</code>
 +
 +If you have setup for more mailboxes, dont forget to clean the setting for all the others:
 +
 +<code muttrc>
 +# reset Oauth2 to normal
 +set imap_authenticators="gssapi:digest:cram-md5:sasl-ir:login"
 +set imap_oauth_refresh_command=""
 +set smtp_authenticators=${imap_authenticators}
 +set smtp_oauth_refresh_command=""
 +</code>
 +
 +
  
user/sachy/lakatux.1675533137.txt.gz · Last modified: 2023/02/04 17:52 by 127.0.0.1