Gnus development mailing list
 help / color / mirror / Atom feed
* download attachment and do chmod for certain files
@ 2020-12-15 22:23 Emanuel Berg
  2020-12-16 18:00 ` Eric Abrahamsen
  0 siblings, 1 reply; 13+ messages in thread
From: Emanuel Berg @ 2020-12-15 22:23 UTC (permalink / raw)
  To: ding

Every time I get a photo (almost always a .jpg) and I get it
from the mail location and interface to where I like it on the
disk and with a proper filename, after that I have to do, e.g.,
'chmod +r photo.jpg'.

How would you automate this for certain files, say *.jpg ?

So basically if photo.jpg, then chmod +r photo.jpg ?

Non-trivial question I guess, so extra hacker points for
a solution :)

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: download attachment and do chmod for certain files
  2020-12-15 22:23 download attachment and do chmod for certain files Emanuel Berg
@ 2020-12-16 18:00 ` Eric Abrahamsen
  2020-12-16 18:08   ` Eric Abrahamsen
  2020-12-16 18:20   ` Adam Sjøgren
  0 siblings, 2 replies; 13+ messages in thread
From: Eric Abrahamsen @ 2020-12-16 18:00 UTC (permalink / raw)
  To: ding

Emanuel Berg <moasenwood@zoho.eu> writes:

> Every time I get a photo (almost always a .jpg) and I get it
> from the mail location and interface to where I like it on the
> disk and with a proper filename, after that I have to do, e.g.,
> 'chmod +r photo.jpg'.
>
> How would you automate this for certain files, say *.jpg ?
>
> So basically if photo.jpg, then chmod +r photo.jpg ?
>
> Non-trivial question I guess, so extra hacker points for
> a solution :)

The "MIME Commands" part of the Gnus manual mentions the
`gnus-article-mime-part-function' variable (which holds a function) --
if you look at the description of that, the example usage is very
close to yours.

What I'm a little confused about is that this would run automatically
*every time you open the message*. This seems fairly inefficient -- I
think in normal mail usage it's very common for users to open messages
multiple times. So whatever function you wrote for that would maybe want
to check somehow if the images had already been saved.

I expected there would be some sort of "save MIME handle alist" thing
where you could have it automatically kick in when you saved an image,
but I didn't immediately see anything like that. I've studiously avoided
learning anything about Gnus' MIME handling over the years.

The other solution that comes to mind is using "pipe to part" ("K |"),
and piping the images to your own shell script that saves the image and
does the chmod.

Hope something in there is helpful.

Eric



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: download attachment and do chmod for certain files
  2020-12-16 18:00 ` Eric Abrahamsen
@ 2020-12-16 18:08   ` Eric Abrahamsen
  2020-12-16 18:20   ` Adam Sjøgren
  1 sibling, 0 replies; 13+ messages in thread
From: Eric Abrahamsen @ 2020-12-16 18:08 UTC (permalink / raw)
  To: ding

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> Emanuel Berg <moasenwood@zoho.eu> writes:
>
>> Every time I get a photo (almost always a .jpg) and I get it
>> from the mail location and interface to where I like it on the
>> disk and with a proper filename, after that I have to do, e.g.,
>> 'chmod +r photo.jpg'.
>>
>> How would you automate this for certain files, say *.jpg ?
>>
>> So basically if photo.jpg, then chmod +r photo.jpg ?
>>
>> Non-trivial question I guess, so extra hacker points for
>> a solution :)
>
> The "MIME Commands" part of the Gnus manual mentions the
> `gnus-article-mime-part-function' variable (which holds a function) --
> if you look at the description of that, the example usage is very
> close to yours.
>
> What I'm a little confused about is that this would run automatically
> *every time you open the message*. This seems fairly inefficient -- I
> think in normal mail usage it's very common for users to open messages
> multiple times. So whatever function you wrote for that would maybe want
> to check somehow if the images had already been saved.
>
> I expected there would be some sort of "save MIME handle alist" thing
> where you could have it automatically kick in when you saved an image,
> but I didn't immediately see anything like that. I've studiously avoided
> learning anything about Gnus' MIME handling over the years.
>
> The other solution that comes to mind is using "pipe to part"

sorry, "pipe part", that was a typo.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: download attachment and do chmod for certain files
  2020-12-16 18:00 ` Eric Abrahamsen
  2020-12-16 18:08   ` Eric Abrahamsen
@ 2020-12-16 18:20   ` Adam Sjøgren
  2020-12-16 18:33     ` Eric Abrahamsen
                       ` (2 more replies)
  1 sibling, 3 replies; 13+ messages in thread
From: Adam Sjøgren @ 2020-12-16 18:20 UTC (permalink / raw)
  To: ding

Eric writes:

> I expected there would be some sort of "save MIME handle alist" thing
> where you could have it automatically kick in when you saved an image,
> but I didn't immediately see anything like that.

There is a generic variable for setting the permissions of a saved
attachment, regardless of type:

