Re: Macro variable with current folder name?

2023-03-11 Thread José María Mateos

On Sat, Mar 11, 2023 at 07:30:13PM +0100, Dennis Preiser wrote:

When I use the following macro inside the folder-hook (I don't have
offlineimap)

macro index,pager G "!/bin/echo $record\n"; \


Ok, found the issue. The problem is that the folder name contains '=' 
(as in =INBOX) and for folders also '/' (as in =mutt/). These characters 
need to be removed or offlineimap, understandably, doesn't understand 
what folder I'm talking about.


This is the end solution (which works for my folder structure, other 
people might need a different sanitizing function):


folder-hook . 'set my_record=$record; \
   set record=^; \
   macro index,pager G "!offlineimap -o -l /tmp/offlineimap.log -f 
$(echo $record | sed -e 's/[=\/]//g')\n" \
"Retrieve new IMAP messages for current folder"; \
   set record=$my_record'

Thanks a lot for your help.

--
José María (Chema) Mateos || https://rinzewind.org


Re: Macro variable with current folder name?

2023-03-11 Thread Dennis Preiser
On Sat, Mar 11, 2023 at 07:30:13PM +0100, Dennis Preiser wrote:
> Just to be sure: You don't have another macro "macro index,pager G ..."
> behind the folder-hook?

This question is nonsense, the folder hook would overwrite it.

Dennis


Re: Macro variable with current folder name?

2023-03-11 Thread Dennis Preiser
On Sat, Mar 11, 2023 at 01:05:13PM -0500, José María Mateos wrote:
> On Sat, Mar 11, 2023 at 06:15:14PM +0100, Dennis Preiser wrote:
>> 
>> folder-hook . 'set my_record=$record; \
>> set record=^; \
>> macro index,pager G "echo $record"; \
>> set record=$my_record'
> 
> Thanks for your suggestion. I tried this:
> 
> folder-hook . 'set my_record=$record; \
> set record=^; \
> macro index,pager G "!offlineimap -o -l /tmp/offlineimap.log -f $record\n" \
> "Retrieve new IMAP messages for current folder"; \
> set record=$my_record'
> 
> However, I got an error that leads me to think that the parameter $record is
> not being received on the other side. Perhaps I should surround the variable
> name with something so that the shell recognizes it?

When I use the following macro inside the folder-hook (I don't have
offlineimap)

macro index,pager G "!/bin/echo $record\n"; \

and then press G in my inbox I got

| =INBOX.INBOX
| Press any key to continue...

Just to be sure: You don't have another macro "macro index,pager G ..."
behind the folder-hook?

Dennis


Re: Macro variable with current folder name?

2023-03-11 Thread José María Mateos

On Sat, Mar 11, 2023 at 06:15:14PM +0100, Dennis Preiser wrote:


folder-hook . 'set my_record=$record; \
  set record=^; \
  macro index,pager G "echo $record"; \
  set record=$my_record'


Thanks for your suggestion. I tried this:

folder-hook . 'set my_record=$record; \
   set record=^; \
   macro index,pager G "!offlineimap -o -l /tmp/offlineimap.log -f 
$record\n" \
"Retrieve new IMAP messages for current folder"; \
   set record=$my_record'

However, I got an error that leads me to think that the parameter 
$record is not being received on the other side. Perhaps I should 
surround the variable name with something so that the shell recognizes 
it?


Thanks again!

--
José María (Chema) Mateos || https://rinzewind.org


Re: Macro variable with current folder name?

2023-03-11 Thread Dennis Preiser
On Sat, Mar 11, 2023 at 09:19:22AM -0500, José María Mateos wrote:
> I have this macro:
> 
> macro index,pager G "!offlineimap -o -l /tmp/offlineimap.log\n" "Retrieve new 
> IMAP messages"
> 
> It works well, but I typically use only for =INBOX, so checking all the
> folders (the default behaviour) is a waste. I've been trying to find if
> there's any way to pass only the current folder name in the macro. Something
> like
> 
> macro index,pager G "!offlineimap -o -l /tmp/offlineimap.log -f 
> $FOLDER_NAME\n"
> 
> I haven't been able to find anything like that. I've found some old
> solutions online[1] but they look slightly cumbersome; I'd like to set up
> just one macro, not several (I could have one for the INBOX and another one
> for all folders, though, but still, it's two macros). Also, they're old
> responses, and mutt has changed since then.

There is a "current mailbox" shortcut '^'. However, this expands only
for mailbox variables. You could use $record temporarily for the macro
and then set it back to the old value (here with echo to see what ends
up in the variable):

folder-hook . 'set my_record=$record; \
   set record=^; \
   macro index,pager G "echo $record"; \
   set record=$my_record'

Dennis