lib/mms2r/media.rb
def filename?(part)
      name = part.filename
      if (name.nil? || name.empty?)
        if part.content_id && (matched = /^<(.+)>$/.match(part.content_id))
          name = matched[1]
        else
          name = "#{Time.now.to_f}.#{self.default_ext(part.part_type?)}"
        end
      end
      # FIXME FWIW, janky look for dot extension 1 to 4 chars long
      name = (name =~ /\..{1,4}$/ ? name : "#{name}.#{self.default_ext(part.part_type?)}").strip

      # handle excessively large filenames
      if name.size > 255
        ext = File.extname(name)
        base = File.basename(name, ext)
        name = "#{base[0, 255 - ext.size]}#{ext}"
      end

      name
    end
def filename?(part)
      name = part.filename
      if (name.nil? || name.empty?)
        if part.content_id && (matched = /^<(.+)>$/.match(part.content_id))
          name = matched[1]
        else
          name = "#{Time.now.to_f}.#{self.default_ext(part.part_type?)}"
        end
      end
      # FIXME FWIW, janky look for dot extension 1 to 4 chars long
      name = (name =~ /\..{1,4}$/ ? name : "#{name}.#{self.default_ext(part.part_type?)}").strip

      # handle excessively large filenames
      if name.size > 255
        ext = File.extname(name)
        base = File.basename(name, ext)
        name = "#{base[0, 255 - ext.size]}#{ext}"
      end

      name
    end
def filename? ( part ) name = part . filename if ( name . nil? || name . empty? ) if part . content_id && ( matched = / / . match ( part . content_id ) ) name = matched [ 1 ] else name = "#{Time.now.to_f}.#{self.default_ext(part.part_type?)}" end end # FIXME FWIW, janky look for dot extension 1 to 4 chars long name = ( name =~ / \. / ? name : "#{name}.#{self.default_ext(part.part_type?)}" ) . strip # handle excessively large filenames if name . size > 255 ext = File . extname ( name ) base = File . basename ( name , ext ) name = "#{base[0, 255 - ext.size]}#{ext}" end name end
returns a filename declared for a part, or a default if its not defined
returns a filename declared for a part or a default if its not defined