,----[ C-h v mm-attachment-file-modes RET ]
| mm-attachment-file-modes is a variable defined in ‘mm-decode.el’.
| Its value is 420
| Original value was 384
| 
|   You can customize this variable.
|   This variable was introduced, or its default value was changed, in
|   version 22.1 of Emacs.
| 
| Documentation:
| Set the mode bits of saved attachments to this integer.
`----

It is used in the function mm-save-part-to-file, which could either be
replaced or advice'd to only have the permissions applied to specific
types of attachments.


  Best regards,

    Adam


P.S. (format "0%o" 420) → 0644 rw--r--r-, (format "0%o" 384) → 0600 rw------

-- 
 "But you have heard enough, now it is time for you         Adam Sjøgren
  to listen."                                          asjo@koldfront.dk



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: download attachment and do chmod for certain files
  2020-12-16 18:20   ` Adam Sjøgren
@ 2020-12-16 18:33     ` Eric Abrahamsen
  2020-12-18 13:19     ` Emanuel Berg
  2020-12-18 21:16     ` Emanuel Berg
  2 siblings, 0 replies; 13+ messages in thread
From: Eric Abrahamsen @ 2020-12-16 18:33 UTC (permalink / raw)
  To: ding

Adam Sjøgren <asjo@koldfront.dk> writes:

> Eric writes:
>
>> I expected there would be some sort of "save MIME handle alist" thing
>> where you could have it automatically kick in when you saved an image,
>> but I didn't immediately see anything like that.
>
> There is a generic variable for setting the permissions of a saved
> attachment, regardless of type:
>
> ,----[ C-h v mm-attachment-file-modes RET ]
> | mm-attachment-file-modes is a variable defined in ‘mm-decode.el’.
> | Its value is 420
> | Original value was 384
> | 
> |   You can customize this variable.
> |   This variable was introduced, or its default value was changed, in
> |   version 22.1 of Emacs.
> | 
> | Documentation:
> | Set the mode bits of saved attachments to this integer.
> `----
>
> It is used in the function mm-save-part-to-file, which could either be
> replaced or advice'd to only have the permissions applied to specific
> types of attachments.

Excellent! In fact I glanced over this a second ago, when poking around
in the code, but somehow didn't tweak to the fact that this does exactly
what Emanuel is after.

Thanks,
Eric



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: download attachment and do chmod for certain files
  2020-12-16 18:20   ` Adam Sjøgren
  2020-12-16 18:33     ` Eric Abrahamsen
@ 2020-12-18 13:19     ` Emanuel Berg
  2020-12-18 21:16     ` Emanuel Berg
  2 siblings, 0 replies; 13+ messages in thread
From: Emanuel Berg @ 2020-12-18 13:19 UTC (permalink / raw)
  To: ding

Adam Sjøgren wrote:

> P.S. (format "0%o" 420) → 0644 rw--r--r-, (format "0%o" 384) → 0600 rw------

Thanks a lot, this last line saved me a lot of frustration,
couldn't figure out why 644 didn't work and what weird thing
384 was (the default value).

Yes, this works :)

PS. Maybe something to improve in the docstring? It just says
    "Set the mode bits of saved attachments to this integer."
    and I suppose, since you wrote that, I'm not the only one
    to then think of, e.g., 644 for rw--r--r-

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: download attachment and do chmod for certain files
  2020-12-16 18:20   ` Adam Sjøgren
  2020-12-16 18:33     ` Eric Abrahamsen
  2020-12-18 13:19     ` Emanuel Berg
@ 2020-12-18 21:16     ` Emanuel Berg
  2020-12-18 21:49       ` Andreas Schwab
  2 siblings, 1 reply; 13+ messages in thread
From: Emanuel Berg @ 2020-12-18 21:16 UTC (permalink / raw)
  To: ding

Adam Sjøgren wrote:

> P.S. (format "0%o" 420) → 0644 rw--r--r- [...]

$ echo $(( 4*8**0 + 4*8**1 + 6*8**2 )) # 420

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: download attachment and do chmod for certain files
  2020-12-18 21:16     ` Emanuel Berg
@ 2020-12-18 21:49       ` Andreas Schwab
  2020-12-18 22:36         ` Emanuel Berg
  2020-12-18 22:38         ` Emanuel Berg
  0 siblings, 2 replies; 13+ messages in thread
From: Andreas Schwab @ 2020-12-18 21:49 UTC (permalink / raw)
  To: ding

On Dez 18 2020, Emanuel Berg wrote:

> Adam Sjøgren wrote:
>
>> P.S. (format "0%o" 420) → 0644 rw--r--r- [...]
>
> $ echo $(( 4*8**0 + 4*8**1 + 6*8**2 )) # 420

$ echo $((0644))

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: download attachment and do chmod for certain files
  2020-12-18 21:49       ` Andreas Schwab
