| Ver tema anterior :: Ver tema siguiente |
| Autor |
Mensaje |
Angel Master


Registrado: 15 Abr 2003Mensajes: 2311Ubicación: Toledo (España)
|
Publicado: Sab 09 Ene, 2010 6:29 pm Asunto: Leer correo con TIdPOP3 |
|
|
Partiendo del ejemplo en Pascal que viene con Indy 9.0.17 he tratado de ver el correo que hay en un buzón POP3. He llegado hasta aquí:
| Código: | nMensajes = Recibir->CheckMessages();
if (nMensajes < 1)
return;
for (nItem = 1; nItem <= nMensajes; nItem ++)
{
Correo->Clear();
if (!Recibir->RetrieveHeader(nItem, Correo))
continue;
slLog->Clear();
for (int nParte = 0; nParte < Correo->MessageParts->Count; nParte ++)
if (Correo->MessageParts->Items[nParte]->ClassNameIs("TIdText"))
{
slLog->Text = Correo->MessageParts->Body->Text;
break;
}
}
|
Pero el codigo que hay en este último if no soy capaz de adaptarlo; estoy partiendo de este código:
| Código: | for intIndex := 0 to Pred(Msg.MessageParts.Count) do
begin
if (Msg.MessageParts.Items[intIndex] is TIdAttachment) then
begin //general attachment
pnlAttachments.visible := true;
li := lvMessageParts.Items.Add;
li.ImageIndex := 8;
li.Caption := TIdAttachment(Msg.MessageParts.Items[intIndex]).Filename;
li.SubItems.Add(TIdAttachment(Msg.MessageParts.Items[intIndex]).ContentType);
end
else
begin //body text
if Msg.MessageParts.Items[intIndex] is TIdText then
begin
Memo1.Lines.Clear;
Memo1.Lines.AddStrings(TIdText(Msg.MessageParts.Items[intIndex]).Body);
end
end;
end; |
pero, por más pruebas que he hecho no logro adaptar la línea Memo1.Lines.AddStrings a Builder. _________________ Un saludo
Necesitamos tu ayuda: Envía AI al 27595 (Coste 1,20 euros + IVA) |
|
| Volver arriba |
|
 |
Cesar C. Salazar Gonzalez Master


Registrado: 01 Oct 2002Mensajes: 2155Ubicación: San Cristóbal de Las Casas, Chiapas
|
Publicado: Dom 10 Ene, 2010 9:30 am Asunto: |
|
|
| Código: | ...
Memo1.Lines.AddStrings(TIdText(Msg.MessageParts.Items[intIndex]).Body);
...
|
Por esta forma
| Código: | Memo1->Lines->AddStrings(dynamic_cast<TIdText*>(Msg->MessageParts->Items[intIndex])->Body); |
_________________
 |
|
| Volver arriba |
|
 |
Angel Master


Registrado: 15 Abr 2003Mensajes: 2311Ubicación: Toledo (España)
|
Publicado: Dom 10 Ene, 2010 10:04 am Asunto: |
|
|
[quote="César C. Salazar González"][code] Memo1-> Lines-> AddStrings (dynamic_cast <TIdText> (MSG-> MessageParts-> items [intIndex]) -> Body);[/ code][/ quote]
¡Perfecto! ¡Eres un monstruo César! _________________ Un saludo
Necesitamos tu ayuda: Envía AI al 27595 (Coste 1,20 euros + IVA) |
|
| Volver arriba |
|
 |
Angel Master


Registrado: 15 Abr 2003Mensajes: 2311Ubicación: Toledo (España)
|
Publicado: Mie 13 Ene, 2010 5:05 pm Asunto: |
|
|
Me está ocurriendo algo que no acabo de entender. Mirando la ayuda de este objeto TIdPOP3 veo que hay tres métodos:
- RetrieveHeader, que recupera las cabeceras del mensaje en un TIdMessage.
- Retrieve, que debería recuperar el cuerpo del mensaje en ese mismo TIdMessage.
- RetrieveRaw, que recupera todo el mensaje en un TStringList.
Mientras el primero y el último funcionan sin problemas, al ejecutar el segundo siempre me lo devuelve vacío. Por más vueltas que le he dado a la ayuda y al ejemplo que viene (aunque esté en Pascal) no soy capaz de recuperar el mensaje. El código Pascal es este:
| Código: | for intIndex := 0 to Pred(Msg.MessageParts.Count) do
begin
if (Msg.MessageParts.Items[intIndex] is TIdAttachment) then
begin //general attachment
pnlAttachments.visible := true;
li := lvMessageParts.Items.Add;
li.ImageIndex := 8;
li.Caption := TIdAttachment(Msg.MessageParts.Items[intIndex]).Filename;
li.SubItems.Add(TIdAttachment(Msg.MessageParts.Items[intIndex]).ContentType);
end
else
begin //body text
if Msg.MessageParts.Items[intIndex] is TIdText then
begin
Memo1.Lines.Clear;
Memo1.Lines.AddStrings(TIdText(Msg.MessageParts.Items[intIndex]).Body);
end
end;
end; |
_________________ Un saludo
Necesitamos tu ayuda: Envía AI al 27595 (Coste 1,20 euros + IVA) |
|
| Volver arriba |
|
 |
|