Jump to content

Regex - combine to one statement - I just couldn't get it to work..


shb_php

Recommended Posts

Ok.. I'm using a tool called imapsync. It copies email accounts from one place to another. IT allows some remapping of folder names... if you know a bit of regex. I did get it to work ( but completely UGLY code). In fact embarrassing... Anyone who knows regex please help me.. I ended up using 4 statements (instead of one).

 

    "s#^INBOX\.sent items$#INBOX\.Sent#"

    "s#^INBOX\.Sent Items$#INBOX\.Sent#"

 

    "s/^INBOX\.sent items\.(.+)/INBOX\.Sent\.$1/"

    "s/^INBOX\.Sent Items\.(.+)/INBOX\.Sent\.$1/"

 

I am just trying to rename "Sent Items" and all its children to "Sent". First problem is case insensitivity... Something like  "/i".. but where exactly ?. And the second bigger problem is the bottom statement does for all the children folders, and the top statement does it for just the "Sent Items" folder itself..

 

PLEASE HELP... I know its embarrassing, but I actualy been working on this (should be) one line for 24 hours straight and its sending me to the nut house. Just can't get it to work - elegantly (ie. in one line)

 

S

Link to comment
Share on other sites

It does it through the parameters passed to it at execution time. The particular option that contains the text I posted is --regextrans2. It is the option that reworks the name of the destination folder eg "Sent Items" to "Sent" or "Inbox.Inbox" to "Inbox" etc..  So to run imapsynch the command may look like this:

 

imapsync ^

  --host1 mail.xxxx.com --user1 ergo --password1 ergo ^

  --host2 mail911.x.com --user2 erg0 --password2 newpw ^

  --regextrans2 "s/^INBOX\.INBOX\.(.+)/INBOX\.$1/" ^

  --regextrans2 "s#^INBOX\.sent items$#INBOX\.Sent#" ^

  --regextrans2 "s#^INBOX\.Sent Items$#INBOX\.Sent#" ^

  --regextrans2 "s/^INBOX\.sent items\.(.+)/INBOX\.Sent\.$1/" ^

  --regextrans2 "s/^INBOX\.Sent Items\.(.+)/INBOX\.Sent\.$1/" ^

  --exclude Deleted ^

  --exclude Trash ^

  --exclude Junk ^

Link to comment
Share on other sites

Thats great ! thx .. that brings it down to two lines..  How to consolidate it further, to a single line ??

 

--regextrans2 "s/^INBOX\.Sent Items$/INBOX\.Sent/i" ^

--regextrans2 "s/^INBOX\.Sent Items\.(.+)/INBOX\.Sent\.$1/i" ^

 

I could only get it to work like that - the first line handles "Sent Items" and the second one handles any sub folders under "Sent Items". But neither line did both no matter how I tweaked them... but, clearly, I'm not a regex or perl person. Any thoughts ?

Link to comment
Share on other sites

At this point I'm not going to flat-out give you the answer. I've been trying to get you to keep working on it, and unless somebody else comes in here and posts the right expression you'll have to try to follow along with what's happening.

 

If you know a bit of regex then you know what [abc] means, right? If I gave you a string cat and told you to replace [abc] with 5, you'd end up with 55t. The t didn't change because it wasn't part of the expression.

 

Now, you want to change INBOX\.Sent Items to INBOX\.Sent, right? Still the same subfolder structure, right? So for the substituting you don't have to care what comes after that one part - if it's not in the expression then it will remain unchanged.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.