Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

'Subscribe' to IMAP folders in with a proxy Apps
The following Perl IMAP proxy allows one to select which IMAP folders (or any other mail program) will see. This prevents from syncing an entire hierarchy if only certain folders are of interest. You'll need to edit the code to point the proxy at your IMAP server. You'll also need to edit the list of folders in the code.

Use at your own risk.

[robg adds: Due to the length of the script, I've uploaded it to the macosxhints server -- Click here to view the source in a new window. Note that I haven't tested this one at all!]
  • Currently 1.50 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)

'Subscribe' to IMAP folders in with a proxy | 20 comments | Create New Account
Click here to return to the ''Subscribe' to IMAP folders in with a proxy' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
'Subscribe' to IMAP folders in with a proxy
Authored by: ars on Apr 08, '04 07:20:17PM

This (i.e. subscription to slected IMAP folders), is a feature I wished for a long time. The only thing is: what do I do with this Perl script? Make it a start-up item? Run it everytime before launching Mail? Some ectra detail on how to use it would be welcome.

[ Reply to This | # ]
'Subscribe' to IMAP folders in with a proxy
Authored by: Cameroon on Apr 09, '04 06:55:51PM

After reading through the script, you should only need to run it at startup. You could certainly make it a startup item, or a cron job or just have it run via inetd.

All depends on what you're comfortable with ;)

[ Reply to This | # ]
'Subscribe' to IMAP folders in with a proxy
Authored by: sk4p on Apr 09, '04 10:10:35PM
Not only that but it looks like a bunch of backslashes necessary for this to even run have been stripped out ...

[ Reply to This | # ]
'Subscribe' to IMAP folders in with a proxy
Authored by: wackazong on Apr 13, '04 05:59:36AM

I would like to EXCLUDE certain folders from my list. With this script it is not possible, anybody know enought perl to modifiy it?

[ Reply to This | # ]
'Subscribe' to IMAP folders in with a proxy
Authored by: jonny5 on Apr 16, '04 10:58:55AM

There's a MUCH easier way to do this, no proxy needed.

In, go to:

Preferences... > Accounts > YOUR IMAP ACCOUNT

Then, in the box "IMAP Path Prefix", enter the name of your mail folder -- "mail" or whatever, you don't need $HOME, or ~ or anything like that.

I'm not sure, but I think if you want to "subscribe" to other folders, you may need to add an additional account with the same imap server settings in, and change the "IMAP Path Prefix" value


[ Reply to This | # ]
'Subscribe' to IMAP folders in with a proxy
Authored by: ars on Apr 17, '04 05:24:10PM

Your set-up might be different, but in my case when I specify:
as the path to my IMAP inbox, I get my inbox plus ALL my other mailfolders. The point of the above script is to get only a selection of those other mailboxes. I want some of those other mailboxes such as the Send folder, but I do not want all my other mail folders. Mail will try to synchronize with all of these other mailfolders every time it connects.
Most Imap clients let you subscribe or unsubscribe to these other IMAP folders, but not Apple's Mail. Moreover if you have no local mailbox Mail will list all of these folders separately and does not let you collapse them. I discovered by accident that if you create a local mailbox, that it will put all of those extra mailfolders in one mailbox, which you can collapse.

[ Reply to This | # ]
'Subscribe' to IMAP folders in with a proxy
Authored by: dschwar1 on May 04, '04 08:21:11PM

Very bizzarely, I managed to figure something out on my own instead of by reading something on Mac OS X Hints. No need to setup another account. If you want to 'subscribe' to multiple files in your IMAP folder, under IMAP path prefix separate the folders you wish to subscribe to with a semicolon. I.e.


Oddly this worked for me and now I can subscribe to only 2 folders.

[ Reply to This | # ]
"Use at own risk" Perl script from Anonymous? How risky is that?
Authored by: dzurn on May 25, '04 11:45:06AM

So if the script was submitted anonymously and also labelled "use at your own risk", how do we go about trusting this script? Especially a language like Perl which has obfuscation as a built-in feature.

The guy still puts his copyright credit in the script (no other contact info at all), but problems are not his fault. Credit but no responsibility?

Riiiight, lemme run that right away.

Madness takes its toll.
Please have exact change.

[ Reply to This | # ]
"Use at own risk" Perl script from Anonymous? How risky is that?
Authored by: carlivar on Jan 04, '06 02:58:49PM

The script is fine. It's not a mystery binary or something. If you're worried about it, read the whole thing and see what it does.

[ Reply to This | # ]
'Subscribe' to IMAP folders in with a proxy
Authored by: slchang on Jun 07, '05 07:50:57PM

There is an updated version of this script available at the author's website:

I've read over the script, both the old and the new, and believe it's perfectly non-malicious. The new version (on the author's site) is based on which folders you wish to exclude, rather than which ones you wish to subscribe to, which is helpful. I suggest that you use the new version of the script rather than the one linked here (the new one is easier to read and configure, and for whatever reason, the version linked here has some regex escaping problems). I've been running it for a few days on Tiger (10.4.1) and it works great. There's nothing fancy going on; I believe it would actually work fine on any version of OS X with the right perl modules.

You do need to tweak the script itself, with the regexes that specify the folders to exclude, as well as the hostname/port of your IMAP server.

If you need an SSL connection to your IMAP server, you will need to install the IO::Socket::SSL perl module, which in turn will require the Net::SSLeay module. You will probably need the Tiger dev tools (which come on the Tiger DVD) to build these.

If you aren't comfortable making simple tweaks to a perl script, or installing perl modules from the command line, this fix is probably not for you, though I can vouch that it works quite well.

[ Reply to This | # ]
'Subscribe' to IMAP folders in with a proxy
Authored by: larse on Sep 01, '05 04:44:45PM
I've put version 1.16 online at that fixes a bug with non-SSL connections to IMAP servers.

[ Reply to This | # ]
'Subscribe' to IMAP folders in with a proxy
Authored by: vogunaescht on Sep 24, '06 01:48:58AM

Hello Lars,
The version of available on your website identifies itself as 1.12, not 1.16.

[ Reply to This | # ]
'Subscribe' to IMAP folders in with a proxy
Authored by: binaryfeed on Jul 30, '05 12:37:01PM

The best way to *install* the proxy script is through login hooks:

sudo defaults write LoginHook /usr/local/bin/

This way, every time someone logs in, the script gets started for them automatically.

[ Reply to This | # ]
'Subscribe' to IMAP folders in with a proxy
Authored by: lazytiger on Oct 08, '05 09:04:16AM

Could someone please give some more specific instructions on how to use this script? I've downloaded it, put it in /usr/local/bin, tweaked it for my server settings (incorrectly?), inserted the folders I want hidden, did the:

sudo defaults write LoginHook /usr/local/bin/

on the command line, but it doesn't seem to be doing anything. What has to be done to activate this script or to figure out if it's misconfigured? I left the local server as "localhost:1143" and changed the remote host to "mail.(mydomain).com:143". There was some complication using this script with SSL, but my server doesn't even support SSL IMAP connections as far as I know. Can I ignore the stuff about IO::Socket::SSL? With running "sudo" in the command above, does that mean perhaps it's now working for the root user but no one else? Do you have to restart Mail? Log out and back in again? Reboot? (I've already done all those things to no avail, but for future reference.)

Please help! Thank you.

[ Reply to This | # ]
'Subscribe' to IMAP folders in with a proxy
Authored by: moritzh on Nov 08, '05 04:52:48PM

I'm using the newest version of the script (about a month old or so), but I have the following problem: After having running for a while (maybe 10 minutes) without any problems at all, the script suddenly goes crazy and consumes all the CPU power of the computer. I've doublechecked that it is indeed the script by looking at the Activity Monitor (it shows up as a process named "perl" in the list as it is a Perl script) and stopping/starting the script manually in the Terminal via "sudo". Strange enough, basically still functions, it (and everything else) is just very slow as the CPU is so busy. As soon as I quit, the CPU usage goes down to normal again. When I restart, same game: At first it's OK, but somewhen it goes crazy again.

Anybody any ideas? I have configured the script as a Startup Item, I connect via port 443 to localhost from which a SSL connection on port 993 goes to my actual mail server. I've set up to check for new mail every 5 minutes. To be sure, I have even told my keychain to lock itself only after a much longer time than 5 minutes (20 minutes) to make sure it has nothing to do with script lacking the required access to the password - but to no avail. At first I had the feeling that the problem went away when I selected some mailboxes on the IMAP server to cause a refresh or after manually entering the password, but this turned out to be an illusion.

I have contacted the author and asked about it, but he does not reply.

Ah yes, one more thing I guess I should mention: I have a firewall set up in stealth mode (the Mac OS X built-in firewall, that is). I can't remember for sure, but even though I have not opened port 443/993 on the firewall, I am quite positive that I did try opening these ports for testing but without success. I'm using Mac OS X 10.4.3 (but the problem has always been there, from 10.4.0 and some minor versions of before the current one - it's been there for as long as I've been using the script).

I'd very much appreciate some help as I really need the feature to `unsubscribe' from the houndreds of public folders with millions of messages on my university IMAP server. Thanks!

[ Reply to This | # ]
Correction: I use port 1143 instead of 443
Authored by: moritzh on Nov 08, '05 04:57:15PM

Small correction: I do use another port (1143) instead of 443 for the local connection to avoid coflicts with the standard port 443, I wrote 443 by mistake.

[ Reply to This | # ]
'Subscribe' to IMAP folders in with a proxy
Authored by: carlivar on Jan 10, '06 09:48:06PM

I've modified this script to do nothing but change IMAP LIST commands sent by to LSUB instead. LIST lists all folders; LSUB only lists subscribed folders. So, run Thunderbird or another email app to set your folder subscriptions, then use normally.

I've sent my changes to Lars and hopefully this will be a command-line option in his excellent script soon.

[ Reply to This | # ]
Could you share your script please?
Authored by: moritzh on Jan 20, '06 05:40:20PM

Excellent! Could you post the script, please? It is not yet integrated into the version available for download at the original author's website ( Thank you!

By the way, did you ever encounter the problem described in my previous post above?

[ Reply to This | # ]
update: it seems to be a bug in's implemtation of "Exchange server", not
Authored by: moritzh on May 22, '06 09:59:42AM

I spent hours trying everything I could think of before posting the above and `blaming', but of course I could only find the reason afterwards...

It seems to be a bug in's implementation of the "Exchange" account type. Reasons:
1) When I created a new account of type "IMAP" rather than "Exchange", either using or not, I could see all messages.
2) When I changed my existing "Exchange" account to an "IMAP" account, it worked too. (Note: You can't change it in the GUI. I made the change directly in the file. It's a bit ugly because you have to re-enter your username and password and you first get a prompt for user '(null)' etc., but it eventually worked for me.) And it stopped working again when I changed the "IMAP" account to an "Exchange" account.
3) Other steps (deleting cache files, deleting the local copies of the messages on the server, recreating the file "Envelope Index", rebuilding all mailboxes etc.) did not help.

Note: When you try do repeat anything I did like modify, ***make a backup of your entire ~/Library/Mail folder!***

P.S.: My server *is* an Exchange Server of course...
P.P.S.: Most of the messages I could not see in the beginning were mail delivery failure notifications from my mail system, *but not all*. There were also some `normal' messages in between.

[ Reply to This | # ]
Caution when using the described script!
Authored by: moritzh on May 22, '06 08:09:15AM

When using (running normally) instead of (running with the described for the first time after a long time, I discovered that there were more messages in my inbox than displayed in! I tried all sorts of things in like rebuilding mailboxes, deleting cache files, synchronizing the account, disabling message rules, but nothing fixed it.

Then I created another account in, this time omitting the local, and then the missing messages were also shown. I.e. then I had two accounts, one with and one without the, and the one without was showing all messages while the one with the filter omitted some messages.

Ergo: To me it appears that is the cause for several messages not showing up in, which I very much regret since I had been using this useful filter for a long time, seemingly without problems. Luckily, most of the messages I missed were not crucial. For now, although I'd like to do otherwise, I cannot recommend to use the filter. I have contacted the author about this.

P.S.: I am using the following version of the script: $Id:,v 1.8 2005/10/05 09:34:26 eggert Exp $

[ Reply to This | # ]