diff --git a/include/class.mailfetch.php b/include/class.mailfetch.php
index 9bf51bc9f39b65881d77b0a8a2388fec25bd01a8..fc1560e43e18e1409e3ecbed35c1e9e09bd13021 100644
--- a/include/class.mailfetch.php
+++ b/include/class.mailfetch.php
@@ -297,7 +297,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.