Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello guys,
I am trying to retrieve emails using tPOP with filter subject and from.
I have special characters in the email subject; Example [AAA] Test1
If i put the subject directly in the filter while escaping the characters, it works fine. I retrieve the emails correctly:
But if i put the same subject in a context variable => context.MAIL_Subject and i escape it, it does not work => NO EMAIL FOUND
context.MAIL_Subject = context.MAIL_Subject.replace("[","\\\\[").replace("]","\\\\]");
System.out.println(context.MAIL_Subject); => \\
[AAA\\] Test1
Can someone advice please?
Best regards,
RA
String str = context.MAIL_Subject.replace("[","\\[").replace("]","\\]");
context.MAIL_Subject = str;
cause as far as i understand :
you have "[AAA]" you want "\\[AAA\\]"
if you print "\\[AAA\\]" you'll see "\[AAA\]"
if you replace [ and ] by \\\\[ and \\\\] and print it you will see "\\[AAA\\]" on the console but the string value will be "\\\\[AAA\\\\]" and not "\\[AAA\\]"
so if you replace [ and ] by \\[ and \\] and print it you will see "\[AAA\]" in the console but the string value will be "\\[AAA\\]" like your direct input wich work.
and i check you can use directly :
context.MAIL_Subject = context.MAIL_Subject.replace("[","\\[").replace("]","\\]");
it will works too.
Hi @Rohit Aftab, you apply the replace method to the same variable you try to affect the value.
You can do something like this instead:
String str = context.MAIL_Subject.replace("[","\\\\[").replace("]","\\\\]");
context.MAIL_Subject = str;
I tried the solution but it is still not working.
String str = context.MAIL_Subject.replace("[","\\\\[").replace("]","\\\\]");
context.MAIL_Subject = str;
Result => Still no mail found
String str = context.MAIL_Subject.replace("[","\\[").replace("]","\\]");
context.MAIL_Subject = str;
cause as far as i understand :
you have "[AAA]" you want "\\[AAA\\]"
if you print "\\[AAA\\]" you'll see "\[AAA\]"
if you replace [ and ] by \\\\[ and \\\\] and print it you will see "\\[AAA\\]" on the console but the string value will be "\\\\[AAA\\\\]" and not "\\[AAA\\]"
so if you replace [ and ] by \\[ and \\] and print it you will see "\[AAA\]" in the console but the string value will be "\\[AAA\\]" like your direct input wich work.
and i check you can use directly :
context.MAIL_Subject = context.MAIL_Subject.replace("[","\\[").replace("]","\\]");
it will works too.
Thank you so much. It works!