shb_php Posted March 7, 2012 Share Posted March 7, 2012 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 Quote Link to comment Share on other sites More sharing options...
requinix Posted March 7, 2012 Share Posted March 7, 2012 To save me from looking it up myself, how does imapsync use this regex to remap the folders? Quote Link to comment Share on other sites More sharing options...
shb_php Posted March 7, 2012 Author Share Posted March 7, 2012 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 ^ Quote Link to comment Share on other sites More sharing options...
requinix Posted March 7, 2012 Share Posted March 7, 2012 Oh, it's Perl-style. I didn't realize (though the s/ really should have tipped me off). Anyway the /i goes at the end. As in s/.../.../i. Quote Link to comment Share on other sites More sharing options...
shb_php Posted March 7, 2012 Author Share Posted March 7, 2012 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 ? Quote Link to comment Share on other sites More sharing options...
requinix Posted March 7, 2012 Share Posted March 7, 2012 Keep the first one but with a change. Speaking of, the $ means end-of-string so do you really want it? Quote Link to comment Share on other sites More sharing options...
shb_php Posted March 7, 2012 Author Share Posted March 7, 2012 The first one ? But I do need it to rename all sub folders of "Sent Items" as well at that folder. Can you please show the full line ? Quote Link to comment Share on other sites More sharing options...
requinix Posted March 7, 2012 Share Posted March 7, 2012 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. Quote Link to comment Share on other sites More sharing options...
shb_php Posted March 7, 2012 Author Share Posted March 7, 2012 --regextrans2 "s/^INBOX\.Sent Items/INBOX\.Sent/i" ^ Thanks heaps... that works I did like your explanation.. But I still don't understand what the: (.+) and the $1 are actually doing ????? Quote Link to comment Share on other sites More sharing options...
requinix Posted March 7, 2012 Share Posted March 7, 2012 The .+ will match everything after the ".Sent Items." (the subfolders). Parentheses make it a capturing group so that the substitution text can use $1 (1=first group counting left-to-right) to insert it back in. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.