OSDN Git Service

b5d1175514c90c21a4f758d4f9cce7c80cbc3bfa
[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,
8 {$IF Defined(DELPRO) }
9         SHDocVw,
10 {$ELSE}
11         SHDocVw_TLB,
12 {$IFEND}
13         ActiveX, {HTTPApp,} YofUtils, IniFiles, StrUtils,
14         GikoSystem, GikoUtil, ImgList, Clipbrd, BoardGroup,
15         IdAntiFreezeBase,       IdAntiFreeze, IdBaseComponent, IdComponent,
16         IdTCPConnection, IdTCPClient, IdHTTP, ActnList, StdActns, IdIntercept,
17         IdLogBase, IdLogDebug, IdException;
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                 procedure EditorPageChange(Sender: TObject);
91                 procedure FormCreate(Sender: TObject);
92                 procedure BrowserStatusTextChange(Sender: TObject;
93                         const Text: WideString);
94                 procedure FormClose(Sender: TObject; var Action: TCloseAction);
95                 procedure FormDestroy(Sender: TObject);
96                 procedure SendActionExecute(Sender: TObject);
97                 procedure SaveActionExecute(Sender: TObject);
98                 procedure AbortActionExecute(Sender: TObject);
99                 procedure CloseActionExecute(Sender: TObject);
100                 procedure UndoActionExecute(Sender: TObject);
101                 procedure CutActionExecute(Sender: TObject);
102                 procedure CopyActionExecute(Sender: TObject);
103                 procedure PasteActionExecute(Sender: TObject);
104                 procedure SendActionUpdate(Sender: TObject);
105                 procedure SaveActionUpdate(Sender: TObject);
106                 procedure CloseActionUpdate(Sender: TObject);
107                 procedure UndoActionUpdate(Sender: TObject);
108                 procedure CutActionUpdate(Sender: TObject);
109                 procedure CopyActionUpdate(Sender: TObject);
110                 procedure PasteActionUpdate(Sender: TObject);
111                 procedure TopActionExecute(Sender: TObject);
112                 procedure TopActionUpdate(Sender: TObject);
113                 procedure SageCheckBoxClick(Sender: TObject);
114                 procedure MailComboBoxChange(Sender: TObject);
115                 procedure TransActionExecute(Sender: TObject);
116                 procedure TransActionUpdate(Sender: TObject);
117                 procedure IdLogDebugReceive(ASender: TIdConnectionIntercept;
118                         AStream: TStream);
119                 procedure IdLogDebugSend(ASender: TIdConnectionIntercept;
120                         AStream: TStream);
121     procedure SelectAllActionExecute(Sender: TObject);
122         private
123                 FThreadItem: TThreadItem;
124                 FBoard: TBoard;
125                 FNameComboEdit: THandle;
126                 FMailComboEdit: THandle;
127                 FAbort: Boolean;
128                 FWork: Boolean;
129                 FStatusCode: Integer;
130                 FDebugStrReceive: string;
131                 FDebugStrSend: string;
132
133                 procedure Preview;
134                 function RepHtml(s: string): string;
135                 function Check: Boolean;
136                 procedure SetNameList(sName, sMail: string);
137 //              procedure Send(SendType: TGikoSendType; SPID: string; PON: string; FirstWriting: Boolean);
138                 procedure Send(SPID: string; PON: string; FirstWriting: Boolean);
139
140                 function GetActiveControlHandle: THandle;
141 //              function GetSendData: string;
142 //              procedure GetSendData(Source: TStringStream);
143                 procedure GetSendData(Source: TStringStream);
144                 procedure SaveSendFile;
145                 procedure SetContent(Content: string);
146                 function GetSPID(CookieLine: string): string;
147                 function GetPON(CookieLine: string): string;
148                 function GetResultType(ResponseText: string): TGikoResultType;
149         protected
150                 procedure CreateParams(var Params: TCreateParams); override;
151         public
152                 procedure SetFont;
153                 procedure SetThreadItem(Item: TThreadItem);
154                 procedure SetBoard(Item: TBoard);
155         end;
156
157 implementation
158
159 uses
160         Giko, ItemDownload;
161 const
162         CAPTION_NAME_NEW: string = '\83M\83R\83i\83\83X\83\8c\97§\82Ä\83G\83f\83B\83^';
163         CAPTION_NAME_RES: string = '\83M\83R\83i\83\83\8c\83X\83G\83f\83B\83^';
164
165         //DAX\82³\82ñ±Ø¶ÞÄ!(\81L\81¤\81M)
166         READCGI_ERR                     = '-ERR';
167         READCGI_INCR            = '-INCR';
168         READCGI_OK                      = '+OK';
169         READCGI_PARTIAL = '+PARTIAL';
170         READCGI_ERR_FOUND_KAKO  = '-ERR \89ß\8b\8e\83\8d\83O\91q\8cÉ\82Å\94­\8c©';
171         READCGI_ERR_NOT_HTML            = '-ERR html\89»\91Ò\82¿';
172         READCGI_ERR_NOT_FOUND           = '-ERR \82»\82ñ\82È\94Âor\83X\83\8c\83b\83h\82È\82¢\82Å\82·\81B';
173         READCGI_ERR_ABONE                               = '-ERR \82Ç\82±\82©\82Å\82 \82Ú\81[\82ñ\82ª\82 \82Á\82½\82Ý\82½\82¢\82Å\82·\81B';
174         READCGI_ERR_TIMEOUT                     = '-ERR \8ew\92è\8e\9e\8aÔ\82ª\89ß\82¬\82Ü\82µ\82½\81B';
175         READCGI_ERR_CANTUSE                     = '-ERR \82à\82¤\81@\82Â\82©\82¦\82Ü\82¹\82ñ';
176         RES2CH_TRUE                             = '<!-- 2ch_X:true -->';
177         RES2CH_FALSE                    = '<!-- 2ch_X:false -->';
178         RES2CH_ERROR                    = '<!-- 2ch_X:error -->';
179         RES2CH_CHECK                    = '<!-- 2ch_X:check -->';
180         RES2CH_COOKIE                   = '<!-- 2ch_X:cookie -->';
181
182 type
183         TSelection = record
184                 StartPos, EndPos: Integer;
185         end;
186
187 {$R *.DFM}
188
189 {constructor TEditorForm.Create(AOwner: TComponent; Item: TBoard);
190 begin
191         inherited Create(AOwner);
192 end;}
193
194 procedure TEditorForm.CreateParams(var Params: TCreateParams);
195 begin
196         inherited;
197         if FormStyle in [fsNormal, fsStayOnTop] then
198                 if BorderStyle in [bsSingle, bsSizeable] then begin
199                         Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
200                         Params.WndParent := 0;
201                 end;
202 end;
203
204 {procedure TEditorForm.CreateParams(var Params: TCreateParams);
205 begin
206         inherited CreateParams(Params);
207         Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
208 end;}
209
210 procedure TEditorForm.FormCreate(Sender: TObject);
211 var
212         wp: TWindowPlacement;
213     hUser32 : HINST;
214 begin
215         FWork := False;
216         Browser.Navigate('about:blank');
217
218         FBoard := nil;
219         FThreadItem := nil;
220
221         //\83E\83B\83\93\83h\83E\82Ì\88Ê\92u\90Ý\92è
222 {       i := GikoSys.Setting.EditWindowLeft +
223                          GikoSys.Setting.EditWindowTop +
224                          GikoSys.Setting.EditWindowWidth +
225                          GikoSys.Setting.EditWindowHeight;
226         if i > 0 then begin
227                 SetBounds(GikoSys.Setting.EditWindowLeft, GikoSys.Setting.EditWindowTop,
228                                                         GikoSys.Setting.EditWindowWidth, GikoSys.Setting.EditWindowHeight);
229                 if GikoSys.Setting.EditWindowMax then
230                         WindowState := wsMaximized;
231         end;}
232         //\83E\83B\83\93\83h\83E\82Ì\88Ê\92u\90Ý\92è
233         wp.length := sizeof(wp);
234         wp.rcNormalPosition.Top := GikoSys.Setting.EditWindowTop;
235         wp.rcNormalPosition.Left := GikoSys.Setting.EditWindowLeft;
236         wp.rcNormalPosition.Bottom := GikoSys.Setting.EditWindowTop + GikoSys.Setting.EditWindowHeight;
237         wp.rcNormalPosition.Right := GikoSys.Setting.EditWindowLeft + GikoSys.Setting.EditWindowWidth;
238         wp.showCmd := SW_HIDE;
239         SetWindowPlacement(Handle, @wp);
240
241         if GikoSys.Setting.EditWindowMax then
242                 WindowState := wsMaximized;
243
244         //\83E\83B\83\93\83h\83E\82ª\89æ\96Ê\8aO\82È\82ç\89æ\96Ê\93à\82É\88Ú\93®\82·\82é
245         if (Left + Width) > Screen.Width then
246                 Left := Screen.Width - Width;
247         if (Top + Height) > Screen.Height then
248                 Top := Screen.Height - Height;
249         if Left < 0 then
250                 Left := 0;
251         if Top < 0 then
252                 Top := 0;
253
254         //\95\9d\82Æ\8d\82\82³\82ª0\82È\82ç\91å\82«\82­\82·\82é
255         if GikoSys.Setting.EditWindowHeight < 0 then
256                 Height := 400;
257         if GikoSys.Setting.EditWindowWidth < 0 then
258                 Width := 600;
259
260         EditorPage.ActivePage := EditorTab;
261         FNameComboEdit := GetWindow(NameComboBox.Handle, GW_CHILD);
262         FMailComboEdit := GetWindow(MailComboBox.Handle, GW_CHILD);
263         NameComboBox.Items.Assign(GikoSys.Setting.NameList);
264         MailComboBox.Items.Assign(GikoSys.Setting.MailList);
265         SetFont;
266         //u32 := GetModuleHandle('User32.dll') <> 0;
267     hUser32 := LoadLibrary('User32.dll');
268     if hUser32 <> 0 then
269         TransAction.Enabled := true
270     else
271         TransAction.Enabled := false;
272     FreeLibrary(hUser32);
273
274 end;
275
276 procedure TEditorForm.SetBoard(Item: TBoard);
277 begin
278         FBoard := Item;
279         Caption := CAPTION_NAME_NEW + ' - [' + Item.Title + ']';
280         NameComboBox.Text := FBoard.KotehanName;
281         MailComboBox.Text := FBoard.KotehanMail;
282         SageCheckBox.Checked := AnsiPos('sage', MailComboBox.Text) <> 0;
283         TitlePanel.Visible := True;
284 end;
285
286 procedure TEditorForm.SetThreadItem(Item: TThreadItem);
287 begin
288         FThreadItem := Item;
289         Caption := CAPTION_NAME_RES + ' - [' + FThreadItem.Title + ']';
290         NameComboBox.Text := FThreadItem.ParentBoard.KotehanName;
291         MailComboBox.Text := FThreadItem.ParentBoard.KotehanMail;
292         SageCheckBox.Checked := AnsiPos('sage', MailComboBox.Text) <> 0;
293         TitlePanel.Visible := False;
294 end;
295
296 procedure TEditorForm.SetFont;
297 begin
298         BodyEdit.Font.Name := GikoSys.Setting.EditorFontName;
299         BodyEdit.Font.Size := GikoSys.Setting.EditorFontSize;
300         BodyEdit.Font.Color := GikoSys.Setting.EditorFontColor;
301         BodyEdit.Color := GikoSys.Setting.EditorBackColor;
302 end;
303
304 procedure TEditorForm.Preview;
305 var
306         Title: string;
307         No: string;
308         Mail: string;
309         Namae: string;
310         DateTime: string;
311         Body: string;
312         s: string;
313
314                                 posTrip : Integer;
315                                 tripOrigin : string;
316 begin
317         if FThreadItem = nil then begin
318                 No := '1';
319                 Title := RepHtml(TitleEdit.Text);
320         end else begin
321                 No := IntToStr(FThreadItem.Count + 1);
322                 Title := RepHtml(FThreadItem.Title);
323         end;
324
325         Namae := RepHtml(NameComboBox.Text);
326         Mail := RepHtml(MailComboBox.Text);
327         Body := RepHtml(BodyEdit.Text);
328         Body := StringReplace(Body, #13#10, '<br>', [rfReplaceAll]);
329         DateTime := FormatDateTime('yyyy/mm/dd(aaa) hh:nn', now);
330
331         if Trim(Namae) = '' then
332                 Namae := '\96¼\96³\82µ\82³\82ñ';
333
334         s := '<HTML><HEAD>' + #13#10
335                         + '<META http-equiv="Content-Type" content="text/html; charset=Shift_JIS">' + #13#10
336                         + '<TITLE>' + title + '</TITLE>' + #13#10
337 //                      + '<STYLE><!--BODY{font-size : 9pt;font-family : "\82l\82\82o\83S\83V\83b\83N";}--></STYLE>' + #13#10
338                         + '</HEAD>' + #13#10
339                         + '<BODY text="#000000" bgcolor="#EFEFEF" link="#0000FF" alink="#FF0000" vlink="#660099">' + #13#10
340                         + '<FONT COLOR="#FF0000">' + title + '</FONT>' + #13#10
341                         + '<DL>' + #13#10;
342                                 posTrip := Pos( '#', Namae );
343                                 if posTrip > 0 then
344                                 begin
345                                                                 tripOrigin := Copy( Namae, posTrip + 1, Length( Namae ) );
346                                                                 Namae :=
347                                                                                                 Copy( Namae, 1, posTrip - 1 ) + '</B> \81\9f' +
348                                                                                                 get_2ch_trip( PChar( tripOrigin ) ) + '<B>';
349                                 end;
350         if Mail = '' then
351                 s := s + '<DT>' + No + ' \81F <FONT color="forestgreen"><B>' + Namae + '</B></FONT> \81F ' + DateTime+ '<BR><DD>' + Body + '<BR><BR><BR>' + #13#10
352         else
353                 s := s + '<DT>' + No + ' \81F <A href="mailto:' + Mail + '"><B>' + Namae + '</B></A> [' + Mail + ']\81F ' + DateTime+ '<BR><DD>' + Body + '<BR><BR><BR>' + #13#10;
354         s := s + '</BODY></HTML>';
355         SetContent(s);
356 end;
357
358 function TEditorForm.RepHtml(s: string): string;
359 begin
360 //      s := StringReplace(s, '&', '&amp;', [rfReplaceAll]);
361         s := StringReplace(s, '<', '&lt;', [rfReplaceAll]);
362         s := StringReplace(s, '>', '&gt;', [rfReplaceAll]);
363 //      s := StringReplace(s, ' ', '&nbsp;', [rfReplaceAll]);  //\8ed\97l\95Ï\8dX\82É\82æ\82è&nbsp;\8eg\97p\95s\89Â
364         s := StringReplace(s, '"', '&quot;', [rfReplaceAll]);
365         Result := s;
366 end;
367
368 procedure TEditorForm.EditorPageChange(Sender: TObject);
369 begin
370         if EditorPage.ActivePage = PreviewTab then begin
371                 Preview;
372         end else begin
373                 Browser.Navigate('about:blank');
374         end;
375 end;
376
377 procedure TEditorForm.BrowserStatusTextChange(Sender: TObject;
378         const Text: WideString);
379 begin
380         if EditorPage.ActivePage = PreviewTab then begin
381                 StatusBar.Panels[0].Text := Text;
382         end else begin
383                 StatusBar.Panels[0].Text := '';
384         end;
385 end;
386
387 function TEditorForm.Check: Boolean;
388 var
389         Msg: string;
390         rc: Integer;
391         Board: TBoard;
392 begin
393         Result := True;
394         if FThreadItem = nil then
395                 Board := FBoard
396         else
397                 Board := FThreadItem.ParentBoard;
398
399         if (not GikoSys.Setting.UseMachineTime) and
400                  ((Board.LastGetTime = 0) or
401                         (Board.LastGetTime = ZERO_DATE)) then begin
402                 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
403                                  + '\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¢';
404                 MsgBox(Handle, Msg, '\83G\83\89\81[', MB_OK or MB_ICONSTOP);
405                 Result := False;
406         end else if BodyEdit.Text = '' then begin
407                 Msg := '\96{\95\82ª\93ü\97Í\82³\82ê\82Ä\82¢\82Ü\82¹\82ñ\81B';
408                 MsgBox(Handle, Msg, '\83G\83\89\81[', MB_OK or MB_ICONSTOP);
409                 Result := False;
410         end else if (FBoard <> nil) and (Trim(TitleEdit.Text) = '') then begin
411                 Msg := '\83^\83C\83g\83\8b\82ª\93ü\97Í\82³\82ê\82Ä\82¢\82Ü\82¹\82ñ\81B';
412                 MsgBox(Handle, Msg, '\83G\83\89\81[', MB_OK or MB_ICONSTOP);
413                 Result := False;
414         end else begin
415                 if (not GikoSys.Dolib.Connected) and (AnsiPos('\81\9c', NameComboBox.Text) <> 0) then begin
416                         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
417                                          + '\82±\82Ì\82Ü\82Ü\91\97\90M\82µ\82Ä\82à\82æ\82ë\82µ\82¢\82Å\82·\82©\81H';
418                         rc := MsgBox(Handle, Msg, '\8am\94F', MB_YESNO or MB_ICONQUESTION);
419                         Result := (rc = IDYES);
420                 end;
421         end;
422 end;
423
424 procedure TEditorForm.FormClose(Sender: TObject; var Action: TCloseAction);
425 begin
426         Action := caFree;
427 end;
428
429 procedure TEditorForm.FormDestroy(Sender: TObject);
430 var
431         wp: TWindowPlacement;
432 begin
433         //\8dÅ\91å\89»\81E\83E\83B\83\93\83h\83E\88Ê\92u\95Û\91
434         wp.length := sizeof(wp);
435         GetWindowPlacement(Handle, @wp);
436
437         GikoSys.Setting.EditWindowTop := wp.rcNormalPosition.Top;
438         GikoSys.Setting.EditWindowLeft := wp.rcNormalPosition.Left;
439         GikoSys.Setting.EditWindowHeight := wp.rcNormalPosition.Bottom - wp.rcNormalPosition.Top;
440         GikoSys.Setting.EditWindowWidth := wp.rcNormalPosition.Right - wp.rcNormalPosition.Left;
441         GikoSys.Setting.EditWindowMax := WindowState = wsMaximized;
442 end;
443
444 procedure TEditorForm.SetNameList(sName, sMail: string);
445 begin
446         if Trim(sName) <> '' then begin
447                 if GikoSys.Setting.NameList.IndexOf(sName) = -1 then
448                         GikoSys.Setting.NameList.Insert(0, sName);
449         end;
450         if Trim(sMail) <> '' then begin
451                 if GikoSys.Setting.MailList.IndexOf(sMail) = -1 then
452                         GikoSys.Setting.MailList.Insert(0, sMail);
453         end;
454 end;
455
456 function TEditorForm.GetActiveControlHandle: THandle;
457 begin
458         if EditorPage.ActivePage = EditorTab then begin
459                 if ActiveControl = NameComboBox then
460                         Result := FNameComboEdit
461                 else if ActiveControl = MailComboBox then
462                         Result := FMailComboEdit
463                 else if ActiveControl = BodyEdit then
464                         Result := BodyEdit.Handle
465                 else if ActiveControl = TitleEdit then
466                         Result := TitleEdit.Handle
467                 else
468                         Result := 0;
469         end else
470                 Result := 0;
471 end;
472
473 procedure TEditorForm.SetContent(Content: string);
474 var
475         doc : Variant;
476 begin
477         doc := Browser.Document;
478         doc.Clear;
479         doc.open;
480         doc.charset := 'Shift_JIS';
481         doc.Write(Content);
482         doc.Close;
483 end;
484
485 procedure TEditorForm.Send(SPID: string; PON: string; FirstWriting: Boolean);
486 var
487         TextStream: TStringStream;
488         Source: TStringStream;
489         ResponseText: string;
490         URL: string;
491         RefURL: string;
492         State: TGikoDownloadState;
493         ResultType: TGikoResultType;
494         MsgResult: Integer;
495         Cookie: string;
496         Board: TBoard;
497 begin
498         FAbort := False;
499         State := gdsError;
500         if FThreadItem = nil then
501                 Board := FBoard
502         else
503                 Board := FThreadItem.ParentBoard;
504
505         Indy.Request.Clear;
506         Indy.ProxyParams.BasicAuthentication := False;
507         if GikoSys.Setting.WriteProxy then begin
508                 Indy.ProxyParams.ProxyServer := GikoSys.Setting.WriteProxyAddress;
509                 Indy.ProxyParams.ProxyPort := GikoSys.Setting.WriteProxyPort;
510                 Indy.ProxyParams.ProxyUsername := GikoSys.Setting.WriteProxyUserID;
511                 Indy.ProxyParams.ProxyPassword := GikoSys.Setting.WriteProxyPassword;
512                 if GikoSys.Setting.ReadProxyUserID <> '' then
513                         Indy.ProxyParams.BasicAuthentication := True;
514         end else begin
515                 Indy.ProxyParams.ProxyServer := '';
516                 Indy.ProxyParams.ProxyPort := 80;
517                 Indy.ProxyParams.ProxyUsername := '';
518                 Indy.ProxyParams.ProxyPassword := '';
519         end;
520         if FThreadItem = nil then begin
521                 URL := FBoard.GetSendURL;
522                 RefURL := GikoSys.UrlToServer(FBoard.URL) + 'test/bbs.cgi';
523         end else begin
524                 URL := FThreadItem.GetSendURL;
525                 RefURL := GikoSys.UrlToServer(FThreadItem.ParentBoard.URL)
526                                                 + 'test/read.cgi/'
527                                                 + FThreadItem.ParentBoard.BBSID
528                                                 + '/' + ChangeFileExt(FThreadItem.FileName, '')
529                                                 + '/l50';
530         end;
531         Indy.Request.UserAgent := GikoSys.GetUserAgent;
532         Indy.Request.Referer := RefURL;
533         Indy.Request.AcceptEncoding := '';
534
535         Cookie := '';
536         if SPID <> '' then
537                 Cookie := Cookie + 'SPID=' + SPID + '; ';
538         if PON <> '' then
539                 Cookie := Cookie + 'PON=' + PON + '; ';
540         Cookie := 'Cookie: ' + Cookie + 'NAME=' + NameComboBox.Text + '; MAIL=' + MailComboBox.Text;
541
542         Indy.Request.CustomHeaders.Clear;
543 //      Indy.Request.CacheControl := 'no-cache';
544         Indy.Request.CustomHeaders.Add('Pragma: no-cache');
545         Indy.Request.AcceptLanguage := 'ja';
546         Indy.Request.Accept := 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*';
547         Indy.Request.ContentType := 'application/x-www-form-urlencoded';
548         Indy.Request.CustomHeaders.Add(Cookie);
549         TextStream := TStringStream.Create('');
550         Source := TStringStream.Create('');
551         try
552                 try
553                         FDebugStrReceive := '';
554                         FDebugStrSend := '';
555                         GetSendData(Source);
556                         Indy.Post(URL, Source, TextStream);
557                         ResponseText := TextStream.DataString;
558
559                         ResultType := GetResultType(ResponseText);
560
561                         if ResultType = grtOK then
562                                 State := gdsComplete
563                         else if ResultType = grtCookie then begin
564                                 //\83\8b\81[\83v\96h\8e~
565                                 if not FirstWriting then
566                                         raise Exception.Create('');
567                                 MsgResult := MsgBox(
568                                         Handle,
569                                         '\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 +
570                                         '\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 +
571                                         '\91S\90Ó\94C\82ð\95\89\82¤\82±\82Æ\82ð\8f³\91ø\82µ\82Ä\8f\91\82«\8d\9e\82Ý\82Ü\82·\82©\81H',
572                                         '\8fî\95ñ',
573                                         MB_YESNO or MB_ICONQUESTION);
574                                 if MsgResult = IDYES then begin
575                                         Board.SPID := GetSPID(Indy.Response.RawHeaders.Values['Set-Cookie']);
576                                         Board.PON := GetPON(Indy.Response.RawHeaders.Values['Set-Cookie']);
577                                         if (Board.SPID = '') and (Board.PON = '') then
578                                                 raise Exception.Create('');
579                                         //\82à\82¤\88ê\89ñ\82±\82Ì\83\81\83\\83b\83h
580                                         Send(Board.SPID, Board.PON, False);
581                                         Exit;
582                                 end else begin
583                                         Board.SPID := '';
584                                         Board.PON := '';
585                                         Exit;
586                                 end;
587                         end else if ResultType = grtCheck then begin
588                                 //
589                                 //\83\8b\81[\83v\96h\8e~
590                                 if not FirstWriting then
591                                         raise Exception.Create('');
592
593                                 MsgResult := MsgBox(
594                                         Handle,
595                                         '\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 +
596                                         '\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 +
597                                         '\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 +
598                                         '\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 +
599                                         #13#10 +
600                                         '\91S\90Ó\94C\82ð\95\89\82¤\82±\82Æ\82ð\8f³\91ø\82µ\82Ä\8f\91\82«\8d\9e\82Ý\82Ü\82·\82©\81H',
601                                         '\8am\94F',
602                                         MB_YESNO or MB_ICONQUESTION);
603
604                                 if MsgResult = IDYES then begin
605                                         Board.SPID := GetSPID(Indy.Response.RawHeaders.Values['Set-Cookie']);
606                                         Board.PON := GetPON(Indy.Response.RawHeaders.Values['Set-Cookie']);
607                                         if (Board.SPID = '') and (Board.PON = '') then
608                                                 raise Exception.Create('');
609                                         Send(Board.SPID, Board.PON, False);
610                                         Exit;
611                                 end else begin
612                                         Board.SPID := '';
613                                         Board.PON := '';
614                                         Exit;
615                                 end;
616                         end else begin
617                                 State := gdsError;
618                                 raise Exception.Create('');
619                         end;
620                 except
621                         on E: EIdConnectException do begin
622                                 State := gdsError;
623                                 ResponseText := '<html><body>'
624                                                                                         + '<div>\90Ú\91±\82ª\8e¸\94s\82µ\82Ü\82µ\82½<br>'
625                                                                                         + '\89ñ\90ü\82â\83v\83\8d\83L\83V\82Ì\8fó\91Ô\82ð\92²\82×\82Ä\82­\82¾\82³\82¢<br></div>'
626                                                                                         + '<br><br><div>' + E.Message + '</div>'
627                                                                                         + '</body></html>';
628                         end;
629                         on E: Exception do begin
630                                 State := gdsError;
631
632                                 FDebugStrReceive := AnsiReplaceText(FDebugStrReceive, '<', '&lt;');
633                                 FDebugStrReceive := AnsiReplaceText(FDebugStrReceive, '>', '&gt;');
634                                 FDebugStrSend := AnsiReplaceText(FDebugStrSend, '<', '&lt;');
635                                 FDebugStrSend := AnsiReplaceText(FDebugStrSend, '>', '&gt;');
636
637                                 ResponseText := '<html><body>' + TextStream.DataString;
638                                 ResponseText := AnsiReplaceText(ResponseText, '</body>', '');
639                                 ResponseText := AnsiReplaceText(ResponseText, '</html>', '');
640                                 ResponseText := ResponseText + '<hr><div align="left"><pre>';
641                                 ResponseText := ResponseText + '<b>\82±\82±\82©\82ç\83M\83R\83i\83r\82Ì\8fî\95ñ</b>'#13#10;
642                                 ResponseText := ResponseText + #13#10'\81\9c\91\97\90M'#13#10;
643                                 ResponseText := ResponseText + FDebugStrSend;
644                                 ResponseText := ResponseText + #13#10'\81\9c\8eó\90M'#13#10;
645                                 ResponseText := ResponseText + FDebugStrReceive;
646                                 ResponseText := ResponseText + '</pre></div></body></html>';
647                         end;
648                 end;
649                 FStatusCode := Indy.ResponseCode;
650                 if FAbort then
651                         State := gdsAbort;
652         finally
653                 Source.Free;
654                 TextStream.Free;
655         end;
656
657         if State = gdsComplete then begin
658                 GikoForm.PlaySound('ResEnd');
659                 SaveSendFile;
660                 if FThreadItem = nil then
661                         GikoForm.AddMessageList(FBoard.Title + ' [\90V\83X\83\8c\91\97\90M\8fI\97¹]', nil, gmiOK)
662                 else
663                         GikoForm.AddMessageList(FThreadItem.Title + ' [\83\8c\83X\91\97\90M\8fI\97¹]', nil, gmiOK);
664                 Close;
665         end else if State = gdsError then begin
666                 if FThreadItem = nil then
667                         GikoForm.AddMessageList(FBoard.Title + ' [\90V\83X\83\8c\91\97\90M\8e¸\94s]', nil, gmiNG)
668                 else
669                         GikoForm.AddMessageList(FThreadItem.Title + ' [\83\8c\83X\91\97\90M\8e¸\94s]', nil, gmiNG);
670                 EditorPage.ActivePage := PreviewTab;
671                 SetContent(ResponseText);
672         end else if State = gdsAbort then begin
673                 GikoForm.AddMessageList(FThreadItem.Title + ' [\92\86\92f]', nil, gmiSAD);
674         end;
675 end;
676
677 function TEditorForm.GetResultType(ResponseText: string): TGikoResultType;
678 begin
679         if AnsiPos('\8f\91\82«\82±\82Ý\82ª\8fI\82í\82è\82Ü\82µ\82½', ResponseText) <> 0 then
680                 Result := grtOK
681         else if (AnsiPos('\83N\83b\83L\81[\82ª\82È\82¢\82©\8aú\8cÀ\90Ø\82ê\82Å\82·', ResponseText) > 0) or
682                                         (AnsiPos('<title>\83N\83b\83L\81[\8am\94F\81I</title>', ResponseText) > 0)  or
683                                         (AnsiPos('<title>\81¡\83N\83b\83L\81[\8am\94F\81I\81¡</title>', ResponseText) > 0)  or
684                                         //(AnsiPos('\83N\83b\83L\81[\8am\94F', ResponseText) > 0) or
685                                         (AnsiPos(RES2CH_COOKIE, ResponseText) > 0)  then
686                 Result := grtCookie
687         else if (AnsiPos('<font size=+2 color=#FF0000>\8f\91\82«\8d\9e\82Ý\83`\83F\83b\83N\81I </font>', ResponseText) > 0)  or
688                                         (AnsiPos('<title>\81¡ \8f\91\82«\8d\9e\82Ý\8am\94F\82µ\82Ü\82· \81¡</title>', ResponseText) > 0)  or
689                                         (AnsiPos('<title>\93\8a\8de\8am\94F</title>', ResponseText) > 0)  or
690                                         (AnsiPos('<b>\8f\91\82«\82±\82Ý\8am\94F</b>', ResponseText) > 0)  or
691                                         (AnsiPos('="../test/subbbs.cgi">', ResponseText) > 0)  or
692                                         (AnsiPos(RES2CH_FALSE, ResponseText) > 0)  then
693                 Result := grtCheck
694         else
695                 Result := grtError;
696 end;
697
698
699 procedure TEditorForm.GetSendData(Source: TStringStream);
700 var
701         SessionID: string;
702         s: string;
703         SendTime: Integer;
704         Adjust: Integer;
705         Board: TBoard;
706 begin
707         if FThreadItem = nil then
708                 Board := FBoard
709         else
710                 Board := FThreadItem.ParentBoard;
711
712         if GikoSys.Setting.UseMachineTime then begin
713                 if GikoSys.Setting.TimeAdjust then
714                         Adjust := Gikosys.Setting.TimeAdjustSec
715                 else
716                         Adjust := GikoSys.Setting.TimeAdjustSec * -1;
717                 SendTime := GikoSys.DateTimeToInt(Now) - (9 * 60 * 60) + Adjust
718         end else begin
719                 if (Board.LastGetTime = 0) or (Board.LastGetTime = ZERO_DATE) then
720                         SendTime := GikoSys.DateTimeToInt(Now)
721                 else
722                         SendTime := GikoSys.DateTimeToInt(Board.LastGetTime);
723         end;
724         SessionID := GikoSys.Dolib.SessionID;
725         if SessionID <> '' then
726                 s := 'sid=' + HttpEncode(SessionID) + '&'
727         else
728                 s := '';
729         s := s + 'subject=&'
730                                  + 'FROM=' + HttpEncode(NameComboBox.Text) + '&'
731                                  + 'mail=' + HttpEncode(MailComboBox.Text) + '&'
732                                  + 'MESSAGE=' + HttpEncode(BodyEdit.Text) + '&'
733                                  + 'bbs=' + Board.BBSID + '&'
734                                  + 'time=' + IntToStr(SendTime) + '&';
735         if FThreadItem = nil then begin
736                 s := s + 'subject=' + HttpEncode(TitleEdit.Text) + '&';
737                 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;
738         end else begin
739                 s := s + 'key=' + ChangeFileExt(FThreadItem.FileName, '') + '&';
740                 s := s + 'submit=' + HttpEncode('\8f\91\82«\8d\9e\82Þ') + #13#10;
741         end;
742         Source.WriteString(s);
743 end;
744
745 procedure TEditorForm.SaveSendFile;
746 var
747         sDate: string;
748         ini: TMemIniFile;
749 begin
750         ini := TMemIniFile.Create(GikoSys.GetSentFileName);
751         try
752                 sDate := IntToStr(GikoSys.DateTimeToInt(Now));
753
754                 ini.WriteString(sDate, 'Name', NameComboBox.Text);
755                 ini.WriteString(sDate, 'EMail', MailComboBox.Text);
756                 ini.WriteString(sDate, 'Body', HttpEncode(BodyEdit.Text));
757                 ini.WriteInteger(sDate, 'Status', FStatusCode);
758                 ini.WriteDateTime(sDate, 'Date', Now);
759                 if FThreadItem = nil then begin
760                         ini.WriteString(sDate, 'Title', TitleEdit.Text);
761                         ini.WriteString(sDate, 'BBS', FBoard.BBSID);
762                         ini.WriteInteger(sDate, 'NewThread', 1);
763                 end else begin
764                         ini.WriteString(sDate, 'Title', FThreadItem.Title);
765                         ini.WriteString(sDate, 'BBS', FThreadItem.ParentBoard.BBSID);
766                         ini.WriteString(sDate, 'Key', ChangeFileExt(FThreadItem.FileName, ''));
767                 end;
768
769                 ini.UpdateFile;
770         finally
771                 ini.Free;
772         end;
773 end;
774
775 procedure TEditorForm.SendActionExecute(Sender: TObject);
776 var
777         Board: TBoard;
778         rc: Integer;
779 begin
780         if FWork then
781                 Exit;
782         try
783                 FWork := True;
784                 SendAction.Enabled := False;
785                 Application.ProcessMessages;
786                 if not Check then Exit;
787
788                 if FThreadItem = nil then
789                         Board := FBoard
790                 else
791                         Board := FThreadItem.ParentBoard;
792
793                 if FThreadItem = nil then begin
794                         rc := GikoUtil.MsgBox(Handle,
795                                                                                                         '\81u' + Board.Title + '\81v\94Â\82É\90V\82µ\82¢\83X\83\8c\83b\83h\97§\82Ä\82Ü\82·'#13#10#13#10
796                                                                                                         + '\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
797                                                                                                         + '\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
798                                                                                                         + '\81u\82Í\82¢\81v\82ð\89\9f\82·\82Æ\91\97\90M\82µ\82Ü\82·',
799                                                                                                         '\8am\94F',
800                                                                                                         MB_ICONQUESTION or MB_YESNO);
801                         if rc <> ID_YES then
802                                 Exit;
803                 end;
804
805                 SetNameList(NameComboBox.Text, MailComboBox.Text);
806                 if KotehanCheckBox.Checked then begin
807                         Board.KotehanName := NameComboBox.Text;
808                         Board.KotehanMail := MailComboBox.Text;
809                 end;
810                 Send(Board.SPID, Board.PON, True);
811         finally
812                 FWork := False;
813         end;
814 end;
815
816 procedure TEditorForm.SaveActionExecute(Sender: TObject);
817 begin
818 //
819 end;
820
821 procedure TEditorForm.CloseActionExecute(Sender: TObject);
822 begin
823         Close;
824 end;
825
826 procedure TEditorForm.UndoActionExecute(Sender: TObject);
827 begin
828         SendMessage(GetActiveControlHandle, WM_UNDO, 0, 0);
829 end;
830
831 procedure TEditorForm.CutActionExecute(Sender: TObject);
832 begin
833         SendMessage(GetActiveControlHandle, WM_CUT, 0, 0);
834 end;
835
836 procedure TEditorForm.CopyActionExecute(Sender: TObject);
837 begin
838         SendMessage(GetActiveControlHandle, WM_COPY, 0, 0);
839 end;
840
841 procedure TEditorForm.PasteActionExecute(Sender: TObject);
842 begin
843         SendMessage(GetActiveControlHandle, WM_PASTE, 0, 0);
844 end;
845
846 procedure TEditorForm.SelectAllActionExecute(Sender: TObject);
847 begin
848         SendMessage(GetActiveControlHandle, EM_SETSEL, 0, GetWindowTextLength(GetActiveControlHandle));
849 end;
850
851 procedure TEditorForm.TopActionExecute(Sender: TObject);
852 begin
853         if TopAction.Checked then
854                 FormStyle := fsStayOnTop
855         else
856                 FormStyle := fsNormal;
857 end;
858
859 procedure TEditorForm.AbortActionExecute(Sender: TObject);
860 begin
861         FAbort := True;
862 end;
863
864 procedure TEditorForm.SendActionUpdate(Sender: TObject);
865 begin
866         SendAction.Enabled := not FWork;
867 end;
868
869 procedure TEditorForm.SaveActionUpdate(Sender: TObject);
870 begin
871         SaveAction.Enabled := False;
872 end;
873
874 procedure TEditorForm.CloseActionUpdate(Sender: TObject);
875 begin
876         SendAction.Enabled := not FWork;
877 end;
878
879 procedure TEditorForm.UndoActionUpdate(Sender: TObject);
880 begin
881         UndoAction.Enabled := (GetActiveControlHandle <> 0)
882                                                                                                 and (SendMessage(GetActiveControlHandle, EM_CANUNDO, 0, 0) <> 0)
883                                                                                                 and (not FWork);
884 end;
885
886 procedure TEditorForm.CutActionUpdate(Sender: TObject);
887 var
888         Selection: TSelection;
889         AHandle: THandle;
890 begin
891         AHandle := GetActiveControlHandle;
892         SendMessage(AHandle, EM_GETSEL, Longint(@Selection.StartPos), Longint(@Selection.EndPos));
893         CutAction.Enabled := (AHandle <> 0)
894                                                                                 and ((Selection.EndPos - Selection.StartPos) <> 0)
895                                                                                 and (not FWork);
896 end;
897
898 procedure TEditorForm.CopyActionUpdate(Sender: TObject);
899 var
900         Selection: TSelection;
901         AHandle: THandle;
902 begin
903         AHandle := GetActiveControlHandle;
904         SendMessage(AHandle, EM_GETSEL, Longint(@Selection.StartPos), Longint(@Selection.EndPos));
905         CopyAction.Enabled := (AHandle <> 0)
906                                                                                 and ((Selection.EndPos - Selection.StartPos) <> 0)
907                                                                                 and (not FWork);
908 end;
909
910 procedure TEditorForm.PasteActionUpdate(Sender: TObject);
911 begin
912         PasteAction.Enabled := (GetActiveControlHandle <> 0)
913                                                                                         and (Clipboard.HasFormat(CF_TEXT))
914                                                                                         and (not FWork);
915 end;
916
917 procedure TEditorForm.TopActionUpdate(Sender: TObject);
918 begin
919         TopAction.Enabled := not FWork;
920 end;
921
922 procedure TEditorForm.SageCheckBoxClick(Sender: TObject);
923 begin
924         if SageCheckBox.Checked then begin
925                 if AnsiPos('sage', MailComboBox.Text) = 0 then
926                         MailComboBox.Text := 'sage' + MailComboBox.Text;
927         end else begin
928                 if AnsiPos('sage', MailComboBox.Text) <> 0 then
929                         MailComboBox.Text := StringReplace(MailComboBox.Text, 'sage', '', [rfReplaceAll]);
930         end;
931 end;
932
933 procedure TEditorForm.MailComboBoxChange(Sender: TObject);
934 begin
935         if AnsiPos('sage', MailComboBox.Text) = 0 then
936                 SageCheckBox.Checked := False
937         else
938                 SageCheckBox.Checked := True;
939 end;
940
941
942 function TEditorForm.GetSPID(CookieLine: string): string;
943 var
944         s: string;
945         i: Integer;
946 begin
947         Result := '';
948         i := 0;
949         while True do begin
950                 s := Trim(GikoSys.GetTokenIndex(CookieLine, ';', i));
951                 if s = '' then
952                         Break
953                 else begin
954                         if Pos('SPID=', s) = 1 then begin
955                                 Result := Trim(Copy(s, 6, Length(s)));
956                                 Break;
957                         end;
958                 end;
959                 inc(i);
960         end;
961 end;
962
963 function TEditorForm.GetPON(CookieLine: string): string;
964 var
965         s: string;
966         i: Integer;
967 begin
968         Result := '';
969         i := 0;
970         while True do begin
971                 s := Trim(GikoSys.GetTokenIndex(CookieLine, ';', i));
972                 if s = '' then
973                         Break
974                 else begin
975                         if Pos('PON=', s) = 1 then begin
976                                 Result := Trim(Copy(s, 5, Length(s)));
977                                 Break;
978                         end;
979                 end;
980                 inc(i);
981         end;
982 end;
983
984 procedure TEditorForm.IdLogDebugReceive(ASender: TIdConnectionIntercept;
985         AStream: TStream);
986 var
987         StringStream: TStringStream;
988 begin
989         StringStream := TStringStream.Create('');
990         try
991                 StringStream.CopyFrom(AStream, AStream.Size);
992                 FDebugStrReceive := FDebugStrReceive + StringStream.DataString;
993         finally
994                 StringStream.Free;
995         end;
996 end;
997
998 procedure TEditorForm.IdLogDebugSend(ASender: TIdConnectionIntercept;
999         AStream: TStream);
1000 var
1001         StringStream: TStringStream;
1002 begin
1003         StringStream := TStringStream.Create('');
1004         try
1005                 StringStream.CopyFrom(AStream, AStream.Size);
1006                 FDebugStrSend := FDebugStrSend + StringStream.DataString;
1007         finally
1008                 StringStream.Free;
1009         end;
1010 end;
1011
1012 procedure TEditorForm.TransActionExecute(Sender: TObject);
1013 begin
1014         AlphaBlend := TransAction.Checked;
1015 end;
1016
1017 procedure TEditorForm.TransActionUpdate(Sender: TObject);
1018 begin
1019         TransAction.Enabled := not FWork;
1020 end;
1021
1022 end.
1023