2012-04-02 1 views
0

cloudmailin을 사용하여 특정 주소로 보내는 전자 메일을 수신하고 있습니다. Mail.app에서 첨부 파일이 포함 된 전자 메일을 보내는 간단한 시나리오를 시도하고 있습니다. 내 응용 프로그램에서 게시물을받을 때 메일 개체를 만듭니다.Rails 3 Apple Mail.app의 첨부 파일이 포함 된 전자 메일 읽기

메일 개체를 만들 때 첨부 파일이 비어 있습니다. 나는 다른 클라이언트를 통해 이메일을 보내는 경우

mail_str = 
"Received: (qmail 16453 invoked from network); 2 Apr 2012 14:27:29 -0000\r\nReceived: from unknown (71.170.102.226)\r\n by smtpauth20.prod.mesa1.secureserver.net (64.202.165.36) with ESMTP; 02 Apr 2012 14:27:29 -0000\r\nFrom: Jake Dempsey <[email protected]>\r\nContent-Type: multipart/mixed; boundary=\"Apple-Mail=_8E1F0992-1DAA-409B-BC73-74747FFDFA98\"\r\nSubject: inv\r\nDate: Mon, 2 Apr 2012 09:27:28 -0500\r\nMessage-Id: <[email protected]>\r\nTo: [email protected]\r\nMime-Version: 1.0 (Apple Message framework v1257)\r\nX-Mailer: Apple Mail (2.1257)\r\n\r\n\r\n--Apple-Mail=_8E1F0992-1DAA-409B-BC73-74747FFDFA98\r\nContent-Disposition: attachment;\r\nfilename=test.csv\r\nContent-Type: text/csv;\r\nname=\"test.csv\"\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\nRemove Itesm,Item ID,Short Desc,Long Desc,Segment,Item =\r\nClass,Cost,MSRP,Stock UOM, Unit Vol,Unit Weight,Unit Height,Unit =\r\nLength,Unit Width=0Dno,1, super short, super long long, Casual, =\r\nCasual,1,3,Each, , , , , =0Dno,2, super short, super long long, Casual, =\r\nCasual,1,3,Each, , , , , =0Dno,3, super short, super long long, Casual, =\r\nCasual,1,3,Each, , , , , =0Dno,4, super short, super long long, Casual, =\r\nCasual,1,3,Each, , , , , =0Dno,5, super short, super long long, Casual, =\r\nCasual,1,3,Each, , , , , =0Dno,6, super short, super long long, Casual, =\r\nCasual,1,3,Each, , , , , =0Dno,7, super short, super long long, Casual, =\r\nCasual,1,3,Each, , , , , =0Dno,8, super short, super long long, Casual, =\r\nCasual,1,3,Each, , , , , =0D=\r\n\r\n--Apple-Mail=_8E1F0992-1DAA-409B-BC73-74747FFDFA98--\r\n" 

mail_obj = Mail.new mail_str 
puts mail_obj.attachments.size #should be 1 

, 나는 mail_obj를 만들 수 있어요 및 첨부 파일의 크기는 I 우리는 몇 가지 문제가 있었다 레일

답변

1

3.1.3을 사용하고 1

입니다 메일 보석은 항상 올바른 첨부 파일을 찾고 중첩 된 첨부 파일을 찾습니다. 결국 우리는 각 메시지 부분을 반복하고 첨부 파일을 반복적으로 추출하는 메서드를 만드는 작업을 마무리했습니다. ..

def parse_attachment(mail, attachments=[]) 
    mail.parts.each do |part| 
    if part.attachment? 
     attachments << part 
    else 
     if part.parts && part.parts.length > 0 
     parse_attachment(part, attachments) 
     end 
    end 
    end 
    return attachments 
end 
+0

스티브, 병 시험이 밖으로 곧 그것이 않는 경우 당신에게 가장 좋은 대답을 (이것은 우리가 완벽하지 않을 수 있으므로 사용하는 실제 방법이 아닙니다 경고) 예를 들어

무엇 너는 .. 고마워. –

관련 문제