1;;; gnuspost.el --- post news commands for GNUS newsreader 2 3;; Copyright (C) 1989, 1990, 1993, 1994 Free Software Foundation, Inc. 4 5;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet> 6;; Keywords: news 7 8;; This file is part of GNU Emacs. 9 10;; GNU Emacs is free software; you can redistribute it and/or modify 11;; it under the terms of the GNU General Public License as published by 12;; the Free Software Foundation; either version 2, or (at your option) 13;; any later version. 14 15;; GNU Emacs is distributed in the hope that it will be useful, 16;; but WITHOUT ANY WARRANTY; without even the implied warranty of 17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18;; GNU General Public License for more details. 19 20;; You should have received a copy of the GNU General Public License 21;; along with GNU Emacs; see the file COPYING. If not, write to 22;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 23 24;;; Code: 25 26(require 'gnus) 27 28(defvar gnus-organization-file "/usr/lib/news/organization" 29 "*Local news organization file.") 30 31(defvar gnus-post-news-buffer "*post-news*") 32(defvar gnus-winconf-post-news nil) 33 34(autoload 'news-reply-mode "rnewspost") 35(autoload 'timezone-make-date-arpa-standard "timezone") 36 37;;; Post news commands of GNUS Group Mode and Summary Mode 38 39(defun gnus-group-post-news () 40 "Post an article." 41 (interactive) 42 ;; Save window configuration. 43 (setq gnus-winconf-post-news (current-window-configuration)) 44 (unwind-protect 45 (gnus-post-news) 46 (or (and (eq (current-buffer) (get-buffer gnus-post-news-buffer)) 47 (not (zerop (buffer-size)))) 48 ;; Restore last window configuration. 49 (set-window-configuration gnus-winconf-post-news))) 50 ;; We don't want to return to Summary buffer nor Article buffer later. 51 (if (get-buffer gnus-summary-buffer) 52 (bury-buffer gnus-summary-buffer)) 53 (if (get-buffer gnus-article-buffer) 54 (bury-buffer gnus-article-buffer))) 55 56(defun gnus-summary-post-news () 57 "Post an article." 58 (interactive) 59 (gnus-summary-select-article t nil) 60 ;; Save window configuration. 61 (setq gnus-winconf-post-news (current-window-configuration)) 62 (unwind-protect 63 (progn 64 (switch-to-buffer gnus-article-buffer) 65 (widen) 66 (delete-other-windows) 67 (gnus-post-news)) 68 (or (and (eq (current-buffer) (get-buffer gnus-post-news-buffer)) 69 (not (zerop (buffer-size)))) 70 ;; Restore last window configuration. 71 (set-window-configuration gnus-winconf-post-news))) 72 ;; We don't want to return to Article buffer later. 73 (bury-buffer gnus-article-buffer)) 74 75(defun gnus-summary-followup (yank) 76 "Post a reply article. 77If prefix argument YANK is non-nil, original article is yanked automatically." 78 (interactive "P") 79 (gnus-summary-select-article t nil) 80 ;; Check Followup-To: poster. 81 (set-buffer gnus-article-buffer) 82 (if (and gnus-use-followup-to 83 (string-equal "poster" (gnus-fetch-field "followup-to")) 84 (or (not (eq gnus-use-followup-to t)) 85 (not (y-or-n-p "Do you want to ignore `Followup-To: poster'? ")))) 86 ;; Mail to the poster. GNUS is now RFC1036 compliant. 87 (gnus-summary-reply yank) 88 ;; Save window configuration. 89 (setq gnus-winconf-post-news (current-window-configuration)) 90 (unwind-protect 91 (progn 92 (switch-to-buffer gnus-article-buffer) 93 (widen) 94 (delete-other-windows) 95 (gnus-news-reply yank)) 96 (or (and (eq (current-buffer) (get-buffer gnus-post-news-buffer)) 97 (not (zerop (buffer-size)))) 98 ;; Restore last window configuration. 99 (set-window-configuration gnus-winconf-post-news))) 100 ;; We don't want to return to Article buffer later. 101 (bury-buffer gnus-article-buffer))) 102 103(defun gnus-summary-followup-with-original () 104 "Post a reply article with original article." 105 (interactive) 106 (gnus-summary-followup t)) 107 108(defun gnus-summary-cancel-article () 109 "Cancel an article you posted." 110 (interactive) 111 (gnus-summary-select-article t nil) 112 (gnus-eval-in-buffer-window gnus-article-buffer 113 (gnus-cancel-news))) 114 115 116;;; Post a News using NNTP 117 118;;;###autoload 119(fset 'sendnews 'gnus-post-news) 120 121;;;###autoload 122(fset 'postnews 'gnus-post-news) 123 124;;;###autoload 125(defun gnus-post-news () 126 "Begin editing a new USENET news article to be posted. 127Type \\[describe-mode] once editing the article to get a list of commands." 128 (interactive) 129 (if (or (not gnus-novice-user) 130 (y-or-n-p "Are you sure you want to post to all of USENET? ")) 131 (let ((artbuf (current-buffer)) 132 (newsgroups ;Default newsgroup. 133 (if (eq major-mode 'gnus-article-mode) gnus-newsgroup-name)) 134 (subject nil) 135 ;; Get default distribution. 136 (distribution (car gnus-local-distributions)) 137 (followup-to nil)) 138 ;; Connect to NNTP server if not connected yet, and get 139 ;; several information. 140 (if (not (gnus-server-opened)) 141 (progn 142 (gnus-start-news-server t) ;Confirm server. 143 (gnus-setup-news))) 144 ;; Get current article information. 145 (save-restriction 146 (and (not (zerop (buffer-size))) 147 ;;(equal major-mode 'news-mode) 148 (equal major-mode 'gnus-article-mode) 149 (progn 150 ;;(news-show-all-headers) 151 (gnus-article-show-all-headers) 152 (narrow-to-region (point-min) 153 (progn (goto-char (point-min)) 154 (search-forward "\n\n") 155 (point))))) 156 (setq news-reply-yank-from (mail-fetch-field "from")) 157 (setq news-reply-yank-message-id (mail-fetch-field "message-id"))) 158 (pop-to-buffer gnus-post-news-buffer) 159 (news-reply-mode) 160 (gnus-overload-functions) 161 (if (and (buffer-modified-p) 162 (> (buffer-size) 0) 163 (not (y-or-n-p "Unsent article being composed; erase it? "))) 164 ;; Continue composition. 165 ;; Make news-reply-yank-original work on the current article. 166 (setq mail-reply-buffer artbuf) 167 (erase-buffer) 168 (if gnus-interactive-post 169 ;; Newsgroups, subject and distribution are asked for. 170 ;; Suggested by yuki@flab.fujitsu.junet. 171 (progn 172 ;; Subscribed newsgroup names are required for 173 ;; completing read of newsgroup. 174 (or gnus-newsrc-assoc 175 (gnus-read-newsrc-file)) 176 ;; Which do you like? (UMERIN) 177 ;; (setq newsgroups (read-string "Newsgroups: " "general")) 178 (or newsgroups ;Use the default newsgroup. 179 (let (group) 180 (while (not 181 (string= 182 (setq group 183 (completing-read "Newsgroup: " 184 gnus-newsrc-assoc 185 nil 'require-match)) 186 "")) 187 (or followup-to (setq followup-to group)) 188 (if newsgroups 189 (setq newsgroups (concat newsgroups "," group)) 190 (setq newsgroups group))))) 191 (setq subject (read-string "Subject: ")) 192 ;; Choose a distribution from gnus-distribution-list. 193 ;; completing-read should not be used with 194 ;; 'require-match functionality in order to allow use 195 ;; of unknow distribution. 196 (gnus-read-distributions-file) 197 (setq distribution 198 (if (consp gnus-distribution-list) 199 (completing-read "Distribution: " 200 gnus-distribution-list 201 nil nil ;Never 'require-match 202 distribution ;Default distribution. 203 ) 204 (read-string "Distribution: "))) 205 ;; Empty string is okay. 206 ;;(if (string-equal distribution "") 207 ;; (setq distribution nil)) 208 )) 209 (news-setup () subject () newsgroups artbuf) 210 ;; Make sure the article is posted by GNUS. 211 ;;(mail-position-on-field "Posting-Software") 212 ;;(insert "GNUS: NNTP-based News Reader for GNU Emacs") 213 ;; Insert Distribution: field. 214 ;; Suggested by ichikawa@flab.fujitsu.junet. 215 (mail-position-on-field "Distribution") 216 (insert (or distribution "")) 217 ;; Add Followup-To header 218 (if followup-to 219 (progn 220 (mail-position-on-field "Followup-To") 221 (insert followup-to))) 222 ;; Handle author copy using FCC field. 223 (if gnus-author-copy 224 (progn 225 (mail-position-on-field "FCC") 226 (insert gnus-author-copy))) 227 (if gnus-interactive-post 228 ;; All fields are filled in. 229 (goto-char (point-max)) 230 ;; Move point to Newsgroup: field. 231 (goto-char (point-min)) 232 (end-of-line)) 233 )) 234 (message ""))) 235 236(defun gnus-news-reply (&optional yank) 237 "Compose and post a reply (aka a followup) to the current article on USENET. 238While composing the followup, use \\[news-reply-yank-original] to yank the 239original message into it." 240 (interactive) 241 (if (or (not gnus-novice-user) 242 (y-or-n-p "Are you sure you want to followup to all of USENET? ")) 243 (let (from cc subject date to followup-to newsgroups message-of 244 references distribution message-id 245 (artbuf (current-buffer))) 246 (save-restriction 247 (and (not (zerop (buffer-size))) 248 ;;(equal major-mode 'news-mode) 249 (equal major-mode 'gnus-article-mode) 250 (progn 251 ;; (news-show-all-headers) 252 (gnus-article-show-all-headers) 253 (narrow-to-region (point-min) 254 (progn (goto-char (point-min)) 255 (search-forward "\n\n") 256 (point))))) 257 (setq from (mail-fetch-field "from")) 258 ;; Get reply-to working corrrectly for gnus-auto-mail-to-author (jpm) 259 (setq reply-to (mail-fetch-field "reply-to")) 260 (setq news-reply-yank-from from) 261 (setq subject (mail-fetch-field "subject")) 262 (setq date (mail-fetch-field "date")) 263 (setq followup-to (mail-fetch-field "followup-to")) 264 ;; Ignore Followup-To: poster. 265 (if (or (null gnus-use-followup-to) ;Ignore followup-to: field. 266 (string-equal "" followup-to) ;Bogus header. 267 (string-equal "poster" followup-to)) 268 (setq followup-to nil)) 269 (setq newsgroups (or followup-to (mail-fetch-field "newsgroups"))) 270 (setq references (mail-fetch-field "references")) 271 (setq distribution (mail-fetch-field "distribution")) 272 (setq message-id (mail-fetch-field "message-id")) 273 (setq news-reply-yank-message-id message-id)) 274 (pop-to-buffer gnus-post-news-buffer) 275 (news-reply-mode) 276 (gnus-overload-functions) 277 (if (and (buffer-modified-p) 278 (> (buffer-size) 0) 279 (not (y-or-n-p "Unsent article being composed; erase it? "))) 280 ;; Continue composition. 281 ;; Make news-reply-yank-original work on current article. 282 (setq mail-reply-buffer artbuf) 283 (erase-buffer) 284 (and subject 285 (setq subject 286 (concat "Re: " (gnus-simplify-subject subject 're-only)))) 287 (and from 288 (progn 289 (let ((stop-pos 290 (string-match " *at \\| *@ \\| *(\\| *<" from))) 291 (setq message-of 292 (concat 293 (if stop-pos (substring from 0 stop-pos) from) 294 "'s message of " 295 date))))) 296 (news-setup nil subject message-of newsgroups artbuf) 297 (if followup-to 298 (progn (news-reply-followup-to) 299 (insert followup-to))) 300 ;; Fold long references line to follow RFC1036. 301 (mail-position-on-field "References") 302 (let ((begin (point)) 303 (fill-column 79) 304 (fill-prefix "\t")) 305 (if references 306 (insert references)) 307 (if (and references message-id) 308 (insert " ")) 309 (if message-id 310 (insert message-id)) 311 ;; The region must end with a newline to fill the region 312 ;; without inserting extra newline. 313 (fill-region-as-paragraph begin (1+ (point)))) 314 ;; Make sure the article is posted by GNUS. 315 ;;(mail-position-on-field "Posting-Software") 316 ;;(insert "GNUS: NNTP-based News Reader for GNU Emacs") 317 ;; Distribution must be the same as original article. 318 (mail-position-on-field "Distribution") 319 (insert (or distribution "")) 320 ;; Handle author copy using FCC field. 321 (if gnus-author-copy 322 (progn 323 (mail-position-on-field "FCC") 324 (insert gnus-author-copy))) 325 ;; Insert To: FROM field, which is expected to mail the 326 ;; message to the author of the article too. Use Reply-To 327 ;; field like gnus-mail-reply-using-m* (jpm). 328 (if (and gnus-auto-mail-to-author (or reply-to from)) 329 (progn 330 (goto-char (point-min)) 331 (insert "To: " (or reply-to from) "\n"))) 332 (goto-char (point-max))) 333 ;; Yank original article automatically. 334 (if yank 335 (let ((last (point))) 336 ;;(goto-char (point-max)) 337 ;; Insert at current point. 338 (news-reply-yank-original nil) 339 (goto-char last))) 340 ) 341 (message ""))) 342 343(defun gnus-inews-news () 344 "Send a news message." 345 (interactive) 346 (let* ((case-fold-search nil) 347 (server-running (gnus-server-opened))) 348 (save-excursion 349 ;; Connect to default NNTP server if necessary. 350 ;; Suggested by yuki@flab.fujitsu.junet. 351 (gnus-start-news-server) ;Use default server. 352 ;; NNTP server must be opened before current buffer is modified. 353 (widen) 354 (goto-char (point-min)) 355 (run-hooks 'news-inews-hook) 356 ;; Mail the message too if To: or Cc: exists. 357 (if (save-restriction 358 (narrow-to-region 359 (point-min) 360 (progn 361 (goto-char (point-min)) 362 (search-forward (concat "\n" mail-header-separator "\n")) 363 (point))) 364 (or (mail-fetch-field "to" nil t) 365 (mail-fetch-field "cc" nil t))) 366 (if gnus-mail-send-method 367 (progn 368 (message "Sending via mail...") 369 (funcall gnus-mail-send-method) 370 (message "Sending via mail... done")) 371 (ding) 372 (message "No mailer defined. To: and/or Cc: fields ignored.") 373 (sit-for 1))) 374 ;; Send to NNTP server. 375 (message "Posting to USENET...") 376 (if (gnus-inews-article) 377 (message "Posting to USENET... done") 378 ;; We cannot signal an error. 379 (ding) (message "Article rejected: %s" (gnus-status-message))) 380 (set-buffer-modified-p nil)) 381 ;; If NNTP server is opened by gnus-inews-news, close it by myself. 382 (or server-running 383 (gnus-close-server)) 384 (and (fboundp 'bury-buffer) (bury-buffer)) 385 ;; Restore last window configuration. 386 (and gnus-winconf-post-news 387 (set-window-configuration gnus-winconf-post-news)) 388 (setq gnus-winconf-post-news nil) 389 )) 390 391(defun gnus-cancel-news () 392 "Cancel an article you posted." 393 (interactive) 394 (if (yes-or-no-p "Do you really want to cancel this article? ") 395 (let ((from nil) 396 (newsgroups nil) 397 (message-id nil) 398 (distribution nil)) 399 (save-excursion 400 ;; Get header info. from original article. 401 (save-restriction 402 (gnus-article-show-all-headers) 403 (goto-char (point-min)) 404 (search-forward "\n\n" nil 'move) 405 (narrow-to-region (point-min) (point)) 406 (setq from (mail-fetch-field "from")) 407 (setq newsgroups (mail-fetch-field "newsgroups")) 408 (setq message-id (mail-fetch-field "message-id")) 409 (setq distribution (mail-fetch-field "distribution"))) 410 ;; Verify if the article is absolutely user's by comparing 411 ;; user id with value of its From: field. 412 (if (not 413 (string-equal 414 (downcase (mail-strip-quoted-names from)) 415 (downcase (mail-strip-quoted-names (gnus-inews-user-name))))) 416 (progn 417 (ding) (message "This article is not yours.")) 418 ;; Make control article. 419 (set-buffer (get-buffer-create " *GNUS-canceling*")) 420 (buffer-flush-undo (current-buffer)) 421 (erase-buffer) 422 (insert "Newsgroups: " newsgroups "\n" 423 "Subject: cancel " message-id "\n" 424 "Control: cancel " message-id "\n" 425 ;; We should not use the first value of 426 ;; `gnus-distribution-list' as default value, 427 ;; because distribution must be as same as original 428 ;; article. 429 "Distribution: " (or distribution "") "\n" 430 mail-header-separator "\n" 431 ) 432 ;; Send the control article to NNTP server. 433 (message "Canceling your article...") 434 (if (gnus-inews-article) 435 (message "Canceling your article... done") 436 (ding) (message "Failed to cancel your article")) 437 ;; Kill the article buffer. 438 (kill-buffer (current-buffer)) 439 ))) 440 )) 441 442 443;;; Lowlevel inews interface 444 445(defun gnus-inews-article () 446 "Post an article in current buffer using NNTP protocol." 447 (let ((artbuf (current-buffer)) 448 (tmpbuf (get-buffer-create " *GNUS-posting*"))) 449 (save-excursion 450 (set-buffer tmpbuf) 451 (buffer-flush-undo (current-buffer)) 452 (erase-buffer) 453 (insert-buffer-substring artbuf) 454 ;; Remove the header separator. 455 (goto-char (point-min)) 456 (search-forward (concat "\n" mail-header-separator "\n")) 457 (replace-match "\n\n") 458 (goto-char (point-max)) 459 ;; require a newline at the end for inews to append .signature to 460 (or (= (preceding-char) ?\n) 461 (insert ?\n)) 462 ;; This hook may insert a signature. 463 (run-hooks 'gnus-prepare-article-hook) 464 ;; Prepare article headers. All message body such as signature 465 ;; must be inserted before Lines: field is prepared. 466 (save-restriction 467 (goto-char (point-min)) 468 (search-forward "\n\n") 469 (narrow-to-region (point-min) (point)) 470 (gnus-inews-insert-headers)) 471 ;; Run final inews hooks. This hook may do FCC. 472 ;; The article must be saved before being posted because 473 ;; `gnus-request-post' modifies the buffer. 474 (run-hooks 'gnus-inews-article-hook) 475 ;; Post an article to NNTP server. 476 ;; Return NIL if post failed. 477 (prog1 478 (gnus-request-post) 479 (kill-buffer (current-buffer))) 480 ))) 481 482(defun gnus-inews-insert-headers () 483 "Prepare article headers. 484Fields already prepared in the buffer are not modified. 485Fields in gnus-required-headers will be generated." 486 (save-excursion 487 (let ((date (gnus-inews-date)) 488 (message-id (gnus-inews-message-id)) 489 (organization (gnus-inews-organization))) 490 (goto-char (point-min)) 491 (or (mail-fetch-field "path") 492 (and (memq 'Path gnus-required-headers) 493 (insert "Path: " (gnus-inews-path) "\n"))) 494 (or (mail-fetch-field "from") 495 (and (memq 'From gnus-required-headers) 496 (insert "From: " (gnus-inews-user-name) "\n"))) 497 ;; If there is no subject, make Subject: field. 498 (or (mail-fetch-field "subject") 499 (and (memq 'Subject gnus-required-headers) 500 (insert "Subject: \n"))) 501 ;; If there is no newsgroups, make Newsgroups: field. 502 (or (mail-fetch-field "newsgroups") 503 (and (memq 'Newsgroups gnus-required-headers) 504 (insert "Newsgroups: \n"))) 505 (or (mail-fetch-field "message-id") 506 (and message-id 507 (memq 'Message-ID gnus-required-headers) 508 (insert "Message-ID: " message-id "\n"))) 509 (or (mail-fetch-field "date") 510 (and date 511 (memq 'Date gnus-required-headers) 512 (insert "Date: " date "\n"))) 513 ;; Optional fields in RFC977 and RFC1036 514 (or (mail-fetch-field "organization") 515 (and organization 516 (memq 'Organization gnus-required-headers) 517 (let ((begin (point)) 518 (fill-column 79) 519 (fill-prefix "\t")) 520 (insert "Organization: " organization "\n") 521 (fill-region-as-paragraph begin (point))))) 522 (or (mail-fetch-field "distribution") 523 (and (memq 'Distribution gnus-required-headers) 524 (insert "Distribution: \n"))) 525 (or (mail-fetch-field "lines") 526 (and (memq 'Lines gnus-required-headers) 527 (insert "Lines: " (gnus-inews-lines) "\n"))) 528 ))) 529 530 531;; Utility functions. 532 533(defun gnus-inews-insert-signature () 534 "Insert signature file in current article buffer. 535If there is a file named .signature-DISTRIBUTION, it is used instead 536of usual .signature when the distribution of the article is 537DISTRIBUTION. Set the variable to nil to prevent appending the 538signature file automatically. 539Signature file is specified by the variable gnus-signature-file." 540 (save-excursion 541 (save-restriction 542 ;; Change signature file by distribution. 543 ;; Suggested by hyoko@flab.fujitsu.co.jp. 544 (let ((signature 545 (if gnus-signature-file 546 (expand-file-name gnus-signature-file nil))) 547 (distribution nil)) 548 (goto-char (point-min)) 549 (search-forward "\n\n") 550 (narrow-to-region (point-min) (point)) 551 (setq distribution (mail-fetch-field "distribution")) 552 (widen) 553 (if signature 554 (progn 555 (if (file-exists-p (concat signature "-" distribution)) 556 (setq signature (concat signature "-" distribution))) 557 ;; Insert signature. 558 (if (file-exists-p signature) 559 (progn 560 (goto-char (point-max)) 561 (insert "--\n") 562 (insert-file-contents signature))) 563 )))))) 564 565(defun gnus-inews-do-fcc () 566 "Process FCC: fields in current article buffer. 567Unless the first character of the field is `|', the article is saved 568to the specified file using the function specified by the variable 569gnus-author-copy-saver. The default function rmail-output saves in 570Unix mailbox format. 571If the first character is `|', the contents of the article is send to 572a program specified by the rest of the value." 573 (let ((fcc-list nil) 574 (fcc-file nil) 575 (case-fold-search t)) ;Should ignore case. 576 (save-excursion 577 (save-restriction 578 (goto-char (point-min)) 579 (search-forward "\n\n") 580 (narrow-to-region (point-min) (point)) 581 (goto-char (point-min)) 582 (while (re-search-forward "^FCC:[ \t]*" nil t) 583 (setq fcc-list 584 (cons (buffer-substring 585 (point) 586 (progn 587 (end-of-line) 588 (skip-chars-backward " \t") 589 (point))) 590 fcc-list)) 591 (delete-region (match-beginning 0) 592 (progn (forward-line 1) (point)))) 593 ;; Process FCC operations. 594 (widen) 595 (while fcc-list 596 (setq fcc-file (car fcc-list)) 597 (setq fcc-list (cdr fcc-list)) 598 (cond ((string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" fcc-file) 599 (let ((program (substring fcc-file 600 (match-beginning 1) (match-end 1)))) 601 ;; Suggested by yuki@flab.fujitsu.junet. 602 ;; Send article to named program. 603 (call-process-region (point-min) (point-max) shell-file-name 604 nil nil nil "-c" program) 605 )) 606 (t 607 ;; Suggested by hyoko@flab.fujitsu.junet. 608 ;; Save article in Unix mail format by default. 609 (if (and gnus-author-copy-saver 610 (not (eq gnus-author-copy-saver 'rmail-output))) 611 (funcall gnus-author-copy-saver fcc-file) 612 (if (and (file-readable-p fcc-file) (rmail-file-p fcc-file)) 613 (gnus-output-to-rmail fcc-file) 614 (rmail-output fcc-file 1 t t))) 615 )) 616 ) 617 )) 618 )) 619 620(defun gnus-inews-path () 621 "Return uucp path." 622 (let ((login-name (gnus-inews-login-name))) 623 (cond ((null gnus-use-generic-path) 624 (concat gnus-nntp-server "!" login-name)) 625 ((stringp gnus-use-generic-path) 626 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com. 627 (concat gnus-use-generic-path "!" login-name)) 628 (t login-name)) 629 )) 630 631(defun gnus-inews-user-name () 632 "Return user's network address as `NAME@DOMAIN (FULL NAME)'." 633 (let ((login-name (gnus-inews-login-name)) 634 (full-name (gnus-inews-full-name))) 635 (concat login-name "@" (gnus-inews-domain-name gnus-use-generic-from) 636 ;; User's full name. 637 (cond ((string-equal full-name "") "") 638 ((string-equal full-name "&") ;Unix hack. 639 (concat " (" login-name ")")) 640 (t 641 (concat " (" full-name ")"))) 642 ))) 643 644(defun gnus-inews-login-name () 645 "Return user login name. 646Got from the variable `gnus-user-login-name' and the function 647`user-login-name'." 648 (or gnus-user-login-name (user-login-name))) 649 650(defun gnus-inews-full-name () 651 "Return user full name. 652Got from the variable gnus-user-full-name, the environment variable 653NAME, and the function user-full-name." 654 (or gnus-user-full-name 655 (getenv "NAME") (user-full-name))) 656 657(defun gnus-inews-domain-name (&optional genericfrom) 658 "Return user's domain name. 659If optional argument GENERICFROM is a string, use it as the domain 660name; if it is non-nil, strip of local host name from the domain name. 661If the function `system-name' returns full internet name and the 662domain is undefined, the domain name is got from it." 663 ;; Note: compatibility hack. This will be removed in the next version. 664 (and (null gnus-local-domain) 665 (boundp 'gnus-your-domain) 666 (setq gnus-local-domain gnus-your-domain)) 667 ;; End of compatibility hack. 668 (let ((domain (or (if (stringp genericfrom) genericfrom) 669 (getenv "DOMAINNAME") 670 gnus-local-domain 671 ;; Function `system-name' may return full internet name. 672 ;; Suggested by Mike DeCorte <mrd@sun.soe.clarkson.edu>. 673 (if (string-match "\\." (system-name)) 674 (substring (system-name) (match-end 0))) 675 (read-string "Domain name (no host): "))) 676 (host (or (if (string-match "\\." (system-name)) 677 (substring (system-name) 0 (match-beginning 0))) 678 (system-name)))) 679 (if (string-equal "." (substring domain 0 1)) 680 (setq domain (substring domain 1))) 681 (if (null gnus-local-domain) 682 (setq gnus-local-domain domain)) 683 ;; Support GENERICFROM as same as standard Bnews system. 684 ;; Suggested by ohm@kaba.junet and vixie@decwrl.dec.com. 685 (cond ((null genericfrom) 686 (concat host "." domain)) 687 ;;((stringp genericfrom) genericfrom) 688 (t domain)) 689 )) 690 691(defun gnus-inews-message-id () 692 "Generate unique Message-ID for user." 693 ;; Message-ID should not contain a slash and should be terminated by 694 ;; a number. I don't know the reason why it is so. 695 (concat "<" (gnus-inews-unique-id) "@" (gnus-inews-domain-name) ">")) 696 697(defun gnus-inews-unique-id () 698 "Generate unique ID from user name and current time." 699 (let ((date (current-time-string)) 700 (name (gnus-inews-login-name))) 701 (if (string-match "^[^ ]+ \\([^ ]+\\)[ ]+\\([0-9]+\\) \\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\) [0-9][0-9]\\([0-9][0-9]\\)" 702 date) 703 (concat (upcase name) "." 704 (substring date (match-beginning 6) (match-end 6)) ;Year 705 (substring date (match-beginning 1) (match-end 1)) ;Month 706 (substring date (match-beginning 2) (match-end 2)) ;Day 707 (substring date (match-beginning 3) (match-end 3)) ;Hour 708 (substring date (match-beginning 4) (match-end 4)) ;Minute 709 (substring date (match-beginning 5) (match-end 5)) ;Second 710 ) 711 (error "Cannot understand current-time-string: %s." date)) 712 )) 713 714(defun gnus-current-time-zone (time) 715 "The local time zone in effect at TIME, or nil if not known." 716 (let ((z (and (fboundp 'current-time-zone) (current-time-zone time)))) 717 (if (and z (car z)) z gnus-local-timezone))) 718 719(defun gnus-inews-date () 720 "Date string of today. 721If `current-time-zone' works, or if `gnus-local-timezone' is set correctly, 722this yields a date that conforms to RFC 822. Otherwise a buggy date will 723be generated; this might work with some older news servers." 724 (let* ((now (and (fboundp 'current-time) (current-time))) 725 (zone (gnus-current-time-zone now))) 726 (if zone 727 (gnus-inews-valid-date now zone) 728 ;; No timezone info. 729 (gnus-inews-buggy-date now)))) 730 731(defun gnus-inews-valid-date (&optional time zone) 732 "A date string that represents TIME and conforms to the Usenet standard. 733TIME is optional and defaults to the current time. 734Some older versions of Emacs always act as if TIME is nil. 735The optional argument ZONE specifies the local time zone (default GMT)." 736 (timezone-make-date-arpa-standard 737 (if (fboundp 'current-time) 738 (current-time-string time) 739 (current-time-string)) 740 zone "GMT")) 741 742(defun gnus-inews-buggy-date (&optional time) 743 "A buggy date string that represents TIME. 744TIME is optional and defaults to the current time. 745Some older versions of Emacs always act as if TIME is nil." 746 (let ((date (if (fboundp 'current-time) 747 (current-time-string time) 748 (current-time-string)))) 749 (if (string-match "^[^ ]+ \\([^ ]+\\)[ ]+\\([0-9]+\\) \\([0-9:]+\\) [0-9][0-9]\\([0-9][0-9]\\)" 750 date) 751 (concat (substring date (match-beginning 2) (match-end 2)) ;Day 752 " " 753 (substring date (match-beginning 1) (match-end 1)) ;Month 754 " " 755 (substring date (match-beginning 4) (match-end 4)) ;Year 756 " " 757 (substring date (match-beginning 3) (match-end 3))) ;Time 758 (error "Cannot understand current-time-string: %s." date)) 759 )) 760 761(defun gnus-inews-organization () 762 "Return user's organization. 763The ORGANIZATION environment variable is used if defined. 764If not, the variable gnus-local-organization is used instead. 765If the value begins with a slash, it is taken as the name of a file 766containing the organization." 767 ;; The organization must be got in this order since the ORGANIZATION 768 ;; environment variable is intended for user specific while 769 ;; gnus-local-organization is for machine or organization specific. 770 771 ;; Note: compatibility hack. This will be removed in the next version. 772 (and (null gnus-local-organization) 773 (boundp 'gnus-your-organization) 774 (setq gnus-local-organization gnus-your-organization)) 775 ;; End of compatibility hack. 776 (let* ((private-file (expand-file-name "~/.organization" nil)) 777 (organization (or (getenv "ORGANIZATION") 778 gnus-local-organization 779 private-file))) 780 (and (stringp organization) 781 (> (length organization) 0) 782 (string-equal (substring organization 0 1) "/") 783 ;; Get it from the user and system file. 784 ;; Suggested by roland@wheaties.ai.mit.edu (Roland McGrath). 785 (let ((dist (mail-fetch-field "distribution"))) 786 (setq organization 787 (cond ((file-exists-p (concat organization "-" dist)) 788 (concat organization "-" dist)) 789 ((file-exists-p organization) organization) 790 ((file-exists-p gnus-organization-file) 791 gnus-organization-file) 792 (t organization))) 793 )) 794 (cond ((not (stringp organization)) nil) 795 ((and (string-equal (substring organization 0 1) "/") 796 (file-exists-p organization)) 797 ;; If the first character is `/', assume it is the name of 798 ;; a file containing the organization. 799 (save-excursion 800 (let ((tmpbuf (get-buffer-create " *GNUS organization*"))) 801 (set-buffer tmpbuf) 802 (erase-buffer) 803 (insert-file-contents organization) 804 (prog1 (buffer-string) 805 (kill-buffer tmpbuf)) 806 ))) 807 ((string-equal organization private-file) nil) ;No such file 808 (t organization)) 809 )) 810 811(defun gnus-inews-lines () 812 "Count the number of lines and return numeric string." 813 (save-excursion 814 (save-restriction 815 (widen) 816 (goto-char (point-min)) 817 (search-forward "\n\n" nil 'move) 818 (int-to-string (count-lines (point) (point-max)))))) 819 820(provide 'gnuspost) 821 822;;; gnuspost.el ends here 823