class Gmail::Client::Plain
Public Instance Methods
attach_many(pathPattern)
click to toggle source
# File lib/gmail_attach_many.rb, line 29 def attach_many (pathPattern) total_limit = 25*1024*1024 messageArray = GmailAttachMany::MessageArray.new attachments = [] files = Dir.glob(pathPattern).find_all {|f| File.file? f} files.sort_by!{ |m| m.downcase } files.inject(0) do |sum, f| if !(File.size(f) > total_limit) total = sum + File.size(f) if total > total_limit message = self.compose attachments.each do |a| message.add_file a end messageArray.push message attachments = [f] total = File.size(f) else attachments.push f if (files.find_index f) == (files.length - 1) message = self.compose attachments.each do |a| message.add_file a end messageArray.push message end total end else raise "One of the files selected is too big to attach to an email. File name: #{f}. File size: #{File.size(f)} Limit is #{total_limit} bytes." end end return messageArray end