MAILS AVEC INDY10, RÉSOLUTION DU PROBLÈME LORSQUE CHARSET = UTF-8

florenth - 28 juil. 2007 à 11:40
cs_MAURICIO Messages postés 2106 Date d'inscription mardi 10 décembre 2002 Statut Modérateur Dernière intervention 15 décembre 2014 - 3 nov. 2010 à 11:53
Cette discussion concerne un article du site. Pour la consulter dans son contexte d'origine, cliquez sur le lien ci-dessous.

https://codes-sources.commentcamarche.net/source/43582-mails-avec-indy10-resolution-du-probleme-lorsque-charset-utf-8

cs_MAURICIO Messages postés 2106 Date d'inscription mardi 10 décembre 2002 Statut Modérateur Dernière intervention 15 décembre 2014 5
3 nov. 2010 à 11:53
Salut,

ce bug n' existe plus depuis Indy tiburon.

A+
ActiveX Messages postés 32 Date d'inscription jeudi 6 février 2003 Statut Membre Dernière intervention 22 janvier 2008
22 janv. 2008 à 22:47
j'ai répété exactement la même chose que toi et cela ne fonctionne pas, peux tu mettres un zip avec un prog qui fonctionne que je puisse les comparer et voir mes erreurs.

merci

ActiveX
ActiveX Messages postés 32 Date d'inscription jeudi 6 février 2003 Statut Membre Dernière intervention 22 janvier 2008
21 janv. 2008 à 20:39
Bonjour Mauricio, j'ai un problème, j'ai tous les informations sauf les infos sur les attachements.

j'utilise Indy10 avec delphi entreprise 6

le ExtraHeaders.Text est toujours vide

peux tu m'aider SVP

mon code est le suivant :


IdMessage.NoDecode := false;
IdMessage.NoEncode := false;
IdMessage.ProcessHeaders;
for i := 0 to IdMessage.MessageParts.Count-1 do
begin
// récupération du corps du mail
// if IdMessage.MessageParts.Items[i].ClassName = 'TIdText' then
// if IdMessage.MessageParts.Items[i].DisplayName = 'TIdText' then
// if IdMessage.MessageParts.Items[i] is TIdText then
if IdMessage.MessageParts.Items[i].ClassName = 'TIdText' then
begin
try
if TIdText(IdMessage.MessageParts.Items[i]).ContentType = 'text/html'then
ViewerSourceForm.RichHtml.Lines.Add(TIdText(IdMessage.MessageParts.Items[i]).Body.Text)//text/html
else
ViewerSourceForm.Body.Lines.Add(TIdText(IdMessage.MessageParts.Items[i]).Body.Text);//text/plain
if TIdText(IdMessage.MessageParts.Items[i]).Boundary <> '' then
ViewerSourceForm.Source.Lines.Add(TIdText(IdMessage.MessageParts.Items[i]).Boundary);
if TIdText(IdMessage.MessageParts.Items[i]).Headers.Text <> '' then
ViewerSourceForm.Source.Lines.Add(TIdText(IdMessage.MessageParts.Items[i]).Headers.Text);
if TIdText(IdMessage.MessageParts.Items[i]).ExtraHeaders.Text <> '' then
ViewerSourceForm.Source.Lines.Add(TIdText(IdMessage.MessageParts.Items[i]).ExtraHeaders.Text);
ViewerSourceForm.Source.Lines.Add(TIdText(IdMessage.MessageParts.Items[i]).Body.Text);
except
end;
end;
// if IdMessage.MessageParts.Items[i].ClassName = 'TIdAttachmentFile' then
// if IdMessage.MessageParts.Items[i].DisplayName = 'TIdAttachmentFile' then
// if IdMessage.MessageParts.Items[i] is TIdAttachment then
if IdMessage.MessageParts.Items[i].ClassName = 'TIdAttachmentFile' then
begin
try
ViewerSourceForm.ListBox1.Items.Add(TIdAttachment(IdMessage.MessageParts.Items[i]).FileName);
if TIdAttachment(IdMessage.MessageParts.Items[i]).Boundary <> '' then
ViewerSourceForm.Source.Lines.Add(TIdAttachment(IdMessage.MessageParts.Items[i]).Boundary);
if TIdAttachment(IdMessage.MessageParts.Items[i]).Headers.Text <> '' then
ViewerSourceForm.Source.Lines.Add(TIdAttachment(IdMessage.MessageParts.Items[i]).Headers.Text);
if TIdAttachment(IdMessage.MessageParts.Items[i]).ExtraHeaders.Text <> '' then
ViewerSourceForm.Source.Lines.Add(TIdAttachment(IdMessage.MessageParts.Items[i]).ExtraHeaders.Text);
except
end;
end;
end;