@ 2020-12-18 22:36         ` Emanuel Berg
  2020-12-18 22:55           ` Jason L Tibbitts III
  2020-12-18 22:38         ` Emanuel Berg
  1 sibling, 1 reply; 13+ messages in thread
From: Emanuel Berg @ 2020-12-18 22:36 UTC (permalink / raw)
  To: ding

Andreas Schwab wrote:

>>> P.S. (format "0%o" 420) → 0644 rw--r--r- [...]
>>
>> $ echo $(( 4*8**0 + 4*8**1 + 6*8**2 )) # 420
>
> $ echo $((0644))

Okay?

$ echo $((0644)) # 644

in zsh 5.7.1 (x86_64-debian-linux-gnu)

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: download attachment and do chmod for certain files
  2020-12-18 21:49       ` Andreas Schwab
  2020-12-18 22:36         ` Emanuel Berg
@ 2020-12-18 22:38         ` Emanuel Berg
  2020-12-18 22:47           ` Emanuel Berg
  1 sibling, 1 reply; 13+ messages in thread
From: Emanuel Berg @ 2020-12-18 22:38 UTC (permalink / raw)
  To: ding

Andreas Schwab wrote:

>>> P.S. (format "0%o" 420) → 0644 rw--r--r- [...]
>>
>> $ echo $(( 4*8**0 + 4*8**1 + 6*8**2 )) # 420
>
> $ echo $((0644))

Ah, in bash it works!

$ echo $(( 0644 )) # 420

Cool :)

GNU bash, version 5.0.3(1)-release (x86_64-pc-linux-gnu)

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: download attachment and do chmod for certain files
  2020-12-18 22:38         ` Emanuel Berg
@ 2020-12-18 22:47           ` Emanuel Berg
  2020-12-21  9:06             ` Eric S Fraga
  0 siblings, 1 reply; 13+ messages in thread
From: Emanuel Berg @ 2020-12-18 22:47 UTC (permalink / raw)
  To: ding

Emanuel Berg wrote:

>>>> P.S. (format "0%o" 420) → 0644 rw--r--r- [...]
>>>
>>> $ echo $(( 4*8**0 + 4*8**1 + 6*8**2 )) # 420
>>
>> $ echo $((0644))
>
> Ah, in bash it works!
>
> $ echo $(( 0644 )) # 420
>
> Cool :)
>
> GNU bash, version 5.0.3(1)-release (x86_64-pc-linux-gnu)

in zsh:

$ echo $(( 8#644 )) # 420

zsh 5.7.1 (x86_64-debian-linux-gnu)

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: download attachment and do chmod for certain files
  2020-12-18 22:36         ` Emanuel Berg
@ 2020-12-18 22:55           ` Jason L Tibbitts III
  0 siblings, 0 replies; 13+ messages in thread
From: Jason L Tibbitts III @ 2020-12-18 22:55 UTC (permalink / raw)
  To: ding

>>>>> "EB" == Emanuel Berg <moasenwood@zoho.eu> writes:

EB> Andreas Schwab wrote:
>>>> P.S. (format "0%o" 420) → 0644 rw--r--r- [...]
>>> 
>>> $ echo $(( 4*8**0 + 4*8**1 + 6*8**2 )) # 420
>> 
>> $ echo $((0644))

EB> Okay?

EB> $ echo $((0644)) # 644

EB> in zsh 5.7.1 (x86_64-debian-linux-gnu)

Totally offtopic, I know, but.... "setopt OCTAL_ZEROES" if you want that
behavior.

 - J<


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: download attachment and do chmod for certain files
  2020-12-18 22:47           ` Emanuel Berg
@ 2020-12-21  9:06             ` Eric S Fraga
  0 siblings, 0 replies; 13+ messages in thread
From: Eric S Fraga @ 2020-12-21  9:06 UTC (permalink / raw)
  To: ding

On Friday, 18 Dec 2020 at 23:47, Emanuel Berg wrote:
> $ echo $(( 8#644 )) # 420

Given that we are talking about a tool in Emacs, start up Calc and type
8#644.  No need for any external tools!

-- 
Eric S Fraga via Emacs 28.0.50 & org 9.4.3 on Debian bullseye/sid



^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-12-21  9:07 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-15 22:23 download attachment and do chmod for certain files Emanuel Berg
2020-12-16 18:00 ` Eric Abrahamsen
2020-12-16 18:08   ` Eric Abrahamsen
2020-12-16 18:20   ` Adam Sjøgren
2020-12-16 18:33     ` Eric Abrahamsen
2020-12-18 13:19     ` Emanuel Berg
2020-12-18 21:16     ` Emanuel Berg
2020-12-18 21:49       ` Andreas Schwab
2020-12-18 22:36         ` Emanuel Berg
2020-12-18 22:55           ` Jason L Tibbitts III
2020-12-18 22:38         ` Emanuel Berg
2020-12-18 22:47           ` Emanuel Berg
2020-12-21  9:06             ` Eric S Fraga

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).