11 TIdQuotedPrintableEncoder
= object(TIdCoder
)
13 FQPOutputString
: string;
14 procedure QPOutput(const sOut
: string); virtual;
15 function ToQuotedPrintable(const b
: Byte): string;
16 procedure Coder
; virtual;//override;
17 procedure CompleteCoding
; virtual;//override;
20 { constructor Create(AOwner: TComponent); override;
23 virtual; procedure Reset
; virtual;//override;
25 PIdQuotedPrintableEncoder
=^TIdQuotedPrintableEncoder
;
26 function NewIdQuotedPrintableEncoder(AOwner
: PControl
):PIdQuotedPrintableEncoder
;
29 TIdQuotedPrintableDecoder
= object(TIdCoder
)
33 procedure Coder
; virtual;//override;
34 procedure CompleteCoding
; virtual;//override;
36 { constructor Create(AOwner: TComponent); override;
39 virtual; procedure Reset
; virtual;//override;
41 PIdQuotedPrintableDecoder
=^TIdQuotedPrintableDecoder
;
42 function NewIdQuotedPrintableDecoder(AOwner
: PControl
):PIdQuotedPrintableDecoder
;
53 QPEDBDIC
= '!"#$@[\]^`{|}~';
55 function NewIdQuotedPrintableEncoder(AOwner
: PControl
):PIdQuotedPrintableEncoder
;
56 //constructor TIdQuotedPrintableEncoder.Create;
58 // inherited Create(AOwner);
59 New( Result
, Create
);
63 FQPOutputString
:= '';
67 destructor TIdQuotedPrintableEncoder
.Destroy
;
72 procedure TIdQuotedPrintableEncoder
.Reset
;
74 FQPOutputString
:= '';
77 procedure TIdQuotedPrintableEncoder
.Coder
;
85 while i
<= FCBufferSize
do
87 b
:= Byte(FCBuffer
[i
]);
88 if (b
>= QPLowBound
) and (b
<= QPHighBound
) then
90 if b
= QPMidBound
then
92 s
:= s
+ ToQuotedPrintable(QPMidBound
);
95 if IndyPos(Char(b
), QPEDBDIC
) > 0 then
97 s
:= s
+ ToQuotedPrintable(b
);
108 if i
< FCBufferSize
then
110 if FCBuffer
[i
+ 1] = LF
then
117 s
:= s
+ ToQuotedPrintable(b
);
123 FCBuffer
[1] := Char(b
);
130 s
:= s
+ ToQuotedPrintable(b
);
139 procedure TIdQuotedPrintableEncoder
.QPOutput
;
144 FQPOutputString
:= FQPOutputString
+ sOut
;
145 i
:= IndyPos(EOL
, FQPOutputString
);
148 s
:= Copy(FQPOutputString
, 1, i
- 1);
149 FQPOutputString
:= Copy(FQPOutputString
, i
+ 2, length(FQPOutputString
));
156 s
:= s
+ Copy(ToQuotedPrintable(Byte(s
[i
])), 2, 2);
168 i
:= IndyPos(EOL
, FQPOutputString
);
170 while length(FQPOutputString
) > 75 do
172 if FQPOutputString
[73] = '=' then
177 if FQPOutputString
[74] = '=' then
182 if FQPOutputString
[75] = '=' then
190 OutputString(Copy(FQPOutputString
, 1, i
) + '=');
191 FQPOutputString
:= Copy(FQPOutputString
, i
+ 1, length(FQPOutputString
));
195 procedure TIdQuotedPrintableEncoder
.CompleteCoding
;
199 fInCompletion
:= True;
201 // InternSetBufferSize(FCBufferedData);
202 FCBufferedData
:= FCBufferSize
;
203 if FCBufferedData
> 0 then
207 if FCBufferedData
> 0 then
209 QPOutput(ToQuotedPrintable(13));
211 j
:= Length(FQPOutputString
);
214 case FQPOutputString
[j
] of
217 FQPOutputString
:= FQPOutputString
+ Copy(ToQuotedPrintable(
218 Byte(FQPOutputString
[j
])), 2, 2);
219 FQPOutputString
[j
] := '=';
222 while length(FQPOutputString
) > 75 do
224 if FQPOutputString
[73] = '=' then
229 if FQPOutputString
[74] = '=' then
234 if FQPOutputString
[75] = '=' then
242 OutputString(Copy(FQPOutputString
, 1, i
) + '=');
243 FQPOutputString
:= Copy(FQPOutputString
, i
+ 1, length(FQPOutputString
));
245 OutputString(FQPOutputString
);
247 // InternSetBufferSize(i);
251 function TIdQuotedPrintableEncoder
.ToQuotedPrintable
;
253 result
:= '=' + UpperCase(Int2Hex(b
, 2));
256 function NewIdQuotedPrintableDecoder(AOwner
: PControl
):PIdQuotedPrintableDecoder
;
257 //constructor TIdQuotedPrintableDecoder.Create;
259 // inherited Create(AOwner);
260 New( Result
, Create
);
264 SetLength(fQPTriple
, 2);
265 UniqueString(fQPTriple
);
271 destructor TIdQuotedPrintableDecoder
.Destroy
;
276 procedure TIdQuotedPrintableDecoder
.Reset
;
282 procedure TIdQuotedPrintableDecoder
.Coder
;
288 function IsHex(c
: Char): Boolean;
291 '0'..'9', 'a'..'f', 'A'..'F':
303 while i
<= FCBufferedData
do
306 if fInTriple
> 0 then
308 fQPTriple
[fInTriple
] := c
;
311 if fInTriple
>= 3 then
313 if IsHex(fQPTriple
[1]) and IsHex(fQPTriple
[2]) then
315 s
:= s
+ Chr(Str2Int('$' + fQPTriple
));
318 if (fQPTriple
[1] = CR
) and (fQPTriple
[2] = LF
) then
323 s
:= s
+ '=' + fQPTriple
;
343 procedure TIdQuotedPrintableDecoder
.CompleteCoding
;
345 fInCompletion
:= True;
347 if fInTriple
> 0 then
349 OutputString(Copy(fQPTriple
, 1, fInTriple
- 1));
355 { RegisterCoderClass(TIdQuotedPrintableEncoder, CT_CREATION, CP_STANDARD,
356 '', 'quoted-printable');
357 RegisterCoderClass(TIdQuotedPrintableDecoder, CT_REALISATION, CP_STANDARD,
358 '', 'quoted-printable');}