Find the currently selected folder

Rob Mueller robm at fastmail.fm
Sat Sep 7 09:30:48 EDT 2002


Summary: Is there any way to find the currently imap state (authenticated,
selected, etc) and if selected, the actual folder selected?

If you're curious as to why I want to do this, here's the reasons...

One of the things we currently do with web-system is to cache open IMAP
connections in a socket pool. It basically uses the linux/unix 'sendmsg'
call to pass a file descriptor between processes to a 'pooling' process,
storing them hashed by username. At the moment though, we don't store any
other information with the socket. The biggest problem this means is that
when we get the socket back, we don't know what folder is currently
'selected', so by default we always select the needed one.

Now I was just doing some strace runs on cyrus, and I've found that 'select'
is actually a fairly 'expensive' operation, regardless of if you're already
in the folder you do a select on (see below)

So I'm thinking that avoiding the select might be a noticeable improvement.
The 3 main ways to go are:
1. Have a complete proxy, that you connect to, write commands to, retrieve
responses from, etc, and it holds the open connections to the server and
proxies everything. This would involve a whole lot of new code and a new
daemon process though.
2. Use the imap socket pool we have now, but store the current imap state,
and if in 'selected', the current folder as well, and pass that back and
forth. Easier, but unfortunately, not really easy because of how certain
things are done
3. Have some way of querying the IMAP server for it's current state and if
in 'selected', the current folder as well.

I'd like to go 3, but I can't see any obvious way to do this, or am I
missing something?

Rob

Strace run for doing an inbox select is below...

read(0, ". select inbox\r\n", 4096)     = 16
flock(5, LOCK_SH)                       = 0
fstat64(5, {st_mode=S_IFREG|0600, st_size=9912, ...}) = 0
stat64("/var/imap/mailboxes.db", {st_mode=S_IFREG|0600, st_size=9912, ...})
= 0
flock(5, LOCK_UN)                       = 0
open("/var/spool/imap/r/user/robm/cyrus.header", O_RDWR) = 10
fstat64(10, {st_mode=S_IFREG|0600, st_size=208, ...}) = 0
mmap2(NULL, 208, PROT_READ, MAP_SHARED, 10, 0) = 0x4022b000
open("/var/spool/imap/r/user/robm/cyrus.index", O_RDWR) = 11
fstat64(11, {st_mode=S_IFREG|0600, st_size=680, ...}) = 0
mmap2(NULL, 16384, PROT_READ, MAP_SHARED, 11, 0) = 0x4022c000
open("/var/spool/imap/r/user/robm/cyrus.cache", O_RDWR) = 12
fstat64(12, {st_mode=S_IFREG|0600, st_size=15256, ...}) = 0
mmap2(NULL, 24576, PROT_READ, MAP_SHARED, 12, 0) = 0x40260000
fstat64(11, {st_mode=S_IFREG|0600, st_size=680, ...}) = 0
chdir("/var/spool/imap/r/user/robm")    = 0
mmap2(NULL, 16384, PROT_READ, MAP_SHARED, 11, 0) = 0x4026c000
fstat64(12, {st_mode=S_IFREG|0600, st_size=15256, ...}) = 0
mmap2(NULL, 24576, PROT_READ, MAP_SHARED, 12, 0) = 0x40287000
flock(13, LOCK_EX|LOCK_NB)              = 0
fstat64(13, {st_mode=S_IFREG|0600, st_size=11040, ...}) = 0
stat64("/var/imap/user/r/robm.seen", {st_mode=S_IFREG|0600, st_size=11040,
...}) = 0
time(NULL)                              = 1028080763
lseek(13, 60, SEEK_SET)                 = 60
write(13, "\0\0+(", 4)                  = 4
lseek(13, 11040, SEEK_SET)              = 11040
writev(13, [{"\0\0\0\4", 4}, {"\0\0*\330", 4}, {"\0\0\0\2", 4},
{"\0\0\0\20", 4}, {"133ae5603cfc3919", 16}, {"\0\0\0\37", 4}, {"1 1028080763
15 1028079644 1:14", 31}, {"\0", 1},
{"\0\0\0\330", 4}, {"\377\377\377\377", 4}], 10) = 76
fdatasync(13)                           = 0
lseek(13, 11116, SEEK_SET)              = 11116
write(13, "\0\0\0\377", 4)              = 4
fdatasync(13)                           = 0
flock(13, LOCK_UN)                      = 0
open("/var/imap/quota/r/user.robm", O_RDWR) = 14
fstat64(14, {st_mode=S_IFREG|0600, st_size=14, ...}) = 0
mmap2(NULL, 14, PROT_READ, MAP_SHARED, 14, 0) = 0x40230000
munmap(0x40230000, 14)                  = 0
_llseek(8, 0, [0], SEEK_SET)            = 0
write(8, "robmlbvmware[127.0.0.1]\trobm\tuse"..., 39) = 39
_llseek(8, 0, [39], SEEK_CUR)           = 0
ftruncate(8, 39)                        = 0
brk(0x8117000)                          = 0x8117000
time([1028080763])                      = 1028080763
getpid()                                = 4565
rt_sigaction(SIGPIPE, {0x4003ff00, [], 0x4000000}, {SIG_IGN}, 8) = 0
send(9, "<183>Jul 31 11:59:23 imapd[4565]"..., 62, 0) = 62
rt_sigaction(SIGPIPE, {SIG_IGN}, NULL, 8) = 0
sendto(6, "C 1.3.6.1.4.1.3.2.2.3.1.4.33 1\n", 31, 0, {sin_family=AF_UNIX,
path="/tmp/.snmp_door"}, 17) = -1 ENOENT (No such file or directory)
open("/var/imap/msg/shutdown", O_RDONLY) = -1 ENOENT (No such file or
directory)
select(1, [0], NULL, NULL, {0, 0})      = 0 (Timeout)
write(1, "* FLAGS (\\Answered \\Flagged \\Dra"..., 301) = 301
time(NULL)                              = 1028080763
select(1, [0], NULL, NULL, {1800, 0})   = 1 (in [0], left {1633, 120000})
time(NULL)                              = 1028080930





More information about the Info-cyrus mailing list