Autore Topic: Problemi di lettura di un allegato pdf usando il client pop3  (Letto 611 volte)

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.253
  • Ne mors quidem nos iunget
    • Mostra profilo
Vi riporto questa discussione apparsa nella M.L. ufficiale:

" If I download emails containing pdf files using .Message.ToString() and save
 the email to file then try to decode the attachment with-:


 
Codice: gambas [Seleziona]
Dim hMimeMessage As MimeMessage
 Dim hMimePart As MimePart
 Dim sTemp As String
       Dialog.Title = "Select a text file"
       If Dialog.OpenFile() Then Return
       sTemp = File.Load(Dialog.Path)
       hMimeMessage = New MimeMessage(sTemp)
       For Each hMimePart In hMimeMessage.Part
            If hMimePart.Disposition = "attachment" Then
                 File.Save(User.Home &/ "New Folder" &/ hMimePart.FileName,
 Mime.Decode(sTemp, hMimePart.ContentEncoding))
            Endif
       Next


The saved file is unreadable.
kmail however can open the saved email and displays the attachment OK.

BTW I'm using Gambas 3.5

bill
"


" You are not doing the right thing: Mime.Decode() is just a decoding
routine (like UnBase64$). You don't have to use it, all is done
automatically by the "Data" property of the message part.

Moreover, a MIME message is a recursive structure. Usually mail clients
hides that by displaying the message contents linearly. So you must
parse the parts recursively until you find your attachment.

Here is an example:

Codice: gambas [Seleziona]
' Gambas module

Private $iLevel As Integer

Public Sub Main()

   Dim hMessage As New MimeMessage

   ' MyPopMessageData is retrieved (for example) with the
   ' Pop3Client[].Text property

   hMessage = New MimeMessage(File.Load(MyPopMessageData))

   PrintPart(hMessage.Part)

End

Public Sub PrintPart(hPart As MimePart)

   Dim hChild As MimePart

   Print String$($iLevel, "| "); "| "
   Print String$($iLevel, "| "); "+-"; If(hPart.Count, "+", "-");;
   Print hPart;; hPart.ContentType;; hPart.FileName

   Inc $iLevel
   For Each hChild In hPart
     PrintPart(hChild)
   Next
   Dec $iLevel

   If hPart.ContentType = "application/pdf" Then
     ' I found the PDF attachment!
     File.Save("~/found-it.pdf", hPart.Data)
   Endif

End


Regards,

--
Benoît Minisini
"


" Thank you Benoît - it works fine now!

bill
"
« Ultima modifica: 09 Dicembre 2013, 15:18:48 da vuott »
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »