IdText.pas 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. {
  2. $Project$
  3. $Workfile$
  4. $Revision$
  5. $DateUTC$
  6. $Id$
  7. This file is part of the Indy (Internet Direct) project, and is offered
  8. under the dual-licensing agreement described on the Indy website.
  9. (http://www.indyproject.org/)
  10. Copyright:
  11. (c) 1993-2005, Chad Z. Hower and the Indy Pit Crew. All rights reserved.
  12. }
  13. {
  14. $Log$
  15. }
  16. {
  17. Rev 1.5 10/26/2004 10:49:20 PM JPMugaas
  18. Updated ref.
  19. Rev 1.4 16/05/2004 18:56:16 CCostelloe
  20. New TIdText/TIdAttachment processing
  21. Rev 1.3 2004.02.03 5:44:34 PM czhower
  22. Name changes
  23. Rev 1.2 10/17/03 12:06:50 PM RLebeau
  24. Updated Assign() to copy all available header values rather than select ones.
  25. Rev 1.1 10/17/2003 1:11:14 AM DSiders
  26. Added localization comments.
  27. Rev 1.0 11/13/2002 08:03:00 AM JPMugaas
  28. 2002-08-30 Andrew P.Rubin
  29. - extract charset & IsBodyEncodingRequired (true = 8 bit)
  30. }
  31. unit IdText;
  32. interface
  33. {$i IdCompilerDefines.inc}
  34. uses
  35. Classes,
  36. IdMessageParts;
  37. type
  38. TIdText = class(TIdMessagePart)
  39. protected
  40. FBody: TStrings;
  41. procedure SetBody(const AStrs : TStrings); virtual;
  42. public
  43. constructor Create(Collection: TIdMessageParts; ABody: TStrings = nil); reintroduce;
  44. destructor Destroy; override;
  45. procedure Assign(Source: TPersistent); override;
  46. function IsBodyEncodingRequired: Boolean;
  47. class function PartType: TIdMessagePartType; override;
  48. //
  49. property Body: TStrings read FBody write SetBody;
  50. end;
  51. implementation
  52. uses
  53. IdGlobal, IdGlobalProtocols,
  54. SysUtils;
  55. { TIdText }
  56. procedure TIdText.Assign(Source: TPersistent);
  57. begin
  58. if Source is TIdText then begin
  59. Body.Assign(TIdText(Source).Body);
  60. end;
  61. // allow TIdMessagePart to copy the headers
  62. inherited Assign(Source);
  63. end;
  64. constructor TIdText.Create(Collection: TIdMessageParts; ABody: TStrings = nil);
  65. begin
  66. inherited Create(Collection);
  67. FBody := TStringList.Create;
  68. TStringList(FBody).Duplicates := dupAccept;
  69. if ABody <> nil then begin
  70. FBody.Assign(ABody);
  71. end;
  72. end;
  73. destructor TIdText.Destroy;
  74. begin
  75. FBody.Free;
  76. inherited Destroy;
  77. end;
  78. function TIdText.IsBodyEncodingRequired: Boolean;
  79. var
  80. i, j: Integer;
  81. S: String;
  82. begin
  83. Result := False;//7bit
  84. for i := 0 to FBody.Count-1 do begin
  85. S := FBody[i];
  86. for j := 1 to Length(S) do begin
  87. if S[j] > #127 then begin
  88. Result := True;
  89. Exit;
  90. end;
  91. end;
  92. end;
  93. end;
  94. class function TIdText.PartType: TIdMessagePartType;
  95. begin
  96. Result := mptText;
  97. end;
  98. procedure TIdText.SetBody(const AStrs: TStrings);
  99. begin
  100. FBody.Assign(AStrs);
  101. end;
  102. initialization
  103. // RegisterClasses([TIdText]);
  104. end.