OSDN Git Service

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