OSDN Git Service

レスの書き込み時に tab や半角スペースを   に置換するようになった。
[gikonavigoeson/gikonavi.git] / Editor.pas
1 unit Editor;
2
3 interface
4
5 uses
6         Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
7         Dialogs, StdCtrls, ComCtrls, ExtCtrls, ToolWin, Menus, OleCtrls, Registry,
8 {$IF Defined(DELPRO) }
9         SHDocVw,
10 {$ELSE}
11         SHDocVw_TLB,
12 {$IFEND}
13         ActiveX, {HTTPApp,} YofUtils, Trip, IniFiles, StrUtils,
14         GikoSystem, GikoUtil, ImgList, Clipbrd, BoardGroup,
15         IdAntiFreezeBase,       IdAntiFreeze, IdBaseComponent, IdComponent,
16         IdTCPConnection, IdTCPClient, IdHTTP, ActnList, StdActns, IdIntercept,
17         IdLogBase, IdLogDebug, IdException, DateUtils, MojuUtils, bmRegExp;
18
19 type
20 //      TSetLayeredWindowAttributes = function(wnd: HWND; crKey: DWORD; bAlpha: BYTE; dwFlag: DWORD): Boolean; stdcall;
21         //\8f\91\82«\8d\9e\82Ý\96ß\82è\92l\83^\83C\83v
22         TGikoResultType = (grtOK, grtCookie, grtCheck, grtError);
23
24         TEditorForm = class(TForm)
25                 MainMenu: TMainMenu;
26                 FileMenu: TMenuItem;
27                 PostMessage: TMenuItem;
28                 SaveMessage: TMenuItem;
29                 CloseMenu: TMenuItem;
30                 N01: TMenuItem;
31                 StatusBar: TStatusBar;
32                 EditorPage: TPageControl;
33                 EditorTab: TTabSheet;
34                 PreviewTab: TTabSheet;
35                 Browser: TWebBrowser;
36                 EditMenu: TMenuItem;
37                 UndoMenu: TMenuItem;
38                 CutMenu: TMenuItem;
39                 CopyMenu: TMenuItem;
40                 PasteMenu: TMenuItem;
41                 N02: TMenuItem;
42                 ToolBarImageList: TImageList;
43                 HotToobarImageList: TImageList;
44                 BodyEdit: TMemo;
45                 NameBasePanel: TPanel;
46                 NameLabel: TLabel;
47                 MailLabel: TLabel;
48                 NameComboBox: TComboBox;
49                 MailComboBox: TComboBox;
50                 ToolBar: TToolBar;
51                 SendToolButton: TToolButton;
52                 OutBoxToolButton: TToolButton;
53                 ToolButton5: TToolButton;
54                 UndoToolButton: TToolButton;
55                 CutToolButton: TToolButton;
56                 CopyToolButton: TToolButton;
57                 PasteToolButton: TToolButton;
58                 ToolButton3: TToolButton;
59                 TransToolButton: TToolButton;
60                 TopToolButton: TToolButton;
61                 Indy: TIdHTTP;
62                 IdAntiFreeze: TIdAntiFreeze;
63                 ToolButton1: TToolButton;
64                 ToolButton2: TToolButton;
65                 ActionList: TActionList;
66                 SendAction: TAction;
67                 SaveAction: TAction;
68                 CloseAction: TAction;
69                 UndoAction: TAction;
70                 CutAction: TAction;
71                 CopyAction: TAction;
72                 PasteAction: TAction;
73                 AbortAction: TAction;
74                 TopAction: TAction;
75                 Show1: TMenuItem;
76                 T1: TMenuItem;
77                 N1: TMenuItem;
78                 S1: TMenuItem;
79                 SageCheckBox: TCheckBox;
80                 IdLogDebug: TIdLogDebug;
81                 TransAction: TAction;
82                 A1: TMenuItem;
83                 KotehanCheckBox: TCheckBox;
84                 TitlePanel: TPanel;
85                 Label1: TLabel;
86                 TitleEdit: TEdit;
87                 SelectAllAction: TAction;
88                 N2: TMenuItem;
89                 SelectAll1: TMenuItem;
90     Timer1: TTimer;
91     QuotePasteAction: TAction;
92     QuotePasteMenuItem: TMenuItem;
93                 procedure EditorPageChange(Sender: TObject);
94                 procedure FormCreate(Sender: TObject);
95                 procedure BrowserStatusTextChange(Sender: TObject;
96                         const Text: WideString);
97                 procedure FormClose(Sender: TObject; var Action: TCloseAction);
98                 procedure FormDestroy(Sender: TObject);
99                 procedure SendActionExecute(Sender: TObject);
100                 procedure SaveActionExecute(Sender: TObject);
101                 procedure AbortActionExecute(Sender: TObject);
102                 procedure CloseActionExecute(Sender: TObject);
103                 procedure UndoActionExecute(Sender: TObject);
104                 procedure CutActionExecute(Sender: TObject);
105                 procedure CopyActionExecute(Sender: TObject);
106                 procedure PasteActionExecute(Sender: TObject);
107                 procedure SendActionUpdate(Sender: TObject);
108                 procedure SaveActionUpdate(Sender: TObject);
109                 procedure CloseActionUpdate(Sender: TObject);
110                 procedure UndoActionUpdate(Sender: TObject);
111                 procedure CutActionUpdate(Sender: TObject);
112                 procedure CopyActionUpdate(Sender: TObject);
113                 procedure PasteActionUpdate(Sender: TObject);
114                 procedure TopActionExecute(Sender: TObject);
115                 procedure TopActionUpdate(Sender: TObject);
116                 procedure SageCheckBoxClick(Sender: TObject);
117                 procedure MailComboBoxChange(Sender: TObject);
118                 procedure TransActionExecute(Sender: TObject);
119                 procedure TransActionUpdate(Sender: TObject);
120                 procedure IdLogDebugReceive(ASender: TIdConnectionIntercept;
121                         AStream: TStream);
122                 procedure IdLogDebugSend(ASender: TIdConnectionIntercept;
123                         AStream: TStream);
124                 procedure SelectAllActionExecute(Sender: TObject);
125     procedure StatusBarResize(Sender: TObject);
126     procedure Timer1Timer(Sender: TObject);
127     procedure FormActivate(Sender: TObject);
128     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
129                 procedure QuotePasteActionExecute(Sender: TObject);
130         private
131                 FThreadItem: TThreadItem;
132                 FBoard: TBoard;
133                 FNameComboEdit: THandle;
134                 FMailComboEdit: THandle;
135                 FAbort: Boolean;
136                 FWork: Boolean;
137                 FStatusCode: Integer;
138                 FDebugStrReceive: string;
139                 FDebugStrSend: string;
140         FSambaTime: TDateTime;
141         FHost: string;
142                 FNow: TDateTime;
143                 procedure Preview;
144                 function RepHtml(s: string): string;
145                 function Check: Boolean;
146                 procedure SetNameList(sName, sMail: string);
147 //              procedure Send(SendType: TGikoSendType; SPID: string; PON: string; FirstWriting: Boolean);
148                 procedure Send(SPID: string; PON: string; FirstWriting: Boolean);
149
150                 function GetActiveControlHandle: THandle;
151 //              function GetSendData: string;
152 //              procedure GetSendData(Source: TStringStream);
153                 procedure GetSendData(Source: TStringStream);
154                 procedure SaveSendFile;
155                 procedure SetContent(Content: string);
156                 function GetSPID(CookieLine: string): string;
157                 function GetPON(CookieLine: string): string;
158                 function GetResultType(ResponseText: string): TGikoResultType;
159         procedure ReadSambaTime(const AHost: string);
160         procedure WriteSambaTime(const AHost: string; ATime: TDateTime);
161         function ReadSettingTime(const AHost: string): Integer;
162         function CheckSambaTime(const AHost: string; ATime: TDateTime): Boolean;
163                                 procedure SetSamba24(AURL: string);
164                 // \88ø\97p\95\84\82Ì\8eæ\93¾
165                 function GetOEIndentChar : string;
166         protected
167                 procedure CreateParams(var Params: TCreateParams); override;
168         public
169                 procedure SetFont;
170                 procedure SetThreadItem(Item: TThreadItem);
171                 procedure SetBoard(Item: TBoard);
172         end;
173
174 implementation
175
176 uses
177         Giko, ItemDownload;
178 const
179         CAPTION_NAME_NEW: string = '\83M\83R\83i\83\83X\83\8c\97§\82Ä\83G\83f\83B\83^';
180         CAPTION_NAME_RES: string = '\83M\83R\83i\83\83\8c\83X\83G\83f\83B\83^';
181
182     // \83G\83f\83B\83b\83g\83E\83B\83\93\83h\83E\82ð\89E\89º\82É\82¸\82ç\82µ\82Ä\8aJ\82­\88Ú\93®\97Ê
183     WINDOWMOVE_H = 30;
184     WINDOWMOVE_V = 30;
185
186         //DAX\82³\82ñ±Ø¶ÞÄ!(\81L\81¤\81M)
187         READCGI_ERR                     = '-ERR';
188         READCGI_INCR            = '-INCR';
189         READCGI_OK                      = '+OK';
190         READCGI_PARTIAL = '+PARTIAL';
191         READCGI_ERR_FOUND_KAKO  = '-ERR \89ß\8b\8e\83\8d\83O\91q\8cÉ\82Å\94­\8c©';
192         READCGI_ERR_NOT_HTML            = '-ERR html\89»\91Ò\82¿';
193         READCGI_ERR_NOT_FOUND           = '-ERR \82»\82ñ\82È\94Âor\83X\83\8c\83b\83h\82È\82¢\82Å\82·\81B';
194         READCGI_ERR_ABONE                               = '-ERR \82Ç\82±\82©\82Å\82 \82Ú\81[\82ñ\82ª\82 \82Á\82½\82Ý\82½\82¢\82Å\82·\81B';
195         READCGI_ERR_TIMEOUT                     = '-ERR \8ew\92è\8e\9e\8aÔ\82ª\89ß\82¬\82Ü\82µ\82½\81B';
196         READCGI_ERR_CANTUSE                     = '-ERR \82à\82¤\81@\82Â\82©\82¦\82Ü\82¹\82ñ';
197         RES2CH_TRUE                             = '<!-- 2ch_X:true -->';
198         RES2CH_FALSE                    = '<!-- 2ch_X:false -->';
199         RES2CH_ERROR                    = '<!-- 2ch_X:error -->';
200         RES2CH_CHECK                    = '<!-- 2ch_X:check -->';
201         RES2CH_COOKIE                   = '<!-- 2ch_X:cookie -->';
202
203
204 type
205         TSelection = record
206                 StartPos, EndPos: Integer;
207         end;
208
209 {$R *.DFM}
210
211 {constructor TEditorForm.Create(AOwner: TComponent; Item: TBoard);
212 begin
213         inherited Create(AOwner);
214 end;}
215
216 procedure TEditorForm.CreateParams(var Params: TCreateParams);
217 begin
218         inherited;
219         if FormStyle in [fsNormal, fsStayOnTop] then
220                 if BorderStyle in [bsSingle, bsSizeable] then begin
221                         Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
222                         Params.WndParent := 0;
223                 end;
224 end;
225
226 {procedure TEditorForm.CreateParams(var Params: TCreateParams);
227 begin
228         inherited CreateParams(Params);
229         Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
230 end;}
231
232 procedure TEditorForm.FormCreate(Sender: TObject);
233 var
234         wp: TWindowPlacement;
235                 hUser32 : HINST;
236 begin
237         FWork := False;
238         Browser.Navigate('about:blank');
239
240         FBoard := nil;
241         FThreadItem := nil;
242
243         //\83E\83B\83\93\83h\83E\82Ì\88Ê\92u\90Ý\92è
244 {       i := GikoSys.Setting.EditWindowLeft +
245                          GikoSys.Setting.EditWindowTop +
246                          GikoSys.Setting.EditWindowWidth +
247                          GikoSys.Setting.EditWindowHeight;
248         if i > 0 then begin
249                 SetBounds(GikoSys.Setting.EditWindowLeft, GikoSys.Setting.EditWindowTop,
250                                                         GikoSys.Setting.EditWindowWidth, GikoSys.Setting.EditWindowHeight);
251                 if GikoSys.Setting.EditWindowMax then
252                         WindowState := wsMaximized;
253         end;}
254
255         //\83E\83B\83\93\83h\83E\82Ì\88Ê\92u\90Ý\92è
256         wp.length := sizeof(wp);
257         wp.rcNormalPosition.Top := GikoSys.Setting.EditWindowTop;
258         wp.rcNormalPosition.Left := GikoSys.Setting.EditWindowLeft;
259
260         wp.rcNormalPosition.Bottom := GikoSys.Setting.EditWindowTop + GikoSys.Setting.EditWindowHeight;
261         wp.rcNormalPosition.Right := GikoSys.Setting.EditWindowLeft + GikoSys.Setting.EditWindowWidth;
262         wp.showCmd := SW_HIDE;
263         SetWindowPlacement(Handle, @wp);
264
265         if GikoSys.Setting.EditWindowMax then
266                 WindowState := wsMaximized;
267
268         //\83E\83B\83\93\83h\83E\82ª\89æ\96Ê\8aO\82È\82ç\89æ\96Ê\93à\82É\88Ú\93®\82·\82é
269         if (Left + Width) > Screen.Width then
270 //              Left := Screen.Width - Width;
271                 Left := 0;
272         if (Top + Height) > Screen.Height then
273 //              Top := Screen.Height - Height;
274                 Top := 0;
275         if Left < 0 then
276                 Left := 0;
277         if Top < 0 then
278                 Top := 0;
279
280     //\8c»\8dÝ\82Ì\83E\83B\83\93\83h\83E\82Ì\88Ê\92u\82ð\95Û\91
281     GikoSys.Setting.EditWindowTop := Top  + WINDOWMOVE_V;   // \8e\9f\82É\8aJ\82­\83E\83B\83\93\83h\83E\82Í
282     GikoSys.Setting.EditWindowLeft := Left + WINDOWMOVE_H;  // \81@\81@\81@\89E\8eÎ\82ß\89º\82É\82¸\82ç\82·
283     //\83E\83B\83\93\83h\83E\82Ì\95\9d\82Æ\8d\82\82³\82ª\8f¬\82³\82·\82¬\82¢\82ê\82Î\8c³\82É\96ß\82·
284         if GikoSys.Setting.EditWindowHeight < 144 then
285                 Height := 400;
286         if GikoSys.Setting.EditWindowWidth < 144 then
287                 Width := 640;
288
289         EditorPage.ActivePage := EditorTab;
290         FNameComboEdit := GetWindow(NameComboBox.Handle, GW_CHILD);
291         FMailComboEdit := GetWindow(MailComboBox.Handle, GW_CHILD);
292         NameComboBox.Items.Assign(GikoSys.Setting.NameList);
293         MailComboBox.Items.Assign(GikoSys.Setting.MailList);
294         SetFont;
295         hUser32 := LoadLibrary('User32.dll');
296         try
297                 if hUser32 <> 0 then
298                         TransAction.Enabled := true
299                 else
300                         TransAction.Enabled := false;
301         finally
302                 FreeLibrary(hUser32);
303         end;
304
305     // \83E\83B\83\93\83h\83E\82Ì\83X\83e\83C\8fó\91Ô
306         if GikoSys.Setting.EditWindowStay then begin    // \83X\83e\83C\8fó\91Ô
307         FormStyle := fsStayOnTop;
308         TopAction.Checked := true;
309         TopToolButton.Down := true;
310     end else begin                                  // \83X\83e\83C\82µ\82È\82¢
311         FormStyle := fsNormal;
312         TopAction.Checked := false;
313         TopToolButton.Down := false;
314     end;
315         // \83X\83e\83C\8fó\91Ô\82Ì\95Û\91
316         GikoSys.Setting.EditWindowStay := FormStyle = fsStayOnTop;
317
318     // \83E\83B\83\93\83h\83E\82Ì\94¼\93§\96¾\8fó\91Ô
319         if(GikoSys.Setting.EditWindowTranslucent) and (TransAction.Enabled) then begin // \94¼\93§\96¾\81i\83g\83\89\83\93\83X\83\8b\81[\83Z\83\93\83g\81j\8fó\91Ô
320         AlphaBlend := true;
321         TransAction.Checked := true;
322         TransToolButton.Down := true;
323     end else begin                                      // \95s\93§\96¾
324         AlphaBlend := false;
325         TransAction.Checked := false;
326         TransToolButton.Down := false;
327     end;
328         // \94¼\93§\96¾\8fó\91Ô\82Ì\95Û\91
329         GikoSys.Setting.EditWindowTranslucent := TransAction.Checked;
330 end;
331
332 procedure TEditorForm.SetBoard(Item: TBoard);
333 begin
334         FBoard := Item;
335         Caption := CAPTION_NAME_NEW + ' - [' + Item.Title + ']';
336         NameComboBox.Text := FBoard.KotehanName;
337         MailComboBox.Text := FBoard.KotehanMail;
338         SageCheckBox.Checked := AnsiPos('sage', MailComboBox.Text) <> 0;
339         TitlePanel.Visible := True;
340     SetSamba24('');
341 end;
342
343 procedure TEditorForm.SetThreadItem(Item: TThreadItem);
344 begin
345         FThreadItem := Item;
346         Caption := CAPTION_NAME_RES + ' - [' + FThreadItem.Title + ']';
347         NameComboBox.Text := FThreadItem.ParentBoard.KotehanName;
348         MailComboBox.Text := FThreadItem.ParentBoard.KotehanMail;
349         SageCheckBox.Checked := AnsiPos('sage', MailComboBox.Text) <> 0;
350         TitlePanel.Visible := False;
351     SetSamba24(FThreadItem.ParentBoard.URL);
352 end;
353
354 procedure TEditorForm.SetFont;
355 begin
356         BodyEdit.Font.Name := GikoSys.Setting.EditorFontName;
357         BodyEdit.Font.Size := GikoSys.Setting.EditorFontSize;
358         BodyEdit.Font.Color := GikoSys.Setting.EditorFontColor;
359         BodyEdit.Color := GikoSys.Setting.EditorBackColor;
360 end;
361
362 procedure TEditorForm.Preview;
363 var
364         Title: string;
365         No: string;
366         Mail: string;
367         Namae: string;
368         DateTime: string;
369         Body: string;
370         s: string;
371
372                                 posTrip : Integer;
373                                 tripOrigin : string;
374         regexp  : TAWKStr;
375 begin
376         if FThreadItem = nil then begin
377                 No := '1';
378                 Title := RepHtml(TitleEdit.Text);
379         end else begin
380                 No := IntToStr(FThreadItem.Count + 1);
381                 Title := RepHtml(FThreadItem.Title);
382         end;
383
384         body := BodyEdit.Text;
385         if GikoSys.Setting.SpaceToNBSP then begin
386                 body := CustomStringReplace( body, #09, '&nbsp;&nbsp;&nbsp;&nbsp;' );
387                 body := CustomStringReplace( body, '  ', '&nbsp;&nbsp;' );
388                 body := CustomStringReplace( body, '&nbsp; ', '&nbsp;&nbsp;' );
389                 regexp := TAWKStr.Create( nil );
390                 try
391                         regexp.RegExp := '^ ';
392                         regexp.GSub( '\&nbsp;', body );
393                 finally
394                         regexp.Free;
395                 end;
396         end;
397
398         Namae := RepHtml(NameComboBox.Text);
399         Mail := RepHtml(MailComboBox.Text);
400         Body := RepHtml(body);
401         Body := StringReplace(Body, #13#10, '<br>', [rfReplaceAll]);
402         DateTime := FormatDateTime('yyyy/mm/dd(aaa) hh:nn', now);
403
404         if Trim(Namae) = '' then
405                 Namae := '\96¼\96³\82µ\82³\82ñ';
406
407         s := '<HTML><HEAD>' + #13#10
408                         + '<META http-equiv="Content-Type" content="text/html; charset=Shift_JIS">' + #13#10
409                         + '<TITLE>' + title + '</TITLE>' + #13#10
410 //                      + '<STYLE><!--BODY{font-size : 9pt;font-family : "\82l\82\82o\83S\83V\83b\83N";}--></STYLE>' + #13#10
411                         + '</HEAD>' + #13#10
412                         + '<BODY text="#000000" bgcolor="#EFEFEF" link="#0000FF" alink="#FF0000" vlink="#660099">' + #13#10
413                         + '<FONT COLOR="#FF0000">' + title + '</FONT>' + #13#10
414                         + '<DL>' + #13#10;
415                                 posTrip := AnsiPos( '#', Namae );
416                                 if posTrip > 0 then
417                                 begin
418                                                                 tripOrigin := Copy( Namae, posTrip + 1, Length( Namae ) );
419                                                                 Namae :=
420                                                                                                 Copy( Namae, 1, posTrip - 1 ) + '</B> \81\9f' +
421                                                                                                 get_2ch_trip( PChar( tripOrigin ) ) + '<B>';
422                                 end;
423         if Mail = '' then
424                 s := s + '<DT>' + No + ' \81F <FONT color="forestgreen"><B>' + Namae + '</B></FONT> \81F ' + DateTime+ '<BR><DD>' + Body + '<BR><BR><BR>' + #13#10
425         else
426                 s := s + '<DT>' + No + ' \81F <A href="mailto:' + Mail + '"><B>' + Namae + '</B></A> [' + Mail + ']\81F ' + DateTime+ '<BR><DD>' + Body + '<BR><BR><BR>' + #13#10;
427         s := s + '</BODY></HTML>';
428         SetContent(s);
429 end;
430
431 function TEditorForm.RepHtml(s: string): string;
432 begin
433 //      s := StringReplace(s, '&', '&amp;', [rfReplaceAll]);
434         s := StringReplace(s, '<', '&lt;', [rfReplaceAll]);
435         s := StringReplace(s, '>', '&gt;', [rfReplaceAll]);
436 //      s := StringReplace(s, ' ', '&nbsp;', [rfReplaceAll]);   //\8ed\97l\95Ï\8dX\82É\82æ\82è&nbsp;\8eg\97p\95s\89Â
437         s := StringReplace(s, '"', '&quot;', [rfReplaceAll]);
438         Result := s;
439 end;
440
441 procedure TEditorForm.EditorPageChange(Sender: TObject);
442 begin
443         if EditorPage.ActivePage = PreviewTab then begin
444                 Preview;
445         end else begin
446                 Browser.Navigate('about:blank');
447         end;
448 end;
449
450 procedure TEditorForm.BrowserStatusTextChange(Sender: TObject;
451         const Text: WideString);
452 begin
453         if EditorPage.ActivePage = PreviewTab then begin
454                 StatusBar.Panels[0].Text := Text;
455         end else begin
456                 StatusBar.Panels[0].Text := '';
457         end;
458 end;
459
460 function TEditorForm.Check: Boolean;
461 var
462         Msg: string;
463         rc: Integer;
464         Board: TBoard;
465 begin
466         Result := True;
467         if FThreadItem = nil then
468                 Board := FBoard
469         else
470                 Board := FThreadItem.ParentBoard;
471
472         if (not GikoSys.Setting.UseMachineTime) and
473                  ((Board.LastGetTime = 0) or
474                         (Board.LastGetTime = ZERO_DATE)) then begin
475                 Msg := '\83T\81[\83o\82Ì\8e\9e\8d\8f\82ª\95ª\82©\82ç\82È\82¢\82½\82ß\81A\91\97\90M\8fo\97\88\82Ü\82¹\82ñ'#13#10
476                                  + '\83X\83\8c\83b\83h\82ð\8dX\90V\81i\8eæ\93¾\81j\8cã\81A15\95b\91Ò\82Á\82Ä\82©\82ç\91\97\90M\82µ\82Ä\82­\82¾\82³\82¢';
477                 MsgBox(Handle, Msg, '\83G\83\89\81[', MB_OK or MB_ICONSTOP);
478                 Result := False;
479         end else if BodyEdit.Text = '' then begin
480                 Msg := '\96{\95\82ª\93ü\97Í\82³\82ê\82Ä\82¢\82Ü\82¹\82ñ\81B';
481                 MsgBox(Handle, Msg, '\83G\83\89\81[', MB_OK or MB_ICONSTOP);
482                 Result := False;
483         end else if (FBoard <> nil) and (Trim(TitleEdit.Text) = '') then begin
484                 Msg := '\83^\83C\83g\83\8b\82ª\93ü\97Í\82³\82ê\82Ä\82¢\82Ü\82¹\82ñ\81B';
485                 MsgBox(Handle, Msg, '\83G\83\89\81[', MB_OK or MB_ICONSTOP);
486                 Result := False;
487         end else begin
488                 if (not GikoSys.Dolib.Connected) and (AnsiPos('\81\9c', NameComboBox.Text) <> 0) then begin
489                         Msg := '\83\8d\83O\83C\83\93\82µ\82Ä\82¢\82È\82¢\82Ì\82Å\81\9c\82Ì\8b@\94\\82Í\97\98\97p\8fo\97\88\82Ü\82¹\82ñ\81B'#13#10
490                                          + '\82±\82Ì\82Ü\82Ü\91\97\90M\82µ\82Ä\82à\82æ\82ë\82µ\82¢\82Å\82·\82©\81H';
491                         rc := MsgBox(Handle, Msg, '\8am\94F', MB_YESNO or MB_ICONQUESTION);
492                         Result := (rc = IDYES);
493                 end;
494         end;
495 end;
496
497 procedure TEditorForm.FormClose(Sender: TObject; var Action: TCloseAction);
498 begin
499         Action := caFree;
500 end;
501
502 procedure TEditorForm.FormDestroy(Sender: TObject);
503 var
504         wp: TWindowPlacement;
505 begin
506         //\8dÅ\91å\89»\81E\83E\83B\83\93\83h\83E\88Ê\92u\95Û\91
507         wp.length := sizeof(wp);
508         GetWindowPlacement(Handle, @wp);
509
510         GikoSys.Setting.EditWindowTop := wp.rcNormalPosition.Top;
511         GikoSys.Setting.EditWindowLeft := wp.rcNormalPosition.Left;
512         GikoSys.Setting.EditWindowHeight := wp.rcNormalPosition.Bottom - wp.rcNormalPosition.Top;
513         GikoSys.Setting.EditWindowWidth := wp.rcNormalPosition.Right - wp.rcNormalPosition.Left;
514         GikoSys.Setting.EditWindowMax := WindowState = wsMaximized;
515         GikoSys.Setting.EditWindowStay := FormStyle = fsStayOnTop;      // \83X\83e\83C\8fó\91Ô\82Ì\95Û\91
516         GikoSys.Setting.EditWindowTranslucent := TransAction.Checked;   // \94¼\93§\96¾\8fó\91Ô\82Ì\95Û\91
517
518 end;
519
520 procedure TEditorForm.SetNameList(sName, sMail: string);
521 begin
522         if Trim(sName) <> '' then begin
523                 if GikoSys.Setting.NameList.IndexOf(sName) = -1 then
524                         GikoSys.Setting.NameList.Insert(0, sName);
525         end;
526         if Trim(sMail) <> '' then begin
527                 if GikoSys.Setting.MailList.IndexOf(sMail) = -1 then
528                         GikoSys.Setting.MailList.Insert(0, sMail);
529         end;
530 end;
531
532 function TEditorForm.GetActiveControlHandle: THandle;
533 begin
534         if EditorPage.ActivePage = EditorTab then begin
535                 if ActiveControl = NameComboBox then
536                         Result := FNameComboEdit
537                 else if ActiveControl = MailComboBox then
538                         Result := FMailComboEdit
539                 else if ActiveControl = BodyEdit then
540                         Result := BodyEdit.Handle
541                 else if ActiveControl = TitleEdit then
542                         Result := TitleEdit.Handle
543                 else
544                         Result := 0;
545         end else
546                 Result := 0;
547 end;
548
549 procedure TEditorForm.SetContent(Content: string);
550 var
551         doc : Variant;
552 begin
553         if Browser.Document <> nil then begin
554                 doc := Browser.Document;
555                 doc.Clear;
556                 doc.open;
557                 doc.charset := 'Shift_JIS';
558                 doc.Write(Content);
559                 doc.Close;
560         end;
561 end;
562
563 procedure TEditorForm.Send(SPID: string; PON: string; FirstWriting: Boolean);
564 var
565         TextStream: TStringStream;
566         Source: TStringStream;
567         ResponseText: string;
568         URL: string;
569         RefURL: string;
570         State: TGikoDownloadState;
571         ResultType: TGikoResultType;
572         MsgResult: Integer;
573         Cookie: string;
574         Board: TBoard;
575         sysMenu : HMENU;
576 begin
577         FAbort := False;
578         State := gdsError;
579         if FThreadItem = nil then
580                 Board := FBoard
581         else
582                 Board := FThreadItem.ParentBoard;
583
584         Indy.Request.Clear;
585         Indy.ProxyParams.BasicAuthentication := False;
586         if GikoSys.Setting.WriteProxy then begin
587                 Indy.ProxyParams.ProxyServer := GikoSys.Setting.WriteProxyAddress;
588                 Indy.ProxyParams.ProxyPort := GikoSys.Setting.WriteProxyPort;
589                 Indy.ProxyParams.ProxyUsername := GikoSys.Setting.WriteProxyUserID;
590                 Indy.ProxyParams.ProxyPassword := GikoSys.Setting.WriteProxyPassword;
591                 if GikoSys.Setting.ReadProxyUserID <> '' then
592                         Indy.ProxyParams.BasicAuthentication := True;
593         end else begin
594                 Indy.ProxyParams.ProxyServer := '';
595                 Indy.ProxyParams.ProxyPort := 80;
596                 Indy.ProxyParams.ProxyUsername := '';
597                 Indy.ProxyParams.ProxyPassword := '';
598         end;
599         if FThreadItem = nil then begin
600                 URL := FBoard.GetSendURL;
601                 RefURL := GikoSys.UrlToServer(FBoard.URL) + 'test/bbs.cgi';
602         end else begin
603                 URL := FThreadItem.GetSendURL;
604                 RefURL := FThreadItem.URL;
605         end;
606         Indy.Request.UserAgent := GikoSys.GetUserAgent;
607         Indy.Request.Referer := RefURL;
608         Indy.Request.AcceptEncoding := '';
609
610         Cookie := '';
611         if SPID <> '' then
612                 Cookie := Cookie + 'SPID=' + SPID + '; ';
613         if PON <> '' then
614                 Cookie := Cookie + 'PON=' + PON + '; ';
615         Cookie := 'Cookie: ' + Cookie + 'NAME=' + NameComboBox.Text + '; MAIL=' + MailComboBox.Text;
616
617         sysMenu := GetSystemMenu( Handle, false );
618         EnableMenuItem( sysMenu, SC_CLOSE, MF_GRAYED );
619 {
620   EnableMenuItem(SysMenu, SC_CLOSE, MF_BYCOMMAND or MF_ENABLED);
621   DrawMenuBar(Handle);
622 }
623         Indy.Request.CustomHeaders.Clear;
624 //      Indy.Request.CacheControl := 'no-cache';
625         Indy.Request.CustomHeaders.Add('Pragma: no-cache');
626         Indy.Request.AcceptLanguage := 'ja';
627         Indy.Request.Accept := 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*';
628         Indy.Request.ContentType := 'application/x-www-form-urlencoded';
629         Indy.Request.CustomHeaders.Add(Cookie);
630         TextStream := TStringStream.Create('');
631         Source := TStringStream.Create('');
632         try
633                 try
634                         FDebugStrReceive := '';
635                         FDebugStrSend := '';
636                         GetSendData(Source);
637                         Indy.Post(URL, Source, TextStream);
638                         ResponseText := TextStream.DataString;
639
640                         ResultType := GetResultType(ResponseText);
641
642                         if ResultType = grtOK then begin
643                 WriteSambaTime(FHost, Now());
644                                 State := gdsComplete;
645                         end else if ResultType = grtCookie then begin
646                                 //\83\8b\81[\83v\96h\8e~
647                                 if not FirstWriting then
648                                         raise Exception.Create('');
649                                 MsgResult := MsgBox(
650                                         Handle,
651                                         '\81E\93\8a\8de\82³\82ê\82½\93à\97e\82Í\83R\83s\81[\81A\95Û\91\81A\88ø\97p\81A\93]\8dÚ\93\99\82³\82ê\82é\8fê\8d\87\82ª\82 \82è\82Ü\82·\81B' + #13#10 +
652                                         '\81E\93\8a\8de\82É\8aÖ\82µ\82Ä\94­\90\82·\82é\90Ó\94C\82Í\91S\82Ä\93\8a\8de\8eÒ\82É\8bA\82µ\82Ü\82·\81B' + #13#10#13#10 +
653                                         '\91S\90Ó\94C\82ð\95\89\82¤\82±\82Æ\82ð\8f³\91ø\82µ\82Ä\8f\91\82«\8d\9e\82Ý\82Ü\82·\82©\81H',
654                                         '\8fî\95ñ',
655                                         MB_YESNO or MB_ICONQUESTION);
656                                 if MsgResult = IDYES then begin
657                                         Board.SPID := GetSPID(Indy.Response.RawHeaders.Values['Set-Cookie']);
658                                         Board.PON := GetPON(Indy.Response.RawHeaders.Values['Set-Cookie']);
659                                         if (Board.SPID = '') and (Board.PON = '') then
660                                                 raise Exception.Create('');
661                                         //\82à\82¤\88ê\89ñ\82±\82Ì\83\81\83\\83b\83h
662                                         Send(Board.SPID, Board.PON, False);
663                                         Exit;
664                                 end else begin
665                                         Board.SPID := '';
666                                         Board.PON := '';
667                                         FWork := false;
668                                         EnableMenuItem(SysMenu, SC_CLOSE, MF_BYCOMMAND or MF_ENABLED);
669                                         DrawMenuBar(Handle);
670                                         Exit;
671                                 end;
672                         end else if ResultType = grtCheck then begin
673                                 //
674                                 //\83\8b\81[\83v\96h\8e~
675                                 if not FirstWriting then
676                                         raise Exception.Create('');
677
678                                 MsgResult := MsgBox(
679                                         Handle,
680                                         '\8f\91\82«\8d\9e\82Ý\82É\8aÖ\82µ\82Ä\82Í\97l\81X\82È\83\8d\83O\8fî\95ñ\82ª\8bL\98^\82³\82ê\82Ä\82¢\82Ü\82·\81B' + #13#10 +
681                                         '\93\8a\8de\82É\8aÖ\82µ\82Ä\94­\90\82·\82é\90Ó\94C\82Í\91S\82Ä\93\8a\8de\8eÒ\82É\8bA\82µ\82Ü\82·\81B' + #13#10 +
682                                         '\8cö\8f\98\97Ç\91­\82É\94½\82µ\82½\82è\81A\91¼\90l\82É\96À\98f\82ð\82©\82¯\82é\8f\91\82«\8d\9e\82Ý\82Í\8dT\82¦\82Ä\89º\82³\82¢\81B' + #13#10 +
683                                         '\93\8a\8de\82³\82ê\82½\93à\97e\82Í\83R\83s\81[\81E\95Û\91\81E\88ø\97p\81E\93]\8dÚ\93\99\82³\82ê\82é\8fê\8d\87\82ª\82 \82è\82Ü\82·\81B' + #13#10 +
684                                         #13#10 +
685                                         '\91S\90Ó\94C\82ð\95\89\82¤\82±\82Æ\82ð\8f³\91ø\82µ\82Ä\8f\91\82«\8d\9e\82Ý\82Ü\82·\82©\81H',
686                                         '\8am\94F',
687                                         MB_YESNO or MB_ICONQUESTION);
688
689                                 if MsgResult = IDYES then begin
690                                         Board.SPID := GetSPID(Indy.Response.RawHeaders.Values['Set-Cookie']);
691                                         Board.PON := GetPON(Indy.Response.RawHeaders.Values['Set-Cookie']);
692                                         if (Board.SPID = '') and (Board.PON = '') then
693                                                 raise Exception.Create('');
694                                         Send(Board.SPID, Board.PON, False);
695                                         Exit;
696                                 end else begin
697                                         EnableMenuItem(SysMenu, SC_CLOSE, MF_BYCOMMAND or MF_ENABLED);
698                                         DrawMenuBar(Handle);
699                                         Board.SPID := '';
700                                         Board.PON := '';
701                                         FWork := false;
702                                         Exit;
703                                 end;
704                         end else begin
705                 WriteSambaTime(FHost, Now());
706                                 State := gdsError;
707                                 raise Exception.Create('');
708                         end;
709                 except
710                         on E: EIdConnectException do begin
711                                 State := gdsError;
712                                 ResponseText := '<html><body>'
713                                                                                         + '<div>\90Ú\91±\82ª\8e¸\94s\82µ\82Ü\82µ\82½<br>'
714                                                                                         + '\89ñ\90ü\82â\83v\83\8d\83L\83V\82Ì\8fó\91Ô\82ð\92²\82×\82Ä\82­\82¾\82³\82¢<br></div>'
715                                                                                         + '<br><br><div>' + E.Message + '</div>'
716                                                                                         + '</body></html>';
717                         end;
718                         on E: Exception do begin
719                                 State := gdsError;
720
721                                 FDebugStrReceive := AnsiReplaceText(FDebugStrReceive, '<', '&lt;');
722                                 FDebugStrReceive := AnsiReplaceText(FDebugStrReceive, '>', '&gt;');
723                                 FDebugStrSend := AnsiReplaceText(FDebugStrSend, '<', '&lt;');
724                                 FDebugStrSend := AnsiReplaceText(FDebugStrSend, '>', '&gt;');
725
726                                 ResponseText := '<html><body>' + TextStream.DataString;
727                                 ResponseText := AnsiReplaceText(ResponseText, '</body>', '');
728                                 ResponseText := AnsiReplaceText(ResponseText, '</html>', '');
729                                 ResponseText := ResponseText + '<hr><div align="left"><pre>';
730                                 ResponseText := ResponseText + '<b>\82±\82±\82©\82ç\83M\83R\83i\83r\82Ì\8fî\95ñ</b>'#13#10;
731                                 ResponseText := ResponseText + #13#10'\81\9c\91\97\90M'#13#10;
732                                 ResponseText := ResponseText + FDebugStrSend;
733                                 ResponseText := ResponseText + #13#10'\81\9c\8eó\90M'#13#10;
734                                 ResponseText := ResponseText + FDebugStrReceive;
735                                 ResponseText := ResponseText + '</pre></div></body></html>';
736                         end;
737                 end;
738                 FStatusCode := Indy.ResponseCode;
739                 if FAbort then
740                         State := gdsAbort;
741         finally
742                 Source.Free;
743                 TextStream.Free;
744                 //sysMenu := GetSystemMenu( Handle, true );
745                 EnableMenuItem(SysMenu, SC_CLOSE, MF_BYCOMMAND or MF_ENABLED);
746                 DrawMenuBar(Handle);
747         end;
748         FWork := false;
749         if State = gdsComplete then begin
750                 GikoForm.PlaySound('ResEnd');
751                 SaveSendFile;
752                 if FThreadItem = nil then
753                         GikoForm.AddMessageList(FBoard.Title + ' [\90V\83X\83\8c\91\97\90M\8fI\97¹]', nil, gmiOK)
754                 else
755                         GikoForm.AddMessageList(FThreadItem.Title + ' [\83\8c\83X\91\97\90M\8fI\97¹]', nil, gmiOK);
756                 Close;
757         end else if State = gdsError then begin
758                 if FThreadItem = nil then
759                         GikoForm.AddMessageList(FBoard.Title + ' [\90V\83X\83\8c\91\97\90M\8e¸\94s]', nil, gmiNG)
760                 else
761                         GikoForm.AddMessageList(FThreadItem.Title + ' [\83\8c\83X\91\97\90M\8e¸\94s]', nil, gmiNG);
762                 EditorPage.ActivePage := PreviewTab;
763                 SetContent(ResponseText);
764         end else if State = gdsAbort then begin
765                 GikoForm.AddMessageList(FThreadItem.Title + ' [\92\86\92f]', nil, gmiSAD);
766         end;
767 end;
768
769 function TEditorForm.GetResultType(ResponseText: string): TGikoResultType;
770 begin
771         if AnsiPos('\8f\91\82«\82±\82Ý\82ª\8fI\82í\82è\82Ü\82µ\82½', ResponseText) <> 0 then
772                 Result := grtOK
773         else if (AnsiPos('\83N\83b\83L\81[\82ª\82È\82¢\82©\8aú\8cÀ\90Ø\82ê\82Å\82·', ResponseText) > 0) or
774                                         (AnsiPos('<title>\83N\83b\83L\81[\8am\94F\81I</title>', ResponseText) > 0)    or
775                                         (AnsiPos('<title>\81¡\83N\83b\83L\81[\8am\94F\81I\81¡</title>', ResponseText) > 0)        or
776                                         //(AnsiPos('\83N\83b\83L\81[\8am\94F', ResponseText) > 0) or
777                                         (AnsiPos(RES2CH_COOKIE, ResponseText) > 0)      then
778                 Result := grtCookie
779         else if (AnsiPos('<font size=+2 color=#FF0000>\8f\91\82«\8d\9e\82Ý\83`\83F\83b\83N\81I </font>', ResponseText) > 0)   or
780                                         (AnsiPos('<title>\81¡ \8f\91\82«\8d\9e\82Ý\8am\94F\82µ\82Ü\82· \81¡</title>', ResponseText) > 0)  or
781                                         (AnsiPos('<title>\93\8a\8de\8am\94F</title>', ResponseText) > 0)  or
782                                         (AnsiPos('<b>\8f\91\82«\82±\82Ý\8am\94F</b>', ResponseText) > 0)      or
783                                         (AnsiPos('="../test/subbbs.cgi">', ResponseText) > 0)   or
784                                         (AnsiPos(RES2CH_FALSE, ResponseText) > 0)       then
785                 Result := grtCheck
786         else
787                 Result := grtError;
788 end;
789
790
791 procedure TEditorForm.GetSendData(Source: TStringStream);
792 var
793         SessionID: string;
794         s: string;
795         SendTime: Integer;
796         Adjust: Integer;
797         Board: TBoard;
798         body            : string;
799         regexp  : TAWKStr;
800 begin
801         if FThreadItem = nil then
802                 Board := FBoard
803         else
804                 Board := FThreadItem.ParentBoard;
805
806         if GikoSys.Setting.UseMachineTime then begin
807                 if GikoSys.Setting.TimeAdjust then
808                         Adjust := Gikosys.Setting.TimeAdjustSec
809                 else
810                         Adjust := GikoSys.Setting.TimeAdjustSec * -1;
811                 SendTime := GikoSys.DateTimeToInt(Now) - (9 * 60 * 60) + Adjust
812         end else begin
813                 if (Board.LastGetTime = 0) or (Board.LastGetTime = ZERO_DATE) then
814                         SendTime := GikoSys.DateTimeToInt(Now)
815                 else
816                         SendTime := GikoSys.DateTimeToInt(Board.LastGetTime);
817         end;
818
819         body := BodyEdit.Text;
820         if GikoSys.Setting.SpaceToNBSP then begin
821                 body := CustomStringReplace( body, #09, '&nbsp;&nbsp;&nbsp;&nbsp;' );
822                 body := CustomStringReplace( body, '  ', '&nbsp;&nbsp;' );
823                 body := CustomStringReplace( body, '&nbsp; ', '&nbsp;&nbsp;' );
824                 regexp := TAWKStr.Create( nil );
825                 try
826                         regexp.RegExp := '^ ';
827                         regexp.GSub( '\&nbsp;', body );
828                 finally
829                         regexp.Free;
830                 end;
831         end;
832
833         SessionID := GikoSys.Dolib.SessionID;
834         if SessionID <> '' then
835                 s := 'sid=' + HttpEncode(SessionID) + '&'
836         else
837                 s := '';
838         s := s + 'subject=&'
839                                  + 'FROM=' + HttpEncode(NameComboBox.Text) + '&'
840                                  + 'mail=' + HttpEncode(MailComboBox.Text) + '&'
841                                  + 'MESSAGE=' + HttpEncode(body) + '&'
842                                  + 'bbs=' + Board.BBSID + '&'
843                                  + 'time=' + IntToStr(SendTime) + '&';
844         if FThreadItem = nil then begin
845                 s := s + 'subject=' + HttpEncode(TitleEdit.Text) + '&';
846                 s := s + 'submit=' + HttpEncode('\91S\90Ó\94C\82ð\95\89\82¤\82±\82Æ\82ð\8f³\91ø\82µ\82Ä\8f\91\82«\8d\9e\82Þ') + #13#10;
847         end else begin
848                 s := s + 'key=' + ChangeFileExt(FThreadItem.FileName, '') + '&';
849                 s := s + 'submit=' + HttpEncode('\8f\91\82«\8d\9e\82Þ') + #13#10;
850         end;
851         Source.WriteString(s);
852 end;
853
854 procedure TEditorForm.SaveSendFile;
855 var
856         sDate: string;
857         ini: TMemIniFile;
858 begin
859         ini := TMemIniFile.Create(GikoSys.GetSentFileName);
860         try
861                 sDate := IntToStr(GikoSys.DateTimeToInt(Now));
862
863                 ini.WriteString(sDate, 'Name', NameComboBox.Text);
864                 ini.WriteString(sDate, 'EMail', MailComboBox.Text);
865                 ini.WriteString(sDate, 'Body', HttpEncode(BodyEdit.Text));
866                 ini.WriteInteger(sDate, 'Status', FStatusCode);
867                 ini.WriteDateTime(sDate, 'Date', Now);
868                 if FThreadItem = nil then begin
869                         ini.WriteString(sDate, 'Title', TitleEdit.Text);
870                         ini.WriteString(sDate, 'BBS', FBoard.BBSID);
871                         ini.WriteInteger(sDate, 'NewThread', 1);
872                 end else begin
873                         ini.WriteString(sDate, 'Title', FThreadItem.Title);
874                         ini.WriteString(sDate, 'BBS', FThreadItem.ParentBoard.BBSID);
875                         ini.WriteString(sDate, 'Key', ChangeFileExt(FThreadItem.FileName, ''));
876                 end;
877
878                 ini.UpdateFile;
879         finally
880                 ini.Free;
881         end;
882 end;
883
884 procedure TEditorForm.SendActionExecute(Sender: TObject);
885 var
886         Board: TBoard;
887         rc: Integer;
888         state : TGikoDownloadState;
889         body            : string;
890         regexp  : TAWKStr;
891 begin
892         if FWork then
893                 Exit;
894         try
895                 FWork := True;
896                 SendAction.Enabled := False;
897                 Application.ProcessMessages;
898                 if not Check then Exit;
899
900                 if FThreadItem = nil then
901                         Board := FBoard
902                 else
903                         Board := FThreadItem.ParentBoard;
904
905                 if FThreadItem = nil then begin
906                         rc := GikoUtil.MsgBox(Handle,
907                                                                                                         '\81u' + Board.Title + '\81v\94Â\82É\90V\82µ\82¢\83X\83\8c\83b\83h\97§\82Ä\82Ü\82·'#13#10#13#10
908                                                                                                         + '\81E\94Â\82Ì\83\8b\81[\83\8b\82ð\8eç\82Á\82½\8f\91\82«\8d\9e\82Ý\82Å\82 \82é\82±\82Æ\82ð\8am\94F\82µ\82Ü\82µ\82½\82©\81H'#13#10
909                                                                                                         + '\81E\91¼\82É\93¯\82\82æ\82¤\82È\83X\83\8c\83b\83h\82ª\96³\82©\82Á\82½\82±\82Æ\82ð\8am\94F\82µ\82Ü\82µ\82½\82©\81H'#13#10#13#10
910                                                                                                         + '\81u\82Í\82¢\81v\82ð\89\9f\82·\82Æ\91\97\90M\82µ\82Ü\82·',
911                                                                                                         '\8am\94F',
912                                                                                                         MB_ICONQUESTION or MB_YESNO);
913                         if rc <> ID_YES then
914                                 Exit;
915                 end;
916
917                 SetNameList(NameComboBox.Text, MailComboBox.Text);
918                 if KotehanCheckBox.Checked then begin
919                         Board.KotehanName := NameComboBox.Text;
920                         Board.KotehanMail := MailComboBox.Text;
921                 end;
922
923                 if Board.IsBoardPlugInAvailable then begin
924                         body := BodyEdit.Text;
925                         if GikoSys.Setting.SpaceToNBSP then begin
926                                 body := CustomStringReplace( body, #09, '&nbsp;&nbsp;&nbsp;&nbsp;' );
927                                 body := CustomStringReplace( body, '  ', '&nbsp;&nbsp;' );
928                                 body := CustomStringReplace( body, '&nbsp; ', '&nbsp;&nbsp;' );
929                                 regexp := TAWKStr.Create( nil );
930                                 try
931                                         regexp.RegExp := '^ ';
932                                         regexp.GSub( '\&nbsp;', body );
933                                 finally
934                                         regexp.Free;
935                                 end;
936                         end;
937
938                         if FThreadItem = nil then begin
939                                 // \83X\83\8c\97§\82Ä
940                                 state := TGikoDownloadState( Board.BoardPlugIn.CreateThread(
941                                         DWORD( Board ), TitleEdit.Text, NameComboBox.Text, MailComboBox.Text, body ) );
942
943                                 if state = gdsComplete then begin
944                                         GikoForm.PlaySound('ResEnd');
945                                         SaveSendFile;
946                                         GikoForm.AddMessageList(FBoard.Title + ' [\90V\83X\83\8c\91\97\90M\8fI\97¹]', nil, gmiOK);
947                                         FWork := False;
948                                         Close;
949                                 end else if State = gdsError then begin
950                                         GikoForm.AddMessageList(FBoard.Title + ' [\90V\83X\83\8c\91\97\90M\8e¸\94s]', nil, gmiNG);
951                                 end else if State = gdsAbort then begin
952                                         GikoForm.AddMessageList(FThreadItem.Title + ' [\92\86\92f]', nil, gmiSAD);
953                                 end;
954                         end else begin
955                                 // \83\8c\83X
956                                 state := TGikoDownloadState( FThreadItem.BoardPlugIn.WriteThread(
957                                         DWORD( FThreadItem ), NameComboBox.Text, MailComboBox.Text, body ) );
958
959                                 if state = gdsComplete then begin
960                                         GikoForm.PlaySound('ResEnd');
961                                         SaveSendFile;
962                                         GikoForm.AddMessageList(FThreadItem.Title + ' [\83\8c\83X\91\97\90M\8fI\97¹]', nil, gmiOK);
963                     FWork := False;
964                                         Close;
965                                 end else if State = gdsError then begin
966                                         GikoForm.AddMessageList(FThreadItem.Title + ' [\83\8c\83X\91\97\90M\8e¸\94s]', nil, gmiNG);
967                                 end else if State = gdsAbort then begin
968                                         GikoForm.AddMessageList(FThreadItem.Title + ' [\92\86\92f]', nil, gmiSAD);
969                                 end;
970                         end;
971                 end else begin
972                         if not Timer1.Enabled then
973                                 Send(Board.SPID, Board.PON, True)
974                         else begin
975                                 if not CheckSambaTime(FHost, Now()) then begin
976                                         rc := GikoUtil.MsgBox(Handle,
977                                                                 'Samba24\82Ì\8bK\92è\92l\96¢\96\9e\82Ì\95b\90\94\82µ\82©\8co\89ß\82µ\82Ä\82¢\82Ü\82¹\82ñ\81B'#13#10
978                                                                 + '\91\97\90M\82ð\92\86\8e~\82µ\82Ü\82·\82©\81H' + #13#10
979                                                                 + '(\81u\82¢\82¢\82¦\81v\82¾\82Æ\91\97\90M\82µ\82Ü\82·)', 'Samba24\8cx\8d\90',
980                                                                 MB_YESNO or MB_ICONQUESTION);
981                                         if rc = IDYES then begin
982                                                 FWork := false;
983                                                 Exit;
984                                         end;
985                                 end;
986                                 Send(Board.SPID, Board.PON, True);
987                         end;
988                 end;
989         finally
990                 FWork := False;
991                 if Timer1.Enabled then
992                         ReadSambaTime(FHost);
993         end;
994 end;
995
996 procedure TEditorForm.SaveActionExecute(Sender: TObject);
997 begin
998 //
999 end;
1000
1001 procedure TEditorForm.CloseActionExecute(Sender: TObject);
1002 begin
1003         Close;
1004 end;
1005
1006 procedure TEditorForm.UndoActionExecute(Sender: TObject);
1007 begin
1008         SendMessage(GetActiveControlHandle, WM_UNDO, 0, 0);
1009 end;
1010
1011 procedure TEditorForm.CutActionExecute(Sender: TObject);
1012 begin
1013         SendMessage(GetActiveControlHandle, WM_CUT, 0, 0);
1014 end;
1015
1016 procedure TEditorForm.CopyActionExecute(Sender: TObject);
1017 begin
1018         SendMessage(GetActiveControlHandle, WM_COPY, 0, 0);
1019 end;
1020
1021 procedure TEditorForm.PasteActionExecute(Sender: TObject);
1022 begin
1023         SendMessage(GetActiveControlHandle, WM_PASTE, 0, 0);
1024 end;
1025
1026 procedure TEditorForm.SelectAllActionExecute(Sender: TObject);
1027 begin
1028         SendMessage(GetActiveControlHandle, EM_SETSEL, 0, GetWindowTextLength(GetActiveControlHandle));
1029 end;
1030
1031 procedure TEditorForm.TopActionExecute(Sender: TObject);     // \83E\83B\83\93\83h\83E\8dÅ\91O\96Ê(Stay)\83{\83^\83\93\82Ì\8f\88\97\9d
1032 begin
1033         if not (fsShowing in Self.FormState) then begin
1034                 if TopAction.Checked then begin // \83X\83e\83C\8fó\91Ô\82É\90Ý\92è
1035                         SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE);
1036                 end     else begin   // \83X\83e\83C\8fó\91Ô\89ð\8f\9c
1037                         SetWindowPos(Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE);
1038                 end;
1039                 // \83X\83e\83C\8fó\91Ô\82Ì\95Û\91
1040                 GikoSys.Setting.EditWindowStay := FormStyle = fsStayOnTop;
1041         end;
1042 end;
1043
1044 procedure TEditorForm.AbortActionExecute(Sender: TObject);
1045 begin
1046         FAbort := True;
1047 end;
1048
1049 procedure TEditorForm.SendActionUpdate(Sender: TObject);
1050 begin
1051         SendAction.Enabled := not FWork;
1052 end;
1053
1054 procedure TEditorForm.SaveActionUpdate(Sender: TObject);
1055 begin
1056         SaveAction.Enabled := False;
1057 end;
1058
1059 procedure TEditorForm.CloseActionUpdate(Sender: TObject);
1060 begin
1061         CloseAction.Enabled := not FWork;
1062 end;
1063
1064 procedure TEditorForm.UndoActionUpdate(Sender: TObject);
1065 begin
1066         UndoAction.Enabled := (GetActiveControlHandle <> 0)
1067                                                                                                 and (SendMessage(GetActiveControlHandle, EM_CANUNDO, 0, 0) <> 0)
1068                                                                                                 and (not FWork);
1069 end;
1070
1071 procedure TEditorForm.CutActionUpdate(Sender: TObject);
1072 var
1073         Selection: TSelection;
1074         AHandle: THandle;
1075 begin
1076         AHandle := GetActiveControlHandle;
1077         SendMessage(AHandle, EM_GETSEL, Longint(@Selection.StartPos), Longint(@Selection.EndPos));
1078         CutAction.Enabled := (AHandle <> 0)
1079                                                                                 and ((Selection.EndPos - Selection.StartPos) <> 0)
1080                                                                                 and (not FWork);
1081 end;
1082
1083 procedure TEditorForm.CopyActionUpdate(Sender: TObject);
1084 var
1085         Selection: TSelection;
1086         AHandle: THandle;
1087 begin
1088         AHandle := GetActiveControlHandle;
1089         SendMessage(AHandle, EM_GETSEL, Longint(@Selection.StartPos), Longint(@Selection.EndPos));
1090         CopyAction.Enabled := (AHandle <> 0)
1091                                                                                 and ((Selection.EndPos - Selection.StartPos) <> 0)
1092                                                                                 and (not FWork);
1093 end;
1094
1095 procedure TEditorForm.PasteActionUpdate(Sender: TObject);
1096 begin
1097         PasteAction.Enabled := (GetActiveControlHandle <> 0)
1098                                                                                         and (Clipboard.HasFormat(CF_TEXT))
1099                                                                                         and (not FWork);
1100 end;
1101
1102 procedure TEditorForm.TopActionUpdate(Sender: TObject);
1103 begin
1104         TopAction.Enabled := not FWork;
1105 end;
1106
1107 procedure TEditorForm.SageCheckBoxClick(Sender: TObject);
1108 begin
1109         if SageCheckBox.Checked then begin
1110                 if AnsiPos('sage', MailComboBox.Text) = 0 then
1111                         MailComboBox.Text := 'sage' + MailComboBox.Text;
1112         end else begin
1113                 if AnsiPos('sage', MailComboBox.Text) <> 0 then
1114                         MailComboBox.Text := StringReplace(MailComboBox.Text, 'sage', '', [rfReplaceAll]);
1115         end;
1116 end;
1117
1118 procedure TEditorForm.MailComboBoxChange(Sender: TObject);
1119 begin
1120         if AnsiPos('sage', MailComboBox.Text) = 0 then
1121                 SageCheckBox.Checked := False
1122         else
1123                 SageCheckBox.Checked := True;
1124 end;
1125
1126
1127 function TEditorForm.GetSPID(CookieLine: string): string;
1128 var
1129         s: string;
1130         i: Integer;
1131 begin
1132         Result := '';
1133         i := 0;
1134         while True do begin
1135                 s := Trim(GikoSys.GetTokenIndex(CookieLine, ';', i));
1136                 if s = '' then
1137                         Break
1138                 else begin
1139                         if Pos('SPID=', s) = 1 then begin
1140                                 Result := Trim(Copy(s, 6, Length(s)));
1141                                 Break;
1142                         end;
1143                 end;
1144                 inc(i);
1145         end;
1146 end;
1147
1148 function TEditorForm.GetPON(CookieLine: string): string;
1149 var
1150         s: string;
1151         i: Integer;
1152 begin
1153         Result := '';
1154         i := 0;
1155         while True do begin
1156                 s := Trim(GikoSys.GetTokenIndex(CookieLine, ';', i));
1157                 if s = '' then
1158                         Break
1159                 else begin
1160                         if Pos('PON=', s) = 1 then begin
1161                                 Result := Trim(Copy(s, 5, Length(s)));
1162                                 Break;
1163                         end;
1164                 end;
1165                 inc(i);
1166         end;
1167 end;
1168
1169 procedure TEditorForm.IdLogDebugReceive(ASender: TIdConnectionIntercept;
1170         AStream: TStream);
1171 var
1172         StringStream: TStringStream;
1173 begin
1174         StringStream := TStringStream.Create('');
1175         try
1176                 StringStream.CopyFrom(AStream, AStream.Size);
1177                 FDebugStrReceive := FDebugStrReceive + StringStream.DataString;
1178         finally
1179                 StringStream.Free;
1180         end;
1181 end;
1182
1183 procedure TEditorForm.IdLogDebugSend(ASender: TIdConnectionIntercept;
1184         AStream: TStream);
1185 var
1186         StringStream: TStringStream;
1187 begin
1188         StringStream := TStringStream.Create('');
1189         try
1190                 StringStream.CopyFrom(AStream, AStream.Size);
1191                 FDebugStrSend := FDebugStrSend + StringStream.DataString;
1192         finally
1193                 StringStream.Free;
1194         end;
1195 end;
1196
1197 procedure TEditorForm.TransActionExecute(Sender: TObject);
1198 begin
1199         AlphaBlend := TransAction.Checked;
1200         // \94¼\93§\96¾\8fó\91Ô\82Ì\95Û\91
1201         GikoSys.Setting.EditWindowTranslucent := TransAction.Checked;
1202 end;
1203
1204 procedure TEditorForm.TransActionUpdate(Sender: TObject);
1205 begin
1206         TransAction.Enabled := not FWork;
1207 end;
1208 //StatusBar\82ÌPanels[0]\82Ì\95\9d\82ð\89Â\95Ï\81B\8ec\82è\82ð\8cÅ\92è\82É\82·\82é
1209 procedure TEditorForm.StatusBarResize(Sender: TObject);
1210 begin
1211         StatusBar.Panels[0].Width := StatusBar.Width
1212                                                                         - StatusBar.Panels[1].Width - StatusBar.Panels[2].Width;
1213
1214 end;
1215
1216 procedure TEditorForm.Timer1Timer(Sender: TObject);
1217 begin
1218         if FSambaTime = ZERO_DATE then
1219                 StatusBar.Panels[1].Text := '\8f\89\8f\91'
1220         else begin
1221                 FNow := IncMilliSecond(FNow, 500);
1222                 StatusBar.Panels[1].Text := Format('%8.0f\95b\8co\89ß', [SecondSpan(FNow, FSambaTime)]);
1223         end;
1224
1225 end;
1226 //Samba.ini\82Ì\8f\91\82«\8d\9e\82Ý\8e\9e\8aÔ\82ð\93Ç\82Ý\8d\9e\82Þ
1227 procedure TEditorForm.ReadSambaTime(const AHost: string);
1228 var
1229         ini :TMemIniFile;
1230         tmp: string;
1231 begin
1232         Timer1.Enabled := false; //\8co\89ß\95b\90\94\95\\8e¦Timer\82ðOff\82É\82·\82é\81i\82±\82ê\82ªON\82Ì\82Æ\82«Samba24\91Î\8dôOn\81j
1233         FNow := Now();   //\8c»\8dÝ\8e\9e\8aÔ\82ð\8eæ\93¾\81iTimer\95\\8e¦\97p\82Å\81ACheck\82·\82é\82Æ\82«\82Í\8dÄ\82ÑNow()\82ð\8cÄ\82Ô\81j
1234         Timer1.Enabled := true; //\8co\89ß\95b\90\94\95\\8e¦Timer\82ðOn\82É\82·\82é\81i\82±\82ê\82ªON\82Ì\82Æ\82«Samba24\91Î\8dôOn\81j
1235         ini := TMemIniFile.Create(GikoSys.GetSambaFileName);
1236         try
1237                  //\95\8e\9a\97ñ\82Å\93Ç\82Ý\8eæ\82Á\82Ä\81A\95Ï\8a·\8aÖ\90\94\82ÅTDateTime\82Ö
1238                  tmp := ini.ReadString('Send', AHost, DateTimeToStr(ZERO_DATE));
1239                  FSambaTime := ConvertDateTimeString(tmp);
1240         finally
1241                 ini.Free;
1242         end;
1243 end;
1244 //Samba.ini\82É\8dÅ\8fI\8f\91\82«\8d\9e\82Ý\8e\9e\8aÔ\82ð\8f\91\82«\8d\9e\82Þ
1245 procedure TEditorForm.WriteSambaTime(const AHost: string; ATime: TDateTime);
1246 var
1247         ini :TMemIniFile;
1248 begin
1249         ini := TMemIniFile.Create(GikoSys.GetSambaFileName);
1250         try
1251                 ini.WriteDateTime('Send', AHost, ATime);
1252                 ini.UpdateFile;
1253         finally
1254                 ini.Free;
1255         end;
1256 end;
1257 //\8dÅ\8fI\8f\91\82«\8d\9e\82Ý\8e\9e\8aÔ\82Æ\8c»\8dÝ\8e\9e\82ð\94ä\8ar\82·\82é\81i\90^\81F\8bK\92è\92l\88È\8fã\81@\8bU\81F\8bK\92è\92l\96¢\96\9e\81j
1258 function TEditorForm.CheckSambaTime(const AHost: string; ATime: TDateTime): Boolean;
1259 var
1260         pastsec: double;
1261         SettingTime: Integer;
1262 begin
1263         SettingTime := ReadSettingTime(AHost);
1264         ReadSambaTime(AHost);
1265         pastsec := SecondSpan(ATime, FSambaTime);
1266         if pastsec > SettingTime then
1267                 Result := true
1268         else
1269                 Result := false;
1270 end;
1271 //AHost\81i\8eI\96¼\81j\82ÌSamba\82Ì\8bK\92è\92l\82ð\93Ç\82Ý\8d\9e\82Þ
1272 function TEditorForm.ReadSettingTime(const AHost: string): Integer;
1273 var
1274         ini :TMemIniFile;
1275 begin
1276         ini := TMemIniFile.Create(GikoSys.GetSambaFileName);
1277         try
1278                 Result := ini.ReadInteger('Setting', AHost, 0);
1279                 //\8bK\92è\92l\82ª\82O\82Ì\82Æ\82«\81A\82à\82µ\82­\82Í\90Ý\92è\82³\82ê\82Ä\82¢\82È\82¢\82Æ\82«\82Í\81A\83t\83@\83C\83\8b\82É\8f\91\82«\82½\82·\81B
1280                 if Result = 0 then begin
1281                         ini.WriteInteger('Setting', AHost, 0);
1282                         ini.UpdateFile;
1283                 end;
1284         finally
1285                 ini.Free;
1286         end;
1287 end;
1288 //Form\82ªActive\82É\82È\82Á\82½\82ç\8dÅ\8fI\8f\91\82«\8d\9e\82Ý\8e\9e\8aÔ\82ð\93Ç\82Ý\8d\9e\82Þ
1289 procedure TEditorForm.FormActivate(Sender: TObject);
1290 begin
1291         if ( Timer1.Enabled ) and ( FThreadItem <> nil )then
1292                 ReadSambaTime(FHost);
1293 end;
1294 //Samba24\91Î\8dô\82ð\8eg\82¤\82©\82Ç\82¤\82©\8c\88\82ß\82é\8aÖ\90\94
1295 //ReadSambaTime \82ð\8cÄ\82Ñ\8fo\82·\82ÆTimer\82ªOn\82É\82È\82é
1296 procedure TEditorForm.SetSamba24(AURL: string);
1297 var
1298         Protocol, Host, Path, Document, Port, Bookmark : string;
1299 begin
1300         //Samba24\91Î\8dô\82ð\82µ\82È\82¢\82È\82ç\8fI\97¹
1301         if not GikoSys.Setting.UseSamba then
1302                 Exit;
1303         //Host\82ÌURL\82É'.2ch.'\82©'.bbspink.'\82ª\8aÜ\82Ü\82ê\82Ä\82¢\82½\82çSamba24\91Î\8dô\82ð\82·\82é
1304         GikoSys.ParseURI( AURL, Protocol,Host, Path, Document, Port, Bookmark );
1305         if GikoSys.Is2chHost(Host) then begin
1306                 Host := Copy(Host, 1, AnsiPos('.', Host) - 1);
1307                 FHost := Host;   //FHost=\8eI\96¼
1308                 ReadSambaTime(FHost); //\88È\91O\82Ì\8f\91\82«\8d\9e\82Ý\8e\9e\8aÔ\82ð\93Ç\82Ý\8d\9e\82Þ
1309                 //StatusBar\82É\82±\82Ì\8eI\82Ì\8bK\92è\92l\82ð\95\\8e¦\82·\82é
1310                 StatusBar.Panels[2].Text := 'Samba24\8bK\92è\92l' + IntToStr(ReadSettingTime(FHost));
1311         end;
1312 end;
1313 procedure TEditorForm.FormCloseQuery(Sender: TObject;
1314   var CanClose: Boolean);
1315 begin
1316         CanClose := not FWork;
1317 end;
1318
1319 function TEditorForm.GetOEIndentChar : string;
1320 var
1321         regKey                  : TRegistry;
1322         Identities      : string;
1323         IndentChar      : DWORD;
1324 const
1325         DEFAULT_CHAR    = '> ';
1326         OE_MAIL_PATH    = '\Software\Microsoft\Outlook Express\5.0\Mail';
1327         INDENT_CHAR             = 'Indent Char';
1328 begin
1329
1330         Result  := DEFAULT_CHAR;
1331         regKey  := TRegistry.Create;
1332         try
1333                 try
1334                         regKey.RootKey  := HKEY_CURRENT_USER;
1335                         if not regKey.OpenKey( 'Identities', False ) then
1336                                 Exit;
1337                         Identities                      := regKey.ReadString( 'Default User ID' );
1338                         if Identities = '' then
1339                                 Exit;
1340                         if not regKey.OpenKey( Identities + OE_MAIL_PATH, False ) then
1341                                 Exit;
1342                         IndentChar := regKey.ReadInteger( INDENT_CHAR );
1343                         Result := Char( IndentChar ) + ' ';
1344                 except
1345                 end;
1346         finally
1347                 regKey.Free;
1348         end;
1349
1350 end;
1351
1352 procedure TEditorForm.QuotePasteActionExecute(Sender: TObject);
1353 var
1354         s                       : TStringList;
1355         i                       : Integer;
1356         quote   : string;
1357 begin
1358
1359         quote   := GetOEIndentChar;
1360         s                       := TStringList.Create;
1361         try
1362                 s.Text  := Clipboard.AsText;
1363
1364                 for i := s.Count - 1 downto 0 do
1365                         s[ i ]  := quote + s[ i ];
1366
1367                 BodyEdit.SelText        := s.Text;
1368         finally
1369                 s.Free;
1370         end;
1371
1372 end;
1373
1374 end.
1375