begin process at 2010 02 10 00:07:11
  Trouver un code source :
 
dans
 
Accueil > Forum > 

Delphi

 > 

Réseau & Internet

 > 

Autre

 > 

extraire le fax d'un mail


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

extraire le fax d'un mail

jeudi 1 février 2007 à 17:11:42 | extraire le fax d'un mail

chrisledeveloppeur

Bonjour, je réalise une appli qui lorsque l'on y glisse un mail n'importe où dans sa fiche , enregistre ce mail en fichier eml dans un répertoire, ses pièces jointes comprises. le problème reste que je souhaite filtrer les fax reçus par mail vers un traitement spécial pour n'enregistrer que le fichier TIF associé au fax joint dans le mail. Je ne parviens pas à dissocier les fichiers TIF des fichiers joints en général, tous associés au même type de format presse papier. En effet, le cformat retourné est toujours le même nombre, quelquesoit la pièce jointe.
Voici un code général dont je me suis inspiré pour récupérer le mail et son contenu droppé:
[CODE]

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ComObj, ActiveX, ShlObj;

type
  // Form that acts as IDropTarget
  TForm1         =  class(TForm, IDropTarget)
    procedure    FormCreate(Sender: TObject);
    procedure    FormClose(Sender: TObject; var Action: TCloseAction);
  private
     // Private declarations
     function    SaveAsStg(FileNameBase: String; dataObj: IDataObject; fmt: tagFORMATETC): Boolean;
     function    SaveAsStm(FileNameBase: String; dataObj: IDataObject; fmt: tagFORMATETC): Boolean;
     function    SaveAsMem(FileNameBase: String; dataObj: IDataObject; fmt: tagFORMATETC): Boolean;
  protected
     // Protected declarations
     function    DragEnter(const dataObj: IDataObject; grfKeyState: Longint; pt: TPoint; var dwEffect: Longint): HResult; stdcall;
     function    DragOver(grfKeyState: Longint; pt: TPoint; var dwEffect: Longint): HResult; reintroduce; stdcall;
     function    DragLeave: HResult; stdcall;
     function    Drop(const dataObj: IDataObject; grfKeyState: Longint; pt: TPoint; var dwEffect: Longint): HResult; stdcall;
  public
     // Public declarations

  end;

// Acceptable format types
const
  CF_Acceptable:          Array [0..1] of String =   ('RenPrivateMessages',
                                                      'Internet Message (rfc822/rfc1522)');

// Predefined clipboard formats
const
  CF_PredfinedFormats:    Array [1..15] of String =  ('Text',
                                                      'Bitmap',
                                                      'MetaFile',
                                                      'SYLK',
                                                      'DIF',
                                                      'TIFF',
                                                      'OemText',
                                                      'DIB',
                                                      'Palette',
                                                      'Pen Data',
                                                      'RIFF',
                                                      'Wave',
                                                      'Unicode Text',
                                                      'Enhanced Metafile',
                                                      'HDrop');

var
  Form1:         TForm1;

implementation
{$R *.DFM}

function TForm1.DragEnter(const dataObj: IDataObject; grfKeyState: Longint; pt: TPoint; var dwEffect: Longint): HResult;
var  pEFETC:     IEnumFORMATETC;
     FmtETC:     tagFORMATETC;
     lpszFormat: Array [0..255] of Char;
     szFormat:   String;
     dwAllow:    Integer;
     dwfetch:    Integer;
     bAllow:     Boolean;
begin

  // Clear the format string
  szFormat:='';

  // Determine if we want to support the drop of this type
  bAllow:=False;
  if (dataObj.EnumFormatEtc(DATADIR_GET, pEFETC) = S_OK) then
  begin
     // Start the fetch enumeration
     while (pEFETC.Next(1, FmtETC, @dwfetch) = S_OK) do
     begin
        // Attempt to get the clipboard format name
        if (FmtETC.cfFormat in [1..15]) then
           szFormat:=CF_PredfinedFormats[FmtETC.cfFormat]
        else if (GetClipboardFormatName(FmtETC.cfFormat, lpszFormat, SizeOf(lpszFormat)) > 0) then
           szFormat:=lpszFormat
        else
           szFormat:=IntToStr(FmtETC.cfFormat);
        // Compare formats
        for dwAllow:=0 to High(CF_Acceptable) do
        begin
           if (CompareText(CF_Acceptable[dwAllow], szFormat) = 0) then
           begin
              bAllow:=True;
              if bAllow then break;
           end;
        end;
        if bAllow then break;
     end;
     // Release the enumerator
     pEFETC:=nil;
  end;

  // Should we allow the enter?
  result:=NOERROR;
  if not(bAllow) then dwEffect:=DROPEFFECT_NONE;

end;

function TForm1.DragOver(grfKeyState: Longint; pt: TPoint; var dwEffect: Longint): HResult;
begin

  // Allow the drag over
  result:=NOERROR;

end;

function TForm1.DragLeave: HResult;
begin

  // Allow the drag leave
  result:=NOERROR;

end;

function TForm1.SaveAsStg(FileNameBase: String; dataObj: IDataObject; fmt: tagFORMATETC): Boolean;
var  medium:     TStgMedium;
     pvStg:      IStorage;
begin

  // Set default result
  result:=False;

  // Set tymed
  fmt.tymed:=TYMED_ISTORAGE;

  // Get the data
  if (dataObj.GetData(fmt, medium) = S_OK) then
  begin
     // Create storage file
     if (StgCreateDocfile(PWideChar(WideString(FileNameBase+'.msg')),
        STGM_CREATE or STGM_READWRITE or STGM_SHARE_EXCLUSIVE , 0, pvStg) = S_OK) then
     begin
        // Copy from the dropped storage
        result:=(IStorage(medium.stg).CopyTo(0, nil, nil, pvStg) = S_OK);
        // Release the storage interface
        pvStg:=nil;
     end;
     // We are responsible for releasing the storage medium
     IStorage(medium.stg):=nil;
  end;

end;

function TForm1.SaveAsStm(FileNameBase: String; dataObj: IDataObject; fmt: tagFORMATETC): Boolean;
var  msStream:   TMemoryStream;
     pvStm:      IStream;
     medium:     TStgMedium;
     stat:       TStatStg;
     dwSize:     Integer;
begin

  // Set default result
  result:=False;

  // Set tymed
  fmt.tymed:=TYMED_ISTREAM;

  // Get the data
  if (dataObj.GetData(fmt, medium) = S_OK) then
  begin
     // Get the stream
     pvStm:=IStream(medium.stm);
     // Stat to get the size
     if (pvStm.Stat(stat, STATFLAG_NONAME) = S_OK) then
     begin
        // Create memory stream for output
        msStream:=TMemoryStream.Create;
        msStream.Size:=stat.cbSize;
        if (IStream(medium.stm).Read(msStream.Memory, stat.cbSize, @dwSize) = S_OK) then
        begin
           msStream.Size:=dwSize;
           msStream.Position:=0;
           msStream.SaveToFile(FileNameBase+'.eml');
           result:=True;
        end;
        msStream.Free;
     end;
     // Release the stream interface
     IStream(medium.stm):=nil;
  end;

end;

function TForm1.SaveAsMem(FileNameBase: String; dataObj: IDataObject; fmt: tagFORMATETC): Boolean;
var  msStream:   TMemoryStream;
     medium:     TStgMedium;
     stat:       TStatStg;
     lpMem:      Pointer;
     dwSize:     Integer;
begin

  // Set default result
  result:=False;

  // Set tymed
  fmt.tymed:=TYMED_HGLOBAL;

  // Get the data
  if (dataObj.GetData(fmt, medium) = S_OK) then
  begin
     // Get the memory and lock it
     lpMem:=GlobalLock(medium.hGlobal);
     // Create memory stream for output
     msStream:=TMemoryStream.Create;
     msStream.Write(lpMem^, GlobalSize(medium.hGlobal));
     msStream.SaveToFile(FileNameBase+'.eml');
     result:=True;
     msStream.Free;
     // Unlock and free the memory
     GlobalUnlock(medium.hGlobal);
     GlobalFree(medium.hGlobal);
  end;

end;

function TForm1.Drop(const dataObj: IDataObject; grfKeyState: Longint; pt: TPoint; var dwEffect: Longint): HResult;
var  pEFETC:     IEnumFORMATETC;
     FmtETC:     tagFORMATETC;
     msStream:   TMemoryStream;
     cfEml:      Integer;
     cfFile:     Integer;
     pvStg:      IStorage;
     medium:     TStgMedium;
     bHandle:    Boolean;
     dwFetch:    Integer;
     i64Size:    Int64;
     i64Move:    Int64;
