| View previous topic :: View next topic |
| Author |
Message |
Donald Bossen Guest
|
Posted: Mon Nov 29, 2004 11:56 pm Post subject: in SMTP Onworkbegin geting AWorkCountMax of Zero |
|
|
Since acording to the Help AWorkCountMax = 0 is Bytes unknown. is there
away to estimate the total Bytes when SMTP an attachment ie FileSize + ???.
Thanks
Donald S. Bossen
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Tue Nov 30, 2004 12:07 am Post subject: Re: in SMTP Onworkbegin geting AWorkCountMax of Zero |
|
|
"Donald Bossen" <sbossen (AT) jbimporters (DOT) com> wrote
| Quote: | Since acording to the Help AWorkCountMax = 0 is Bytes unknown.
is there away to estimate the total Bytes when SMTP an attachment
|
The only way to estimate the size of TIdMessage prior to sending it is to
save the TIdMessage to a temporary file or stream first, and then use the
size of that instead.
Gambit
|
|
| Back to top |
|
 |
Lee_Nover Guest
|
Posted: Tue Nov 30, 2004 6:04 am Post subject: Re: in SMTP Onworkbegin geting AWorkCountMax of Zero |
|
|
| Quote: | Since acording to the Help AWorkCountMax = 0 is Bytes unknown.
is there away to estimate the total Bytes when SMTP an attachment
The only way to estimate the size of TIdMessage prior to sending it isto
save the TIdMessage to a temporary file or stream first, and then use the
size of that instead.
|
that's an actual size .. but would mean double streaming ..
I use an estimate just to display some progress
(DSiFileSize is just a method to get a file's size)
function GetApproxMessageSize(AMsg: TIdMessage): Integer;
var
I: Integer;
begin
Result := 0;
Inc(Result, Length(AMsg.BccList.EMailAddresses));
Inc(Result, Length(AMsg.CcList.EMailAddresses));
Inc(Result, Length(AMsg.Body.Text));
Inc(Result, Length(AMsg.From.Text));
Inc(Result, Length(AMsg.ExtraHeaders.Text));
Inc(Result, Length(AMsg.Headers.Text));
Inc(Result, Length(AMsg.Recipients.EMailAddresses));
Inc(Result, Length(AMsg.ReplyTo.EMailAddresses));
Inc(Result, Length(AMsg.References));
Inc(Result, Length(AMsg.Subject));
for I:=0 to AMsg.MessageParts.Count-1 do
if AMsg.MessageParts[I] is TIdAttachment then
Inc(Result,
DSiFileSize(TIdAttachment(AMsg.MessageParts[I]).StoredPathName))
else if AMsg.MessageParts[I] is TIdText then
Inc(Result, Length(TIdText(AMsg.MessageParts[I]).Body.Text));
Result:=Round(Result * 1.2);
end;
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Tue Nov 30, 2004 8:01 am Post subject: Re: in SMTP Onworkbegin geting AWorkCountMax of Zero |
|
|
"Lee_Nover" <Lee_Nover[nospam]@delphi-si.com> wrote
| Quote: | that's an actual size ..
|
Almost an exact size. Due to the dynamic nature of TIdMessage, you would
not be guaranteed to have the exact same data produced every time the
TIdMessage is streamed. There might be some slight variations, which could
produce slightly different Sizes. But they would be close enough if all you
are interested in is progress tracking.
| Quote: | but would mean double streaming ..
|
Yes, it does. But it is the only option that Indy supports.
| Quote: | I use an estimate just to display some progress (DSiFileSize
is just a method to get a file's size)
|
There is no estimation supported by Indy. What your manual code is failing
to take into account is all of the encoding and formatting that takes place
during the TIdMessage streaming. That is going to throw your estimation way
off.
Gambit
|
|
| Back to top |
|
 |
Lee_Nover Guest
|
Posted: Tue Nov 30, 2004 9:11 am Post subject: Re: in SMTP Onworkbegin geting AWorkCountMax of Zero |
|
|
| Quote: | There is no estimation supported by Indy. What your manual code is
failing
to take into account is all of the encoding and formatting that takes
|
I know .. a tradeoff I made
the exact progress isn't important .. encoding large files twice is not an
option
... so I just estimate the size .. for the encodings I just add 20% to the
overall size
seems to work just fine :)
|
|
| Back to top |
|
 |
Donald Bossen Guest
|
Posted: Wed Dec 01, 2004 2:37 pm Post subject: Re: in SMTP Onworkbegin geting AWorkCountMax of Zero |
|
|
The Email I am sending is relative Small in size thus saving to a temp
file is acceptable Below is the code I am using to compute the total and
percent of file transmited. I am getting a percent in the range of 74%
which means the total bytes to send is more tha the actual bits sent.
Any ideas on how to Correct?
Thanks
Donald S. Bossen
procedure TFrmSendOrder.IdSMTPWorkBegin(Sender: TObject;
AWorkMode: TWorkMode; const AWorkCountMax: Integer);
begin
TotalToSend := AWorkCountMax;
if TotalToSend <= 0 then
TotalToSend := GetApproxMessageSize;
end;
procedure TFrmSendOrder.IdSMTPWork(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCount: Integer);
begin
FrmOrderSoup.Progress.Percent := round(100 *(AWorkCount /
TotalToSend));
end;
function TFrmSendOrder.GetApproxMessageSize : Integer;
function DSiFileSize(FileName : String) : Integer;
var
f: file of Byte;
begin
system.AssignFile(f, FileName);
Reset(f);
try
result := FileSize(f);
finally
CloseFile(f);
end;
end;
begin
with IdMessage do
begin
if FileExists('C:Soup.txt') then DeleteFile('C:Soup.txt');
IdMessage.SaveToFile('C:Soup.txt');
result := DSiFileSize('C:Soup.txt');
end;
end;
Remy Lebeau (TeamB) wrote:
| Quote: | "Donald Bossen"
news:41ABB72E.9030909 (AT) jbimporters (DOT) com...
Since acording to the Help AWorkCountMax = 0 is Bytes unknown.
is there away to estimate the total Bytes when SMTP an attachment
The only way to estimate the size of TIdMessage prior to sending it is to
save the TIdMessage to a temporary file or stream first, and then use the
size of that instead.
Gambit
|
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Wed Dec 01, 2004 6:45 pm Post subject: Re: in SMTP Onworkbegin geting AWorkCountMax of Zero |
|
|
"Donald Bossen" <sbossen (AT) jbimporters (DOT) com> wrote
| Quote: | The Email I am sending is relative Small in size thus saving to
a temp file is acceptable Below is the code I am using to compute
the total and percent of file transmited. I am getting a percent in the
range of 74% which means the total bytes to send is more tha the
actual bits sent.
|
You are not taking into account that OnWork may not be triggered for the
last data block sent. You should set your progress to 100% in the OnWorkEnd
event.
Gambit
|
|
| Back to top |
|
 |
|