in reply to Mail::IMAPClient and searching email subjects with double quotes

This seems to be a backwards compatibility issue with Mail::IMAPClient. Looking at ->search, it always calls ->_quote_search to quote its arguments. And ->_quote_search passes through everything unchanged if it receives only one argument except the object.

This makes passing only one unquoted argument to ->search inconvenient.

I used the following code to play around with this:

>perl -MData::Dumper -MMail::IMAPClient -we "print Dumper [@ARGV], Mai +l::IMAPClient->_quote_search(@ARGV)" "1 \"2\" foo" 3 $VAR1 = [ '1 "2" foo', '3' ]; $VAR2 = '{9} 1 "2" foo'; $VAR3 = '3'; >perl -MData::Dumper -MMail::IMAPClient -we "print Dumper [@ARGV], Mai +l::IMAPClient->_quote_search(@ARGV)" "\"2\" foo" $VAR1 = [ '"2" foo' ]; $VAR2 = '"2" foo';

So ideally, if you want to search only for the SUBJECT attribute, you can split up your query arguments into the two strings SUBJECT and the actual, unquoted target string. That should trigger the appropriate argument quoting in Mail::IMAPClient.

use strict; use Mail::IMAPClient; use Data::Dumper; sub test_quote { print "Parameters: " . Dumper \@_; my @quoted= Mail::IMAPClient->_quote_search(@_); print "Result : " . Dumper \@quoted; }; test_quote( q(SUBJECT "SUBJECT \"test email \"abc123\" approved\")); test_quote( SUBJECT => q(test email "abc123" approved) ); __END__ Parameters: $VAR1 = [ 'SUBJECT "SUBJECT \\"test email \\"abc123\\" approved\\"' ]; Result : $VAR1 = [ 'SUBJECT "SUBJECT \\"test email \\"abc123\\" approved\\"' ]; Parameters: $VAR1 = [ 'SUBJECT', 'test email "abc123" approved' ]; Result : $VAR1 = [ 'SUBJECT', '{28} test email "abc123" approved' ];

(Maybe your assumption was that IMAP quoting works like shell quoting?)

Replies are listed 'Best First'.
Re^2: Mail::IMAPClient and searching email subjects with double quotes
by treize (Novice) on May 14, 2014 at 15:10 UTC

    Hi there and thank you for looking into this.

    I have actually tried to split up the search into two strings like you mentioned and I get another issue, the search hangs.

    I will update my original question with more information and more snippets of my code. One thing I forgot to mention is that I am searching on an exchange server.