5
我的应用程序存储大量XML文件。后台作业会定期将这些XML文件的一部分发送到特定的邮箱。该邮件代码是死简单:使用ActionMailer发送XML附件时意外的换行符
class MailSender < ActionMailer::Base
default :from => AppConfig.mail_from
smtp_settings :address => AppConfig.smtp_host,
:username => AppConfig.smtp_user,
:password => AppConfig.smtp_pass
def send_xml(record)
f = record.filename.gsub("\\", "/") # converts \ to/
f_short = arq.gsub(/.*\//, "") # extracts only the filename
f_phys = "#{AppConfig.xml_root}#{arq}" # builds the physical filename
headers["Return-Receipt-To"] = AppConfig.return_receipt
attachments[f_short] = File.read(f_phys) if File.exists?(f_phys)
mail :subject => "...",
:to => AppConfig.mail_to
end
end
然而,出于某种原因,这些XML越来越输电损坏:第一行被突破987列,并将在之后990列被添加后每打破,插入一个空间。我认为这幅画说为自己:
col 1 col 990
|.................................................|
<?xml version="1.0" ... </IE><IM>321505493301<
/IM><CNAE>4744001< ... 00</pCOFINS><vCOFINS>0.00
</vCOFINS></COFINS ... /prod><imposto><ICMS><ICM
S40><orig>0</orig> ... <infAdic><infCpl>Permite
我打过电话File.read
自己的rails console
,它工作正常,无换行加入。所以我认为错误应该在ActionMailer
上。有小费吗?
编辑澄清:大多数的XML文档位于一个单一的大行。我无法更改它,因为XML是数字签名的 - 任何更改(包括添加换行符和缩进)都会打破数字签名。