diff --git a/include/class.mailfetch.php b/include/class.mailfetch.php
index 9d96aa66f4ee80fa1b44ef885c1f86400ffff5f8..258b8f8758b557f1d45241e8e8202114051f2e73 100644
--- a/include/class.mailfetch.php
+++ b/include/class.mailfetch.php
@@ -316,7 +316,11 @@ class MailFetcher {
             $struct=@imap_fetchstructure($this->mbox, $mid);
 
         //Match the mime type.
-        if($struct && !$struct->ifdparameters && strcasecmp($mimeType, $this->getMimeType($struct))==0) {
+        if($struct
+                && strcasecmp($mimeType, $this->getMimeType($struct))==0
+                && (!$struct->ifdparameters
+                    || !$this->findFilename($struct->dparameters))) {
+
             $partNumber=$partNumber?$partNumber:1;
             if(($text=imap_fetchbody($this->mbox, $mid, $partNumber))) {
                 if($struct->encoding==3 or $struct->encoding==4) //base64 and qp decode.