My mail queue is currently full of bounce messages for the same domain, but in mixed case.

I tried using exiqgrep to filter these mails from my queue, but it seems that the command is case sensitive. Is there any way to perform a case insensitive search?

up vote 3 down vote accepted

As the other gentleman pointed out, the exiqgrep program is just a perl script. It takes the raw value passed to the -r function (recipient) and uses it in a pattern match. The pattern match is a simple $rcpt =~ /$opt{r}/ perl test, the default match, since it's not specified, is case sensitive.

As with all things perl, TIMTOWTDI (There Is More Than One Way To Do It). Since the function above does not strip or sanitize the value passed to -r, you can simply embed an ignore case modifier in the regex. See perldoc perlre for more details about how the (?MODIFIERS:...) sequence works.

Here is an example where I show that a mixed case search doesn't find the domain I'm looking for, but by using an inline flag modifier as part of the search term, it finds it.

OVZ-CentOS58[root@ivwm51 ~]# exiqgrep -r 'crazyivan@yahoo.com'
26h  4.0K 1VGRud-0001sm-P1 <> *** frozen ***
      crazyivan@yahoo.com

OVZ-CentOS58[root@ivwm51 ~]# exiqgrep -r 'crazYivAn@yahOo.com'
OVZ-CentOS58[root@ivwm51 ~]# exiqgrep -r '(?i:crazYivAn@yahOo.com)'
26h  4.0K 1VGRud-0001sm-P1 <> *** frozen ***
      crazyivan@yahoo.com

Your search will be similar, something like:

(?i:@thedomainyouseek.com)
  • This is the right, and quite elegant, answer. – dawud Sep 3 '13 at 14:27
  • Thanks, great solution! @dawud thanks for your answer as well. I did not realize it was plain Perl that could be edited. – Aron Rotteveel Sep 4 '13 at 8:06
  • Update: based on the discussion in this question and on the Exim mailing list, the exiqgrep search has been changed to case-insensitive mode. This new operation will be a part of the forthcoming exim 4.82 release. – Todd Lyons Oct 7 '13 at 16:03

The manpage does not show such option, but the exiqgrep utility is a perl script whose source you can modify to fit your needs:


114 sub selection() {
115   foreach my $msg (keys(%id)) {
116     if ($opt{f}) {
117       # Match sender address
118       next unless ($id{$msg}{from} =~ /$opt{f}/); # here
119     }
120     if ($opt{r}) {
121       # Match any recipient address
122       my $match = 0;
123       foreach my $rcpt (@{$id{$msg}{rcpt}}) {
124         $match++ if ($rcpt =~ /$opt{r}/); # or here
125       }
126       next unless ($match);
127     }
128     if ($opt{s}) {
129       # Match against the size string.
130       next unless ($id{$msg}{size} =~ /$opt{s}/);
131     }
132     if ($opt{y}) {
133       # Match younger than
134       next unless ($id{$msg}{ages}  $opt{o});
139     }
140     if ($opt{z}) {
141       # Exclude non frozen
142       next unless ($id{$msg}{frozen});
143     }
144     if ($opt{x}) {
145       # Exclude frozen
146       next if ($id{$msg}{frozen});
147     }
148     # Here's what we do to select the record.
149     # Should only get this far if the message passed all of
150     # the active tests.
151     $id{$msg}{d} = 1;
152     # Increment match counter.
153     $mcount++;
154   }
155 }

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.