📄 fcompose.pas
字号:
FCaption := _(Self.Caption);
//controls are filled at runtime because it is easier for translator
//to find out where and how to translate items.
FreeAndNil(l);
//form: Compose, control: e-mail address type
cmboxMailType.Items.Text := _('To:' + #13#10 +
'CC:' + #13#10 +
'BCC:' + #13#10 +
'Reply-To:');
//form: Compose, control: send message as type (format)
cmboxMsgType.Strings.Text := _('Plain text' + #13#10 +
'html' + #13#10 +
'Plain & html');
//form: Compose, control: message priority
cmboxPriority.Strings.Text := _('Lowest' + #13#10 +
'Low' + #13#10 +
'Normal' + #13#10 +
'High' + #13#10 +
'Highest');
actOptionsAutoComplete.Checked := frmMailbox.Profile.Config.ReadBool('frmCompose', 'autoComplete', True);
if actOptionsAutoComplete.Checked then
txtMail.Items := frmMailbox.AutoCompleteList;
end;
procedure TfrmCompose.FormResize(Sender: TObject);
begin
if csDestroyingHandle in Self.ControlState then exit;
lstAddresses.Header.Columns[0].Width := Trunc(lstAddresses.Width * 0.35);
cmboxAccount.Width := lstAddresses.Width - lstAddresses.Header.Columns[0].Width - 2;
cmboxAccount.Left := lstAddresses.Header.Columns[0].Width;
txtSubject.Width := pnlSubject.Width - txtSubject.Left - 8;
cmboxSignature.Left := 0;
cmboxSignature.Width := pnlSig.Width
end;
procedure TfrmCompose.cmboxAccountClick(Sender: TObject);
begin
FAccount := Integer(emailList.Objects[Integer(cmboxAccount.Items.Objects[cmboxAccount.ItemIndex])]);
askForSave := True;
end;
procedure TfrmCompose.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if lstAddresses.IsEditing then
lstAddresses.EndEditNode;
//save message if required
Action := caFree;
if askForSave then begin
case MessageDlg(_('Message has changed do you want to save it?'), mtConfirmation, [mbYes, mbNo, mbCancel] , 0) of
mrYes: begin
//save message
if buildMessage < 0 then
Action := caNone;
end;
mrCancel: Action := caNone; //exit close
else
Action := caFree;
end;
end;
end;
procedure TfrmCompose.actTBSendLaterExecute(Sender: TObject);
begin
actFileSendLater.Execute;
end;
procedure TfrmCompose.LoadOld(msgIdx: Integer; loadStream: TStream);
var descr: TMsgDescription;
var msg: TMemoryStream;
var OldMsgFlat: TFlatMsg;
var i: Integer;
var lst: TStringList;
var str: String;
begin
lstAddresses.Clear;
if (msgIdx >= 0 ) and (loadStream = nil) then begin
msg := TMemoryStream(frmMailbox.Profile.Accounts[FAccount].Mailboxes
[FMailbox].GetMessageContent(msgIdx));
msg.Position := 0;
descr := frmMailbox.Profile.Accounts[FAccount].Mailboxes[
FMailbox].GetMessageDescription(msgIdx);
end
else
msg := TMemoryStream(loadStream);
if msg <> nil then begin
//parse doc
msg.Position := 0;
FOldMsgMime := TMimeMess.Create; //freed in onFormDestroy
FOldMsgMime.Lines.LoadFromStream(msg);
if (msgIdx > 0 ) and (loadStream = nil) then
FreeAndNil(msg); //we don't need it anymore;
Application.ProcessMessages; //let the application have time to clear all memory
FOldMsgMime.DecodeMessage;
//make message flat
OldMsgFlat := TFlatMsg.Create;
OldMsgFlat.MakeFlat(FOldMsgMime.MessagePart);
//load fields
case FEditType of
tetContinue: begin
if OldMsgFlat.MsgPartCount >= 1 then
OldMsgFlat.Parts[0].DecodePart;
cmboxPriority.ItemIndex := Integer(FOldMsgMime.Header.Priority);
if (msgIdx > 0 ) and (loadStream = nil) then begin
FoldAccountIdx := findAccountIndex(descr.account);
cmboxAccount.ItemIndex := findAliasIndex(FoldAccountIdx, GetEmailAddr(FOldMsgMime.Header.From));
end;
loadAddresses(FOldMsgMime);
frmMailView.LoadAttachments(lstAttachments, ilFiles, FOldMsgMime.Header.AttachList, True);
if OldMsgFlat.MsgPartCount >= 1 then
txtMessage.Lines.LoadFromStream(OldMsgFlat.Parts[0].DecodedLines);
txtSubject.Text := UTF8Decode(FOldMsgMime.Header.Subject);
cmboxSignature.ItemIndex :=
cmboxSignature.Items.IndexOf(UTF8Decode(FOldMsgMime.Header.Signature));
loadEmbededAttachments(OldMsgFlat);
end;//case
tetReply, tetReplyAll: begin
FoldAccountIdx := findAccountIndex(descr.account);
cmboxAccount.ItemIndex := findAliasIndex(FoldAccountIdx,
FOldMsgMime.Header.ToList.Text, FOldMsgMime.Header.CCList.Text);
if OldMsgFlat.MsgPartCount >= 1 then begin
txtMessage.Lines.Insert(0, '');
txtMessage.Lines.Insert(0, Format(_('%s wrote on %s:'),
[UTF8Decode(FOldMsgMime.Header.From), DateTimeToStr(descr.date)]));
processMimePart(OldMsgFlat.Parts[0]);
txtSubject.Text := reformatReplies(descr.subject);
if FEditType = tetReply then
addAddress(tatTo, UTF8Decode(FOldMsgMime.Header.From))
else begin //reply to all
str := LowerCase(extractEMail(cmboxAccount.Items[cmboxAccount.ItemIndex]));
for i := 0 to FOldMsgMime.Header.ToList.Count - 1 do begin
if Pos(str, LowerCase(FOldMsgMime.Header.ToList.Strings[i])) = 0 then
addAddress(tatTo, Trim(UTF8Decode(FOldMsgMime.Header.ToList.Strings[i])));
end;
for i := 0 to FOldMsgMime.Header.CCList.Count - 1 do begin
if Pos(str, LowerCase(FOldMsgMime.Header.CCList.Strings[i])) = 0 then
addAddress(tatCC, Trim(UTF8Decode(FOldMsgMime.Header.CCList.Strings[i])));
end;
addAddress(tatTo, UTF8Decode(FOldMsgMime.Header.From));
end; //if
end; //if
end; //case
tetForward: begin
FoldAccountIdx := findAccountIndex(descr.account);
cmboxAccount.ItemIndex := findAliasIndex(FoldAccountIdx,
FOldMsgMime.Header.ToList.Text, FOldMsgMime.Header.CCList.Text);
if OldMsgFlat.MsgPartCount >= 1 then begin
txtMessage.Lines.Insert(0, '');
txtMessage.Lines.Insert(0, Format(_('%s wrote on %s:'),
[UTF8Decode(FOldMsgMime.Header.From), DateTimeToStr(descr.date)]));
processMimePart(OldMsgFlat.Parts[0]);
txtSubject.Text := reformatForwards(descr.subject);
loadEmbededAttachments(OldMsgFlat);
end; //if
end; //case
end;
end;
FreeAndNil(OldMsgFlat);
addAddress(tatTo, '');
askForSave := False;
end;
procedure TfrmCompose.FormShow(Sender: TObject);
var i: Integer;
begin
//read self position & size
frmMailbox.Profile.Config.ReadControlSettings(Self, 'frmCompose');
loadUserSettings;
if FAccount < 0 then begin
FAccount := 0;
i := findAccountIndex(frmMailbox.Profile.Config.ReadString('frmMailbox', 'defaultAccount', ''));
cmboxAccount.ItemIndex := findAliasIndex(i, frmMailbox.Profile.Accounts[i].EMail);
end
else
cmboxAccount.ItemIndex := findAliasIndex(FAccount, frmMailbox.Profile.Accounts[FAccount].EMail);
if FmsgID >= 0 then
LoadOld(FmsgID)
else
selectCorrectSignature;
txtMessage.SelStart := 0;
txtMessage.SelLength := 0;
askForSave := False;
lstAddresses.EditNode(lstAddresses.GetFirst, 1);
end;
procedure TfrmCompose.FormShortCut(var Msg: TWMKey; var Handled: Boolean);
begin
if msg.CharCode = 27 then begin //esc key
Self.Close;
Handled := True;
end
else if msg.CharCode = 46 then begin //delete key
if GetFocus = lstAttachments.Handle then
deleteAttachments
else begin
Handled := False;
end;
end;
end;
procedure TfrmCompose.FormHide(Sender: TObject);
begin
//write self position & size
frmMailbox.Profile.Config.WriteControlSettings(Self, 'frmCompose');
end;
procedure TfrmCompose.actTBSignaturesExecute(Sender: TObject);
begin
frmMain.actToolsSignatures.Execute;
end;
procedure TfrmCompose.actTBAttachExecute(Sender: TObject);
begin
actInsertAttachment.Execute;
end;
procedure TfrmCompose.lstAttachmentsGetImageIndex(Sender: TBaseVirtualTree;
Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
var Ghosted: Boolean; var ImageIndex: Integer);
begin
//return correct attachment image
with PTreeAttach((Sender as TVirtualStringTree).GetNodeData(Node))^ do begin
if (Column = 0) and (Kind in [ikNormal, ikSelected]) then ImageIndex := iconId;
end;
end;
procedure TfrmCompose.lstAttachmentsGetNodeDataSize(Sender: TBaseVirtualTree;
var NodeDataSize: Integer);
begin
NodeDataSize := sizeOf(TTreeAttach);
end;
procedure TfrmCompose.lstAttachmentsGetText(Sender: TBaseVirtualTree;
Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
var CellText: WideString);
begin
//return each column's text
with PTreeAttach((Sender as TVirtualStringTree).GetNodeData(Node))^ do begin
case Column of
0:
begin
if mime <> nil then
CellText := mime.FileName
else
CellText := ExtractFileName(FileName);
end;
1:
begin
if size <> 0 then
CellText := frmMain.sizeToString(size)
else
CellText := '';
end;
end;
end;
end;
procedure TfrmCompose.actInsertAttachmentExecute(Sender: TObject);
begin
diOpen.Filter := _('All Files (*.*)|*.*');
diOpen.DefaultExt := '';
if diOpen.Execute then
frmMailView.loadAttachments(lstAttachments, ilFiles, TStringList(diOpen.Files), False);
updateAttachmentsSize;
end;
procedure TfrmCompose.loadUserSettings;
begin
cmboxPriority.ItemIndex := 2;
cmboxMsgType.ItemIndex := 0;
txtMessage.Font.Name := frmMailbox.Profile.Config.ReadString(
'frmCompose', 'fontName', txtMessage.Font.Name);
txtMessage.Font.Size := frmMailbox.Profile.Config.ReadInteger(
'frmCompose', 'fontSize', txtMessage.Font.Size);
txtMessage.Font.Color := frmMailbox.Profile.Config.ReadInteger(
'frmCompose', 'fontColor', txtMessage.Font.Color);
txtMessage.Font.Charset := frmMailbox.Profile.Config.ReadInteger(
'frmCompose', 'fontCharset', txtMessage.Font.Charset);
txtMessage.Font.Style := TFontStyles(
Byte(frmMailbox.Profile.Config.ReadInteger('frmCompose', 'fontStyle',
Byte(txtMessage.Font.Style))));
tb1.Visible := frmMailbox.Profile.Config.ReadBool(
Self.Name, 'viewToolbar', True);
sb.Visible := frmMailbox.Profile.Config.ReadBool(
Self.Name, 'viewStatusbar', True);
actViewToolbar.Checked := tb1.Visible;
actViewStatusbar.Checked := sb.Visible;
end;
procedure TfrmCompose.actFileCloseExecute(Sender: TObject);
begin
Self.Close;
end;
procedure TfrmCompose.lstAddressesClick(Sender: TObject);
var Node: PVirtualNode;
var p: TPoint;
begin
p := Mouse.CursorPos;
p := lstAddresses.ScreenToClient(p);
Node := lstAddresses.GetNodeAt(p.X, p.Y);
if Node <> nil then
lstAddresses.EditNode(Node, lstAddresses.FocusedColumn)
else begin
//if there is no node under mouse click then add new node
//but only if last one has some text
addNewNodeToAddresses;
end;
end;
procedure TfrmCompose.lstAddressesCreateEditor(Sender: TBaseVirtualTree;
Node: PVirtualNode; Column: TColumnIndex; out EditLink: IVTEditLink);
begin
case Column of
0:
begin
editor.LinkComboEditor(EditLink, '');
cmboxMailType.ItemIndex :=
Integer(PTreeAddresses((Sender as TVirtualStringTree).GetNodeData(Node))^.type_);
end;
1:
begin
editor.LinkACButtonEditor(EditLink, '');
txtMail.Text := PTreeAddresses(
(Sender as TVirtualStringTree).GetNodeData(Node))^.mail;
end
end;
end;
procedure TfrmCompose.lstAddressesEdited(Sender: TBaseVirtualTree;
Node: PVirtualNode; Column: TColumnIndex);
var tmpStr: String;
begin
case Column of
0:
begin
PTreeAddresses((Sender as TVirtualStringTree).GetNodeData(Node))^.type_ :=
TAddrType(cmboxMailType.ItemIndex);
askForSave := True;
end;
1:
begin
if (Pos('@', txtMail.Text) > 0) or (txtMail.Text = '') then
PTreeAddresses((Sender as TVirtualStringTree).GetNodeData(Node))^.mail :=
txtMail.Text
else begin
tmpStr := frmMailbox.Profile.Accounts[FAccount].EMail;
PTreeAddresses((Sender as TVirtualStringTree).GetNodeData(Node))^.mail :=
txtMail.Text + Copy(tmpStr, Pos('@', tmpStr), 1 +
Length(tmpStr) - Pos('@', tmpStr));
end;
addNewNodeToAddresses;
askForSave := True;
end
end;
end;
procedure TfrmCompose.lstAddressesGetNodeDataSize(Sender: TBaseVirtualTree;
var NodeDataSize: Integer);
begin
NodeDataSize := sizeOf(TTreeAddresses);
end;
procedure TfrmCompose.lstAddressesGetText(Sender: TBaseVirtualTree;
Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
var CellText: WideString);
begin
//return each column's text
with PTreeAddresses((Sender as TVirtualStringTree).GetNodeData(Node))^ do begin
case Column of
0:
CellText := cmboxMailType.Items.Strings[Integer(type_)];
1:
CellText := mail;
end;
end;
end;
procedure TfrmCompose.lstAddressesEditing(Sender: TBaseVirtualTree;
Node: PVirtualNode; Column: TColumnIndex; var Allowed: Boolean);
begin
Allowed := True;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -