ExtraHeaders.pas 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. { $HDR$}
  2. {**********************************************************************}
  3. { Unit archived using Team Coherence }
  4. { Team Coherence is Copyright 2002 by Quality Software Components }
  5. { }
  6. { For further information / comments, visit our WEB site at }
  7. { http://www.TeamCoherence.com }
  8. {**********************************************************************}
  9. {}
  10. { $Log: 11243: ExtraHeaders.pas
  11. {
  12. { Rev 1.1 2003.07.11 4:07:42 PM czhower
  13. { Removed deprecated BXBoxster reference.
  14. }
  15. {
  16. { Rev 1.0 11/12/2002 09:17:06 PM JPMugaas
  17. { Initial check in. Import from FTP VC.
  18. }
  19. unit ExtraHeaders;
  20. interface
  21. uses
  22. Classes,
  23. IndyBox;
  24. type
  25. TExtraHeadersBox = class (TIndyBox)
  26. public
  27. procedure Test; override;
  28. end;
  29. implementation
  30. uses
  31. IdGlobal,
  32. IdMessage,
  33. SysUtils, IdAttachmentFile, IdText;
  34. const
  35. ExHdrNames: array[1..2] of string = ('MyExtraHeader', 'MyLongHeader');
  36. ExHdrValues: array[1..2] of string =
  37. ('09823j4lknsdkf80923j4k',
  38. 'lakjsdf289034j234jskyldjflsk djflskd23 923874nc92 jlsdf78 j234lk 234 23203948 20934 0293i'
  39. );
  40. ContentID: string = '<73829274893.90238490.hkjsdhfsk>';
  41. { TExtraHeadersBox }
  42. procedure TExtraHeadersBox.Test;
  43. var
  44. Msg: TIdMessage;
  45. Att: TIdAttachmentFile;
  46. i: integer;
  47. begin
  48. Msg := TIdMessage.Create(nil);
  49. Att := TIdAttachmentFile.Create(Msg.MessageParts, GetDataDir+'test.bmp');
  50. try
  51. Status('Creating message');
  52. for i := low(ExHdrNames) to High(ExHdrNames) do begin
  53. Att.ExtraHeaders.Values[ExHdrNames[i]] := ExHdrValues[i];
  54. end;
  55. Att.ContentID := ContentID;
  56. Att.FileName := 'test.bmp';
  57. Msg.SaveToFile(GetTempDir()+'test.msg');
  58. Status('Message saved');
  59. finally
  60. Msg.Free;
  61. end;
  62. Msg := TIdMessage.Create(nil);
  63. try
  64. Status('Loading message');
  65. Msg.LoadFromFile(GetTempDir()+'test.msg');
  66. Check(Msg.MessageParts.Count = 2, 'Wrong messagepart count ('+IntToStr(Msg.MessageParts.Count)+')!');
  67. Check(Msg.MessageParts.Items[0] is TIdText, 'Wrong type of attachment in #1');
  68. Check(Msg.MessageParts.Items[1] is TIdAttachmentFile, 'Wrong type of attachment in #2');
  69. Att := TIdAttachmentFile(Msg.MessageParts.Items[1]);
  70. Check(Att.FileName = 'test.bmp', 'Filename of Attachment lost');
  71. for i:=low(ExHdrNames) to High(ExHdrNames) do begin
  72. Check(Att.ExtraHeaders.Values[ExHdrNames[i]] = ExHdrValues[i], 'Extra header '+ExHdrNames[i]+' was lost/garbled!');
  73. end;
  74. Check(Att.ContentID = ContentID, 'Content-ID lost/garbled!');
  75. finally
  76. Msg.Free;
  77. end;
  78. end;
  79. initialization
  80. TIndyBox.RegisterBox(TExtraHeadersBox, 'ExtraHeaders', 'Message');
  81. end.