diff --git a/plugins/FeedsParser.inc b/plugins/FeedsParser.inc
index 5824825..ed5b433 100644
--- a/plugins/FeedsParser.inc
+++ b/plugins/FeedsParser.inc
@@ -369,8 +369,8 @@ class FeedsEnclosure extends FeedsElement {
    * @throws RuntimeException
    *   Thrown if the file extension is invalid.
    */
-  public function getSanitizedUri() {
-    return drupal_dirname($this->getValue()) . '/' . $this->getSafeFilename();
+  public function getSanitizedUri(array $headers = array()) {
+    return drupal_dirname($this->getValue()) . '/' . $this->getSafeFilename($headers);
   }
 
   /**
@@ -382,8 +382,8 @@ class FeedsEnclosure extends FeedsElement {
    * @throws RuntimeException
    *   Thrown if the file extension is invalid.
    */
-  public function getLocalValue() {
-    return str_replace(' ', '_', $this->getSafeFilename());
+  public function getLocalValue(array $headers = array()) {
+    return str_replace(' ', '_', $this->getSafeFilename($headers));
   }
 
   /**
@@ -395,7 +395,7 @@ class FeedsEnclosure extends FeedsElement {
    * @throws RuntimeException
    *   Thrown if the file extension is invalid.
    */
-  protected function getSafeFilename() {
+  protected function getSafeFilename(array $headers = array()) {
     if (isset($this->safeFilename)) {
       return $this->safeFilename;
     }
@@ -409,13 +409,17 @@ class FeedsEnclosure extends FeedsElement {
     // Remove leading and trailing whitespace and periods.
     $filename = trim($filename, " \t\n\r\0\x0B.");
 
-    if (strpos($filename, '.') === FALSE) {
-      $extension = FALSE;
-    }
-    else {
-      $extension = drupal_strtolower(substr($filename, strrpos($filename, '.') + 1));
+    $mime_extension = $this->getExtensionFromHeaders($headers);
+
+    $extension = $this->getExtensionFromUrl($filename);
+
+    // Add mime type extension if it doesn't match the file extension.
+    if ($mime_extension !== FALSE && $extension !== $mime_extension) {
+      $filename .= '.' . $mime_extension;
+      $extension = $mime_extension;
     }
 
+
     if (!$extension || !in_array($extension, explode(' ', $this->allowedExtensions), TRUE)) {
       throw new RuntimeException(t('The file @file has an invalid extension.', array('@file' => $filename)));
     }
@@ -430,6 +434,8 @@ class FeedsEnclosure extends FeedsElement {
    *
    * @return string
    *   The content of the referenced resource.
+   *
+   * @deprecated
    */
   public function getContent() {
     feeds_include_library('http_request.inc', 'http_request');
@@ -437,10 +443,28 @@ class FeedsEnclosure extends FeedsElement {
     if ($result->code != 200) {
       throw new Exception(t('Download of @url failed with code !code.', array('@url' => $this->getUrlEncodedValue(), '!code' => $result->code)));
     }
+
     return $result->data;
   }
 
   /**
+   * Downloads the content from the file URL.
+   *
+   * @return stdClass
+   *   The full response from the HTTP request.
+   */
+  protected function getRequest() {
+    feeds_include_library('http_request.inc', 'http_request');
+    $result = http_request_get($this->getUrlEncodedValue());
+
+    if ($result->code != 200) {
+      throw new Exception(t('Download of @url failed with code !code.', array('@url' => $this->getUrlEncodedValue(), '!code' => $result->code)));
+    }
+
+    return $result;
+  }
+
+  /**
    * Get a Drupal file object of the enclosed resource, download if necessary.
    *
    * @param $destination
@@ -487,14 +511,16 @@ class FeedsEnclosure extends FeedsElement {
           $destination = trim($destination, '/') . '/';
         }
         try {
-          $filename = $this->getLocalValue();
+          $response = $this->getRequest();
+
+          $filename = $this->getLocalValue($response->headers);
 
           if (module_exists('transliteration')) {
             require_once drupal_get_path('module', 'transliteration') . '/transliteration.inc';
             $filename = transliteration_clean_filename($filename);
           }
 
-          $file = file_save_data($this->getContent(), $destination . $filename);
+          $file = file_save_data($response->data, $destination . $filename);
         }
         catch (Exception $e) {
           watchdog_exception('Feeds', $e, nl2br(check_plain($e)));
@@ -509,6 +535,49 @@ class FeedsEnclosure extends FeedsElement {
       return $file;
     }
   }
+
+  protected function getExtensionFromHeaders(array $headers) {
+    $headers = array_change_key_case($headers);
+
+    if (!isset($headers['content-type'])) {
+      return FALSE;
+    }
+
+    list($mimetype) = explode(';', $headers['content-type'], 2);
+    $mimetype = trim($mimetype);
+
+    $map = $this->getMimeTypeMap();
+
+    return isset($map[$mimetype]) ? $map[$mimetype] : FALSE;
+  }
+
+  protected function getExtensionFromUrl($filename) {
+    if (strpos($filename, '.') === FALSE) {
+      return FALSE;
+    }
+
+    return drupal_strtolower(substr($filename, strrpos($filename, '.') + 1));
+  }
+
+  /**
+   * Returns a map from common mime types to file extensions.
+   *
+   * @return array
+   */
+  public static function getMimeTypeMap() {
+    return array(
+      'image/jpeg' => 'jpg',
+      'image/gif' => 'gif',
+      'image/bmp' => 'bmp',
+      'image/tiff' => 'tiff',
+      'image/svg+xml' => 'svg',
+      'text/plain' => 'txt',
+      'application/xml' => 'xml',
+      'video/mpeg' => 'mpg',
+      'video/quicktime' => 'mov',
+    );
+  }
+
 }
 
 /**