#############################################################################
CE QUE JE N'AI PAS C'EST CECI

80YnlKSFtJXE1OT0pbXF1eX1VmZ2hpamtsbW5vY3R1dnd4eXp7fH1+f3EQACAgECBAQDBAUGBwcG
BTUBAAIRAyExEgRBUWFxIhMFMoGRFKGxQiPBUtHwMyRi4XKCkkNTFWNzNPElBhaisoMHJjXC0kST
VKMXZEVVNnRl4vKzhMPTdePzRpSkhbSVxNTk9KW1xdXl9VZmdoaWprbG1ub2JzdHV2d3h5ent8f/

#############################################################################

This is a multi-part message in MIME format.

------=_NextPart_000_0008_01C85764.EF744620
Content-Type: multipart/alternative;
boundary="----=_NextPart_001_0009_01C85764.EF744620"


------=_NextPart_001_0009_01C85764.EF744620
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


----- Original Message -----=20
From: xxxxxxxxxxx
To: xxxxxxxxx
Sent: Monday, January 14, 2008 10:28 AM
Subject: image



------=_NextPart_001_0009_01C85764.EF744620
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.6000.16587" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>





----- Original Message -----=20

From: xxxxxxxxxxxxxxxx =20



To: xxxxxxxxxxxxxx


Sent: Monday, January 14, 2008 10:28 AM


Subject: image






</HTML>

------=_NextPart_001_0009_01C85764.EF744620--

------=_NextPart_000_0008_01C85764.EF744620
Content-Type: image/jpeg;name="clefdevoute.jpg"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;filename="clefdevoute.jpg"


CE QUE JE N'AI PAS C'EST CECI

/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB
AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEB
AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wAARCAEaAfgDASIA
AhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA
AAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3
ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWm
p6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEA
AwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSEx
BhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElK
U1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3
uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD+UD9m
YVcL8tFM/wCClaTxeHP2c4iVaWL4U+Aoydsax7R4XX5UaNU3tzks+5ucAjAFFc+RyUsupuKSTqVr
JbaVZLTRaO19jDPv+RpiP+4f/puPr+Z8Hf8ABPt3h/az+GAQNmTV44QAPvhrm1JX6MFJJHPf3r9k
/wBtaySX9lH4zqlvbtPYfGz46TSTG9nS5eM6poxz8xlFwII2x5DbQ2c7128/jR+wGkzftafCSVAP
k8SWh5LKpBuIAeVIyfm6Z49OlfsB+3iXH7L3xKhjQMX+P/x6uZpIAXaOBLzRokSUnd+68zO5zhs/
xY6/O8UJPPctvbXG5Hp/3Uo7dvU+k4WX/CJmv/XjMPW31Pv/AF95/NnRRRX7SfmYUUUU1q9XbzBe

------=_NextPart_000_0008_01C85764.EF744620
Content-Type: image/jpeg;name="Gaff1935662259.jpg"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;filename="Gaff1935662259.jpg"


CE QUE JE N'AI PAS C'EST CECI

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/c2tzU+XMRlOgeCPfh
v7eJbHDUdRxS7XTyOVXfQT9mzKsmOfTOvyVM9QyQYceOZ54WxZ9Tc2ss9wYADve+Gkn/AIOtpd7P
5bk+L9UX5VkG8hvZ0A7jEhrdf7KmjlxVrIS8a/71jOPJegr6uXj5t1lgZE9tNPJGyanls2CIC6rF
+q2Fg1b5LyRBc+ASY3f6+1ZfVqmNLmsEAaeH5UwZomfpC/25CPqLy3pu3bPzklOP1iJ78pK1f5Ne

------=_NextPart_000_0008_01C85764.EF744620--

peux tu m'aider SVP

Merci à l'avance

ActiveX
cs_MAURICIO Messages postés 2106 Date d'inscription mardi 10 décembre 2002 Statut Modérateur Dernière intervention 15 décembre 2014 5
1 août 2007 à 15:20
Voilà c' est fait!
il y a encore une petite erreur qui surgit ocasionnellement (du moins je crois) sur le compo IdPOP3 (fonction receiveHeader qui ne renvoie pas le même "Header" selon qu' on appelle la fonction IdPop3.Retrieve ou IdPop3.RetrieveHeader) mais je ne vois pas comment je peux faire ...
Le fait est que avec IdPop3.RetrieveHeader, le charSet est bien informé alors que lorsqu' ensuite je fais IdPop3.Retrieve pour récupérer le message, le CharSet est vide, le Header étant légèrement diférent ... Arg ...

function TIdPOP3.Retrieve(const MsgNum: Integer; AMsg: TIdMessage): Boolean;
begin
if SendCmd('RETR ' + IntToStr(MsgNum), '') = ST_OK then begin {Do not Localize}
AMsg.Clear;
// This is because of a bug in Exchange? with empty messages. See comment in ReceiveHeader
if ReceiveHeader(AMsg) = '' then begin
// Only retreive the body if we do not already have a full RFC
ReceiveBody(AMsg);
end;
end;
// Will only hit here if ok and NO exception, or IF is not executed
Result :LastCmdResult.Code ST_OK;
end;

function TIdPOP3.RetrieveHeader(const MsgNum: Integer; AMsg: TIdMessage): Boolean;
begin
// Result := False;
AMsg.Clear;
SendCmd('TOP ' + IntToStr(MsgNum) + ' 0', ST_OK); {Do not Localize}
// Only gets here if no exception is raised
ReceiveHeader(AMsg,'.');
Result := True;
end;

Je pense que le problème vient de SendCmd('TOP ' qui renvoie bien le Header alors que SendCmd('RETR ' ne renvoie pas tout à fait le même Header.

A+
cs_MAURICIO Messages postés 2106 Date d'inscription mardi 10 décembre 2002 Statut Modérateur Dernière intervention 15 décembre 2014 5
31 juil. 2007 à 18:38
Ouai, vu comme ça, t' as raison lol !!!
Je sais bien que TextIsSame() est une fonction d'Indy ! Mais puisque tu modifies la librairie, autant utiliser ses propres fonctions, non ?!
LTxt.CharSet = 'utf-8' ne pose pas de problèmes jusqu'au jour où un client/serveur smtp mettra UTT-8, c'est à dire en majuscules...
Tu me dirais... z'avaient qu'a respecter les standards... ben ouais... z'avaient qu'a... mais mon mail, je veux pouvoir le lire !!
cs_MAURICIO Messages postés 2106 Date d'inscription mardi 10 décembre 2002 Statut Modérateur Dernière intervention 15 décembre 2014 5
31 juil. 2007 à 17:37
TextIsSame est une fonction Indy...
Mais tu as raison: faudra que je change cela même si LTxt.CharSet = 'utf-8' ne pose pas de problème particulier.
A+
Bravo pour cette deuxième fonction. Tu enlèves une grosse épine du pied à la librairie Indy qui souffrait malheureusement de ce manque.

Rien que pour ça, 10/10.

Un détail cependant: ne serait-il pas mieux d'utiliser la fonction TextIsSame() au lieu de faire des comparaisons directes (comme LTxt.CharSet = 'utf-8') ? Histoire d'éviter le problèmes de casse.
cs_MAURICIO Messages postés 2106 Date d'inscription mardi 10 décembre 2002 Statut Modérateur Dernière intervention 15 décembre 2014 5
31 juil. 2007 à 16:25
Voila, les bodys sont traités...
NJoy!!!
A+
cs_MAURICIO Messages postés 2106 Date d'inscription mardi 10 décembre 2002 Statut Modérateur Dernière intervention 15 décembre 2014 5
31 juil. 2007 à 15:07
Cette fois le Header est mieux décodé!
J' attaque les bodys en UTF-8!!!
A+
cs_MAURICIO Messages postés 2106 Date d'inscription mardi 10 décembre 2002 Statut Modérateur Dernière intervention 15 décembre 2014 5
30 juil. 2007 à 10:31
Salut,
je me suis juste contenté de boucher la lacune qu' il y avait dans le code, j' ai pas cherché à optimiser ...
A+
Salut !

Je trouve la solution très élégante. Je n'ai pas encore pu tester mais tout me semble parfait.
Cela dit, je trouve que le fonction de base fournie par Indy est nulle niveau performances. Rien de rien n'est optimisé :-(

Enfin bon, on n'est pas à quelques millisecondes près...

A+
Flo
Rejoignez-nous