begin

  // Set result
  result:=NOERROR;

  // Enumerate until we get are able to save the contents
  bHandle:=False;
  cfFile:=RegisterClipboardFormat(CFSTR_FILECONTENTS);
  cfEml:=RegisterClipboardFormat('Internet Message (rfc822/rfc1522)');
  if (dataObj.EnumFormatEtc(DATADIR_GET, pEFETC) = S_OK) then
  begin
     // Start the fetch enumeration
     while (pEFETC.Next(1, FmtETC, @dwfetch) = S_OK) do
     begin
        // Check file contents
        if (FmtETC.cfFormat = cfFile) then
        begin
           // Try as storage first, then stream
           if ((FmtETC.cfFormat and TYMED_ISTORAGE) = TYMED_ISTORAGE) then
           begin
              if SaveAsStg('Test', dataObj, FmtEtc) then break;
           end;
           if ((FmtETC.cfFormat and TYMED_ISTREAM) = TYMED_ISTREAM) then
           begin
              if SaveAsStm('Test', dataObj, FmtEtc) then break;
           end;
        end
        // Check for eml
        else if (FmtETC.cfFormat = cfEml) then
        begin
           if SaveAsMem('Test', dataObj, FmtEtc) then break;
        end;
     end;
  end;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin

  // Register the form as a drop target
  RegisterDragDrop(Handle, Self);

end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin

  // Revoke the form as a drop target
  RevokeDragDrop(Handle);

end;

initialization

  // Initialize ole
  OleInitialize(nil);

finalization

  // Uninitialize ole
  OleUninitialize;

end.


[/CODE]

 

J'ai eu l'idée également de sauvegarder d'abord tout le mail puis de l'ouvrir en faisant l'extraction du TIF avant sa suppression. Traitement de bidouille je sais. Mais de toute façon, je n'ai pas trouvé le composant standard permettant de lire un fichier EML local (sans passer par un client server de mail). L'idée serait de partir d'un chargement dans un memorystream mais aprés je ne sais pas comment faire pour l'associer à par exemple un MailMessage me permettant de lire le EML. Avez-vous une idée sur soit la solution d'extraire le TIF d'un EML local, soit de directement détecté un TIF en pièce jointe du mail droppé? Merci.

vendredi 2 février 2007 à 19:26:50 | Re : extraire le fax d'un mail

WhiteHippo

Membre Club
Bonsoir,

Voir ici le sujet "Decoding Dropped email messages" :
[ Lien ]  

P.S. La librairie LibTiffDelphi te sera peut être utile : [ Lien ]

Cordialement.

"L'imagination est plus importante que le savoir." Albert Einstein


Cette discussion est classée dans : end, begin, medium, dataobj, fmtetc


Répondre à ce message

Sujets en rapport avec ce message

probleme dans mon programme [ par tarik ] monsieur kerad je crois que j'ai un bug dans mon programme ci-dessousprocedure TForm1.Button1Click(Sender: TObject);begintable1.open;try Table1.First Datamodule et accès à partir d'une form [ par manudel ] Voilà, je voudrais avoir accès aux événements des objets figurant sur mon datamodule, mais je n'y arrive pas. J'ai l'erreur suivante : "le type de l'e Index d'un table Dbase [ par webazard ] Bonjour, je crée un base Dbase indiqué dans l'aide de delphi en remplacant ttparadox par ttdbase.en supprimant la construction d'index min prog marche Hints dans une DLL [ par almi ] J'ai une fenêtre (TForm) qui fonctionne parfaitement dans mon executable.Si je la place dans une DLL, j'obtiens le message :Ne peut assigner TFont à T Code 1 à tester [ par apz ] salut a tous,je voulais faire un filtrage sur une table en utlisant les numeros d'enregistrements pour marquer les record et ensuite applique une requ Champs Chamboulés [ par apz ] Salut,1- En voulant avoir une table *.DB à partir d'une table *.DBF, en utilisant le Module Base de Données (Outils/Utilitaires/Copier), j'avais dans Erreur incomprehensible [ par intello2001 ] j'ai lerreur suivante :Unsatisfied forward or external declaration: Tform1....je pesne que c une kestion de end et begin dans mon code : else if TServerSocket en Multithread [ par Cyrille2 ] Salut... je bloque à mort sur un bug... en faite, impossible de lire le socketstream voila la procédure : Code: procedure TServerThread.ClientExecute; Déplacement [ par MAsterC ] Bonjourj'ai besoin d'information en Delphij'ai fait ceci !procedure TModule.TitleBarMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);begi pb avec direct x, y'a pas d'erreur mais ça marche pas ! :-( [ par dweis ] j'essaie de faire un truc assez simple mais j'ai du mal : je veux juste créer une fenetre et initialiser directx.je me suis inspiré de ce code http://


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,499 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales