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?)


In reply to Re: Mail::IMAPClient and searching email subjects with double quotes by Corion
in thread Mail::IMAPClient and searching email subjects with double quotes by treize

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.