Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I get some mails arriving (on an IMAP server) with subject like:

[1270503] apple
[1272481] bottle
[172481] wine
[43172481] grapes

I need these letters to be moved in INBOX.CSR.number where number is the one standing in "[ ]" s in the subject. The mailbox shall be created, if does not exists.

Since I'm not familiar with LUA programming language, I find difficult setting up imapfilter (http://imapfilter.hellug.gr/) to do this.

update1: i need to rearrange the letters on the IMAP account folders. No file operations possible.

share|improve this question

2 Answers 2

Did you think to use procmail, procmail accepts egrep extended regular expressions.

share|improve this answer
    
thanks, but procmail is not a solution: I need to rearrange an IMAP account, procmail is only able to download them and sort, but not on the imap account. –  asdmin Aug 4 '09 at 10:53
up vote 2 down vote accepted

Since no-one has came up with an idea, I had to get deeper in LUA programming language.

The answer is here if later someone finds him/herself in a situation like this:

options.timeout = 120
options.subscribe = true

localhost = IMAP {
    server = 'ipaddress',
    username = 'username',
    password = 'password',
}

sms=localhost.CSR:select_all()
if (sms ~= nil)
then
   subjects=localhost.CSR:fetch_fields({ 'subject' }, sms)
    if (subjects ~= nil)
    then
    	for messageid, subject in pairs(subjects) 
    	do
    		local success, csrnumber = regex_search('^Subject: \\[([0-9]+)\\] ', subject)
    	if success 
    		then 
    			localhost:create_mailbox('CSR.'..csrnumber)
    			localhost:subscribe_mailbox('CSR.'..csrnumber)
    			local tmp = {}
    			tmp[messageid]=true
    			localhost.CSR:move_messages(localhost['CSR.'..csrnumber], tmp)
    		end
    	end
    end
end
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.