         images[id].count -= 1
         checkImage id
       @images = {}
+      for id of @imagesInternal
+        imagesInternal[id].count -= 1
+        checkImageInternal id
+      @imagesInternal = {}
     else
       newImages = {}
-      $($.parseHTML("<div>#{formatBody data.format, data.body}</div>"))
-      .find 'img[src^="/file/"]'
+      body = $($.parseHTML("<div>#{formatBody data.format, data.body}</div>"))
+      body.find 'img[src^="/file/"]'
       .each ->
         newImages[url2file @getAttribute('src')] = true
+      newImagesInternal = {}
+      body.find 'img[src^="/gridfs/"]'
+      .each ->
+        newImagesInternal[url2internalFile @getAttribute('src')] = true
       for id of @images
         unless id of newImages
           images[id].count -= 1


#Session.setDefault 'images', {}
images = {}
id2template = {}
scrollToLater = null
fileQuery = null

  scrollToMessage @data._id if scrollToLater == @data._id
  #images = Session.get 'images'
  @images = {}
  @imagesInternal = {}
  initImage @data._id
  ## initImage calls updateFileQuery which will do this:
  #images[@data._id].file = @data.file
  #initImageInternal @data.file if @data.file?
  @autorun =>
    data = Template.currentData()
    ## If message is naturally folded, don't count images it references.
