Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Class tipmail (mail.prg

72 views
Skip to first unread message

FabioNery

unread,
May 16, 2012, 8:23:39 AM5/16/12
to
Hi,

I received some emails with attachments that have no "content-type 'name'"
field but have the "content-disposition 'filename'" field. For this reason
the attachments are not recovered.

I changed the method thus:
METHOD GetFileName () CLASS TipMail

IF "attachment" Lower $ (:: GetFieldPart ("Content-Disposition"))
RETURN STRTRAN (:: getFieldOption ("Content-Disposition","filename")
'"','')
ENDIF

RETURN STRTRAN (:: getFieldOption ("Content-Type", "name"),"','')

Now I got save the attachments.

Please, could someone validate this change and do it in the svn?

TIA,
FabioNery

TESTE.PRG

PROCEDURE Main

LOCAL oPop, oPart, aParts, oTIpMail, aEmails, i,;
cUser := 'us...@dominio.com.br',;
cPass := 'password',;
oUrl,;
cPasta := 'c:\Tmp\mail\',;
lTrace := .f.,;
lDeletaEmaildoServidor := .f.

setmode( 25,80 )

cUser := StrTran( cUser, "@", "&at;" )
oUrl1 := tUrl():New( "pop://" + cUser + ":" + cPass +
"@pop.server.com" )
oUrl1:cUserid := Strtran( cUser, "&at;", "@" )
opop:= tIPClientPOP():New( oUrl1, lTrace )

IF .NOT. oPop:open()
alert( "Connection error:" + cstr(
oPop:lastErrorMessage() ) )
QUIT
ELSE
aEMails := oPop:retrieveAll( lDeletaEmailDoServidor )
* oPop:close()
ENDIF

FOR i:=1 TO Len( aEMails )
oTIpMail := aEmails[i]
? oTIpMail:getFieldPart( "From" )
? oTIpMail:getFieldPart( "Subject" )

IF oTIpMail:isMultiPart()
// Retrieve all parts of a multipart message
aParts := oTIpMail:getMultiParts()

FOR EACH oPart IN aParts
IF .NOT. Empty( oPart:getFileName() )
// This is a file attachment. Store it in the
TMP folder.
IF oPart:detachFile( cPasta )
? "File written: " + cPasta +
oPart:getFileName()
ENDIF
ELSE
? oPart:getBody()
ENDIF
NEXT
wait
ELSE
// simple mail message
? oTIpMail:getBody()
wait
ENDIF
//oTipMail:Delete(i) // ocorre erro nesta linha dizendo
que não tem o metodo delete em oTipMail
* if lDeletaEmailDoServidor
* oPop:Delete(i)
* endif
NEXT
oPop:close()

wait

RETURN





0 new messages