]> git.pld-linux.org Git - packages/mutt.git/blob - mutt-vvv.nntp.patch
- merged from DEVEL
[packages/mutt.git] / mutt-vvv.nntp.patch
1 WARNING: Run the following script before configure:
2
3 aclocal -I m4
4 autoheader
5 automake --foreign
6 autoconf
7
8 -- 
9 Vsevolod Volkov <vvv@mutt.org.ua>
10
11
12 diff -udprP mutt-1.5.13.orig/ChangeLog.nntp mutt-1.5.13/ChangeLog.nntp
13 --- mutt-1.5.13.orig/ChangeLog.nntp     1970-01-01 03:00:00.000000000 +0300
14 +++ mutt-1.5.13/ChangeLog.nntp  2006-08-15 13:12:32.000000000 +0300
15 @@ -0,0 +1,332 @@
16 +* Tue Aug 15 2006 Vsevolod Volkov <vvv@mutt.org.ua>
17 +- update to 1.5.13
18 +
19 +* Mon Jul 17 2006 Vsevolod Volkov <vvv@mutt.org.ua>
20 +- update to 1.5.12
21 +- fixed reading empty .newsrc
22 +
23 +* Sat Sep 17 2005 Vsevolod Volkov <vvv@mutt.org.ua>
24 +- update to 1.5.11
25 +
26 +* Sat Aug 13 2005 Vsevolod Volkov <vvv@mutt.org.ua>
27 +- update to 1.5.10
28 +
29 +* Sun Mar 13 2005 Vsevolod Volkov <vvv@mutt.org.ua>
30 +- update to 1.5.9
31 +
32 +* Sun Feb 13 2005 Vsevolod Volkov <vvv@mutt.org.ua>
33 +- update to 1.5.8
34 +
35 +* Sat Feb  5 2005 Vsevolod Volkov <vvv@mutt.org.ua>
36 +- update to 1.5.7
37 +- function mutt_update_list_file() moved to newsrc.c and changed algorithm
38 +
39 +* Thu Jul  8 2004 Vsevolod Volkov <vvv@mutt.org.ua>
40 +- fixed error in nntp_logout_all()
41 +
42 +* Sat Apr  3 2004 Vsevolod Volkov <vvv@mutt.org.ua>
43 +- fixed debug output in mutt_newsrc_update()
44 +- added optional support of LISTGROUP command
45 +- fixed typo in nntp_parse_xref()
46 +
47 +* Tue Feb  3 2004 Vsevolod Volkov <vvv@mutt.org.ua>
48 +- update to 1.5.6
49 +
50 +* Thu Dec 18 2003 Vsevolod Volkov <vvv@mutt.org.ua>
51 +- fixed compose menu
52 +
53 +* Thu Nov  6 2003 Vsevolod Volkov <vvv@mutt.org.ua>
54 +- update to 1.5.5.1
55 +
56 +* Wed Nov  5 2003 Vsevolod Volkov <vvv@mutt.org.ua>
57 +- update to 1.5.5
58 +- added space after newsgroup name in .newsrc file
59 +
60 +* Sun May 18 2003 Vsevolod Volkov <vvv@mutt.org.ua>
61 +- nntp patch: fixed SIGSEGV when posting article
62 +
63 +* Sat Mar 22 2003 Vsevolod Volkov <vvv@mutt.org.ua>
64 +- update to 1.5.4
65 +
66 +* Sat Dec 21 2002 Vsevolod Volkov <vvv@mutt.org.ua>
67 +- update to 1.5.3
68 +- replace safe_free calls by the FREE macro
69 +
70 +* Fri Dec  6 2002 Vsevolod Volkov <vvv@mutt.org.ua>
71 +- update to 1.5.2
72 +- nntp authentication can be passed after any command
73 +
74 +* Sat May  4 2002 Vsevolod Volkov <vvv@mutt.org.ua>
75 +- update to 1.5.1
76 +
77 +* Thu May  2 2002 Vsevolod Volkov <vvv@mutt.org.ua>
78 +- update to 1.3.99
79 +
80 +* Wed Mar 13 2002 Vsevolod Volkov <vvv@mutt.org.ua>
81 +- update to 1.3.28
82 +- fixed SIGSEGV in <get-message>, <get-parent>, <get-children>,
83 +  <reconstruct-thread> functions
84 +- fixed message about nntp reconnect
85 +- fixed <attach-news-message> function using browser
86 +- added support of Followup-To: poster
87 +- added %n (new articles) in group_index_format
88 +- posting articles without inews by default
89 +
90 +* Wed Jan 23 2002 Vsevolod Volkov <vvv@mutt.org.ua>
91 +- update to 1.3.27
92 +
93 +* Fri Jan 18 2002 Vsevolod Volkov <vvv@mutt.org.ua>
94 +- update to 1.3.26
95 +
96 +* Thu Jan  3 2002 Vsevolod Volkov <vvv@mutt.org.ua>
97 +- update to 1.3.25
98 +- accelerated speed of access to news->newsgroups hash (by <gul@gul.kiev.ua>)
99 +- added default content disposition
100 +
101 +* Mon Dec  3 2001 Vsevolod Volkov <vvv@mutt.org.ua>
102 +- update to 1.3.24
103 +
104 +* Fri Nov  9 2001 Vsevolod Volkov <vvv@mutt.org.ua>
105 +- update to 1.3.23.2
106 +- fixed segfault if mutt_conn_find() returns null
107 +
108 +* Wed Oct 31 2001 Vsevolod Volkov <vvv@mutt.org.ua>
109 +- update to 1.3.23.1
110 +- added support of LISTGROUP command
111 +- added support for servers with broken overview
112 +- disabled <flag-message> function on news server
113 +- fixed error storing bad authentication information
114 +
115 +* Wed Oct 10 2001 Vsevolod Volkov <vvv@mutt.org.ua>
116 +- update to 1.3.23
117 +- fixed typo in buffy.c
118 +- added substitution of %s parameter in $inews variable
119 +
120 +* Fri Aug 31 2001 Vsevolod Volkov <vvv@mutt.org.ua>
121 +- update to 1.3.22.1
122 +- update to 1.3.22
123 +
124 +* Thu Aug 23 2001 Vsevolod Volkov <vvv@mutt.org.ua>
125 +- update to 1.3.21
126 +
127 +* Wed Jul 25 2001 Vsevolod Volkov <vvv@mutt.org.ua>
128 +- update to 1.3.20
129 +- removed 'server-hook', use 'account-hook' instead
130 +- fixed error opening NNTP server without newsgroup using -f option
131 +
132 +* Fri Jun  8 2001 Vsevolod Volkov <vvv@mutt.org.ua>
133 +- update to 1.3.19
134 +
135 +* Sat May  5 2001 Vsevolod Volkov <vvv@mutt.org.ua>
136 +- update to 1.3.18
137 +- fixed typo in nntp_attempt_features()
138 +- changed algorithm of XGTITLE command testing
139 +- disabled writing of NNTP password in debug file
140 +- fixed reading and writing of long newsrc lines
141 +- changed checking of last line while reading lines from server
142 +- fixed possible buffer overrun in nntp_parse_newsrc_line()
143 +- removed checking of XHDR command
144 +- compare NNTP return codes without trailing space
145 +
146 +* Thu Mar 29 2001 Vsevolod Volkov <vvv@mutt.org.ua>
147 +- update to 1.3.17
148 +- support for 'LIST NEWSGROUPS' command to read descriptions
149 +
150 +* Fri Mar  2 2001 Vsevolod Volkov <vvv@mutt.org.ua>
151 +- update to 1.3.16
152 +
153 +* Wed Feb 14 2001 Vsevolod Volkov <vvv@mutt.org.ua>
154 +- update to 1.3.15
155 +
156 +* Sun Jan 28 2001 Vsevolod Volkov <vvv@mutt.org.ua>
157 +- update to 1.3.14
158 +- show number of tagged messages patch from Felix von Leitner <leitner@fefe.de>
159 +
160 +* Sun Dec 31 2000 Vsevolod Volkov <vvv@mutt.org.ua>
161 +- update to 1.3.13
162 +
163 +* Sat Dec 30 2000 Vsevolod Volkov <vvv@mutt.org.ua>
164 +- Fixed problem if last article in group is deleted
165 +
166 +* Fri Dec 22 2000 Vsevolod Volkov <vvv@mutt.org.ua>
167 +- Fixed checking of XGTITLE command on some servers
168 +
169 +* Mon Dec 18 2000 Vsevolod Volkov <vvv@mutt.org.ua>
170 +- Added \r in AUTHINFO commands
171 +
172 +* Mon Nov 27 2000 Vsevolod Volkov <vvv@mutt.org.ua>
173 +- update to 1.3.12
174 +
175 +* Wed Nov  1 2000 Vsevolod Volkov <vvv@mutt.org.ua>
176 +- update to 1.3.11
177 +- fixed error opening newsgroup from mutt started with -g or -G
178 +
179 +* Thu Oct 12 2000 Vsevolod Volkov <vvv@mutt.org.ua>
180 +- update to 1.3.10
181 +- hotkey 'G' (get-message) replaced with '^G'
182 +
183 +* Thu Sep 21 2000 Vsevolod Volkov <vvv@mutt.org.ua>
184 +- update to 1.3.9
185 +- changed delay displaying error messages from 1 to 2 seconds
186 +- fixed error compiling with nntp and without imap
187 +
188 +* Wed Sep  6 2000 Vsevolod Volkov <vvv@mutt.org.ua>
189 +- fixed catchup in index
190 +- fixed nntp_open_mailbox()
191 +
192 +* Sat Sep  2 2000 Vsevolod Volkov <vvv@mutt.org.ua>
193 +- functions <edit> and <delete-entry> disabled
194 +- format of news mailbox names changed to url form
195 +- option nntp_attempts removed
196 +- option reconnect_news renamed to nntp_reconnect
197 +- default value of nntp_poll changed from 30 to 60
198 +- error handling improved
199 +
200 +* Wed Aug 30 2000 Vsevolod Volkov <vvv@mutt.org.ua>
201 +- update to 1.3.8
202 +- new option show_only_unread
203 +- add newsgroup completion
204 +
205 +* Fri Aug  4 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
206 +- update to 1.3.7
207 +
208 +* Sat Jul 29 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
209 +- update to 1.3.6
210 +
211 +* Sun Jul  9 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
212 +- update to 1.3.5
213 +- authentication code update
214 +- fix for changing to newsgroup from mailbox with read messages
215 +- socket code optimization
216 +
217 +* Wed Jun 21 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
218 +- update to 1.3.4
219 +
220 +* Wed Jun 14 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
221 +- don't substitute current newsgroup with deleted new messages
222 +
223 +* Mon Jun 12 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
224 +- update to 1.3.3
225 +- fix for substitution of newsgroup after reconnection
226 +- fix for loading newsgroups with very long names
227 +- fix for loading more than 32768 newsgroups
228 +
229 +* Wed May 24 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
230 +- update to 1.3.2
231 +
232 +* Sat May 20 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
233 +- update to 1.3.1
234 +
235 +* Fri May 12 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
236 +- update to 1.3
237 +
238 +* Thu May 11 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
239 +- update to 1.2
240 +
241 +* Thu May  4 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
242 +- update to 1.1.14
243 +
244 +* Sun Apr 23 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
245 +- update to 1.1.12
246 +
247 +* Fri Apr  7 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
248 +- add substitution of newsgroup with new messages by default
249 +
250 +* Wed Apr  5 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
251 +- add attach message from newsgroup
252 +- add one-line help in newsreader mode
253 +- disable 'change-dir' command in newsgroups browser
254 +- add -G option
255 +
256 +* Tue Apr  4 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
257 +- get default newsserver name from file /etc/nntpserver
258 +- use case insensitive server names
259 +- add print-style sequence %s to $newsrc
260 +- add -g option
261 +
262 +* Sat Apr  1 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
263 +- remove 'X-FTN-Origin' header processing
264 +
265 +* Thu Mar 30 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
266 +- update to 1.1.11
267 +- update to 1.1.10
268 +
269 +* Thu Mar 23 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
270 +- fix mutt_select_newsserver()
271 +- remove 'toggle-mode' function
272 +- add 'change-newsgroup' function
273 +
274 +* Wed Mar 22 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
275 +- fix server-hook
276 +
277 +* Tue Mar 21 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
278 +- fix error 'bounce' function after 'post'
279 +- add 'forward to newsgroup' function
280 +
281 +* Mon Mar 20 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
282 +- 'forward' function works in newsreader mode
283 +- add 'post' and 'followup' functions to pager and attachment menu
284 +- fix active descriptions and allowed flag reload
285 +
286 +* Tue Mar 14 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
287 +- update to 1.1.9
288 +- remove deleted newsgroups from list
289 +
290 +* Mon Mar 13 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
291 +- update .newsrc in browser
292 +
293 +* Sun Mar 12 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
294 +- reload .newsrc if externally modified
295 +- fix active cache update
296 +
297 +* Sun Mar  5 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
298 +- update to 1.1.8
299 +
300 +* Sat Mar  4 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
301 +- patch *.update_list_file is not required
302 +- count lines when loading descriptions
303 +- remove cache of unsubscribed newsgroups
304 +
305 +* Thu Mar  2 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
306 +- load list of newsgroups from cache faster
307 +
308 +* Wed Mar  1 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
309 +- update to 1.1.7
310 +
311 +* Tue Feb 29 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
312 +- fix unread messages in browser
313 +- fix newsrc_gen_entries()
314 +
315 +* Mon Feb 28 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
316 +- fix mutt_newsgroup_stat()
317 +- fix nntp_delete_cache()
318 +- fix nntp_get_status()
319 +- fix check_children()
320 +- fix nntp_fetch_headers()
321 +
322 +* Fri Feb 25 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
323 +- update to 1.1.5
324 +
325 +* Thu Feb 24 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
326 +- fix updating new messages in cache
327 +
328 +* Mon Feb 21 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
329 +- change default cache filenames
330 +- fix updating new messages in cache
331 +
332 +* Fri Feb 18 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
333 +- fix segmentation fault in news groups browser
334 +
335 +* Tue Feb 15 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
336 +- update to 1.1.4
337 +
338 +* Thu Feb 10 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
339 +- update to 1.1.3
340 +
341 +* Sun Jan 30 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
342 +- add X-Comment-To editing
343 +- add my_hdr support for Newsgroups:, Followup-To: and X-Comment-To: headers
344 +- add variables $ask_followup_to and $ask_x_comment_to
345 +
346 +* Fri Jan 28 2000 Vsevolod Volkov <vvv@mutt.kiev.ua>
347 +- update to 1.1.2
348 diff -udprP mutt-1.5.13.orig/OPS mutt-1.5.13/OPS
349 --- mutt-1.5.13.orig/OPS        2005-07-24 19:56:42.000000000 +0300
350 +++ mutt-1.5.13/OPS     2006-08-15 13:04:56.000000000 +0300
351 @@ -8,14 +8,16 @@ OP_BOUNCE_MESSAGE "remail a message to a
352  OP_BROWSER_NEW_FILE "select a new file in this directory"
353  OP_BROWSER_VIEW_FILE "view file"
354  OP_BROWSER_TELL "display the currently selected file's name"
355 -OP_BROWSER_SUBSCRIBE "subscribe to current mailbox (IMAP only)"
356 -OP_BROWSER_UNSUBSCRIBE "unsubscribe to current mailbox (IMAP only)"
357 +OP_BROWSER_SUBSCRIBE "subscribe to current (IMAP/NNTP only)"
358 +OP_BROWSER_UNSUBSCRIBE "unsubscribe to current (IMAP/NNTP only)"
359  OP_BROWSER_TOGGLE_LSUB "toggle view all/subscribed mailboxes (IMAP only)"
360  OP_BUFFY_LIST "list mailboxes with new mail"
361 +OP_CATCHUP "mark all articles in newsgroup as read"
362  OP_CHANGE_DIRECTORY "change directories"
363  OP_CHECK_NEW "check mailboxes for new mail"
364  OP_COMPOSE_ATTACH_FILE "attach a file(s) to this message"
365  OP_COMPOSE_ATTACH_MESSAGE "attach message(s) to this message"
366 +OP_COMPOSE_ATTACH_NEWS_MESSAGE "attach newsmessage(s) to this message"
367  OP_COMPOSE_EDIT_BCC "edit the BCC list"
368  OP_COMPOSE_EDIT_CC "edit the CC list"
369  OP_COMPOSE_EDIT_DESCRIPTION "edit attachment description"
370 @@ -26,7 +28,10 @@ OP_COMPOSE_EDIT_FROM "edit the from fiel
371  OP_COMPOSE_EDIT_HEADERS "edit the message with headers"
372  OP_COMPOSE_EDIT_MESSAGE "edit the message"
373  OP_COMPOSE_EDIT_MIME "edit attachment using mailcap entry"
374 +OP_COMPOSE_EDIT_NEWSGROUPS "edit the newsgroups list"
375  OP_COMPOSE_EDIT_REPLY_TO "edit the Reply-To field"
376 +OP_COMPOSE_EDIT_FOLLOWUP_TO "edit the Followup-To field"
377 +OP_COMPOSE_EDIT_X_COMMENT_TO "edit the X-Comment-To field"
378  OP_COMPOSE_EDIT_SUBJECT "edit the subject of this message"
379  OP_COMPOSE_EDIT_TO "edit the TO list"
380  OP_CREATE_MAILBOX "create a new mailbox (IMAP only)"
381 @@ -85,8 +90,13 @@ OP_EXIT "exit this menu"
382  OP_FILTER "filter attachment through a shell command"
383  OP_FIRST_ENTRY "move to the first entry"
384  OP_FLAG_MESSAGE "toggle a message's 'important' flag"
385 +OP_FOLLOWUP "followup to newsgroup"
386 +OP_FORWARD_TO_GROUP "forward to newsgroup"
387  OP_FORWARD_MESSAGE "forward a message with comments"
388  OP_GENERIC_SELECT_ENTRY "select the current entry"
389 +OP_GET_CHILDREN "get all children of the current message"
390 +OP_GET_MESSAGE "get message with Message-Id"
391 +OP_GET_PARENT "get parent of the current message"
392  OP_GROUP_REPLY "reply to all recipients"
393  OP_HALF_DOWN "scroll down 1/2 page"
394  OP_HALF_UP "scroll up 1/2 page"
395 @@ -94,11 +104,14 @@ OP_HELP "this screen"
396  OP_JUMP "jump to an index number"
397  OP_LAST_ENTRY "move to the last entry"
398  OP_LIST_REPLY "reply to specified mailing list"
399 +OP_LOAD_ACTIVE "load active file from NNTP server"
400  OP_MACRO "execute a macro"
401  OP_MAIL "compose a new mail message"
402  OP_MAIN_BREAK_THREAD "break the thread in two"
403  OP_MAIN_CHANGE_FOLDER "open a different folder"
404  OP_MAIN_CHANGE_FOLDER_READONLY "open a different folder in read only mode"
405 +OP_MAIN_CHANGE_GROUP "open a different newsgroup"
406 +OP_MAIN_CHANGE_GROUP_READONLY "open a different newsgroup in read only mode"
407  OP_MAIN_CLEAR_FLAG "clear a status flag from a message"
408  OP_MAIN_DELETE_PATTERN "delete messages matching a pattern"
409  OP_MAIN_IMAP_FETCH "force retrieval of mail from IMAP server"
410 @@ -136,6 +149,7 @@ OP_PAGER_HIDE_QUOTED "toggle display of 
411  OP_PAGER_SKIP_QUOTED "skip beyond quoted text"
412  OP_PAGER_TOP "jump to the top of the message"
413  OP_PIPE "pipe message/attachment to a shell command"
414 +OP_POST "post message to newsgroup"
415  OP_PREV_ENTRY "move to the previous entry"
416  OP_PREV_LINE "scroll up one line"
417  OP_PREV_PAGE "move to the previous page"
418 @@ -144,6 +158,7 @@ OP_QUERY "query external program for add
419  OP_QUERY_APPEND "append new query results to current results"
420  OP_QUIT "save changes to mailbox and quit"
421  OP_RECALL_MESSAGE "recall a postponed message"
422 +OP_RECONSTRUCT_THREAD "reconstruct thread containing current message"
423  OP_REDRAW "clear and redraw the screen"
424  OP_REFORMAT_WINCH "{internal}"
425  OP_RENAME_MAILBOX "rename the current mailbox (IMAP only)"
426 @@ -158,18 +173,22 @@ OP_SEARCH_TOGGLE "toggle search pattern 
427  OP_SHELL_ESCAPE "invoke a command in a subshell"
428  OP_SORT "sort messages"
429  OP_SORT_REVERSE "sort messages in reverse order"
430 +OP_SUBSCRIBE_PATTERN "subscribe to newsgroups matching a pattern"
431  OP_TAG "tag the current entry"
432  OP_TAG_PREFIX "apply next function to tagged messages"
433  OP_TAG_PREFIX_COND "apply next function ONLY to tagged messages"
434  OP_TAG_SUBTHREAD "tag the current subthread"
435  OP_TAG_THREAD "tag the current thread"
436  OP_TOGGLE_NEW "toggle a message's 'new' flag"
437 +OP_TOGGLE_READ "toggle view of read messages"
438  OP_TOGGLE_WRITE "toggle whether the mailbox will be rewritten"
439  OP_TOGGLE_MAILBOXES "toggle whether to browse mailboxes or all files"
440  OP_TOP_PAGE "move to the top of the page"
441 +OP_UNCATCHUP "mark all articles in newsgroup as unread"
442  OP_UNDELETE "undelete the current entry"
443  OP_UNDELETE_THREAD "undelete all messages in thread"
444  OP_UNDELETE_SUBTHREAD "undelete all messages in subthread"
445 +OP_UNSUBSCRIBE_PATTERN "unsubscribe from newsgroups matching a pattern"
446  OP_VERSION "show the Mutt version number and date"
447  OP_VIEW_ATTACH "view attachment using mailcap entry if necessary"
448  OP_VIEW_ATTACHMENTS "show MIME attachments"
449 diff -udprP mutt-1.5.13.orig/PATCHES mutt-1.5.13/PATCHES
450 --- mutt-1.5.13.orig/PATCHES    2006-08-11 13:55:43.000000000 +0300
451 +++ mutt-1.5.13/PATCHES 2006-08-15 13:04:56.000000000 +0300
452 @@ -0,0 +1 @@
453 +vvv.nntp
454 diff -udprP mutt-1.5.13.orig/account.c mutt-1.5.13/account.c
455 --- mutt-1.5.13.orig/account.c  2005-09-18 11:22:21.000000000 +0300
456 +++ mutt-1.5.13/account.c       2006-08-15 13:04:56.000000000 +0300
457 @@ -54,6 +54,11 @@ int mutt_account_match (const ACCOUNT* a
458      user = PopUser;
459  #endif
460    
461 +#ifdef USE_NNTP
462 +  if (a1->type == M_ACCT_TYPE_NNTP && NntpUser)
463 +    user = NntpUser;
464 +#endif
465 +
466    if (a1->flags & a2->flags & M_ACCT_USER)
467      return (!strcmp (a1->user, a2->user));
468    if (a1->flags & M_ACCT_USER)
469 @@ -123,6 +128,16 @@ void mutt_account_tourl (ACCOUNT* accoun
470    }
471  #endif
472  
473 +#ifdef USE_NNTP
474 +  if (account->type == M_ACCT_TYPE_NNTP)
475 +  {
476 +    if (account->flags & M_ACCT_SSL)
477 +      url->scheme = U_NNTPS;
478 +    else
479 +      url->scheme = U_NNTP;
480 +  }
481 +#endif
482 +
483    url->host = account->host;
484    if (account->flags & M_ACCT_PORT)
485      url->port = account->port;
486 @@ -148,6 +163,10 @@ int mutt_account_getuser (ACCOUNT* accou
487    else if ((account->type == M_ACCT_TYPE_POP) && PopUser)
488      strfcpy (account->user, PopUser, sizeof (account->user));
489  #endif
490 +#ifdef USE_NNTP
491 +  else if ((account->type == M_ACCT_TYPE_NNTP) && NntpUser)
492 +    strfcpy (account->user, NntpUser, sizeof (account->user));
493 +#endif
494    /* prompt (defaults to unix username), copy into account->user */
495    else
496    {
497 @@ -204,6 +223,10 @@ int mutt_account_getpass (ACCOUNT* accou
498    else if ((account->type == M_ACCT_TYPE_POP) && PopPass)
499      strfcpy (account->pass, PopPass, sizeof (account->pass));
500  #endif
501 +#ifdef USE_NNTP
502 +  else if ((account->type == M_ACCT_TYPE_NNTP) && NntpPass)
503 +    strfcpy (account->pass, NntpPass, sizeof (account->pass));
504 +#endif
505    else
506    {
507      snprintf (prompt, sizeof (prompt), _("Password for %s@%s: "),
508 diff -udprP mutt-1.5.13.orig/account.h mutt-1.5.13/account.h
509 --- mutt-1.5.13.orig/account.h  2005-09-18 11:22:21.000000000 +0300
510 +++ mutt-1.5.13/account.h       2006-08-15 13:04:56.000000000 +0300
511 @@ -28,6 +28,7 @@ enum
512  {
513    M_ACCT_TYPE_NONE = 0,
514    M_ACCT_TYPE_IMAP,
515 +  M_ACCT_TYPE_NNTP,
516    M_ACCT_TYPE_POP
517  };
518  
519 diff -udprP mutt-1.5.13.orig/attach.h mutt-1.5.13/attach.h
520 --- mutt-1.5.13.orig/attach.h   2005-09-18 11:22:21.000000000 +0300
521 +++ mutt-1.5.13/attach.h        2006-08-15 13:04:56.000000000 +0300
522 @@ -50,7 +50,7 @@ void mutt_print_attachment_list (FILE *f
523  
524  void mutt_attach_bounce (FILE *, HEADER *, ATTACHPTR **, short, BODY *);
525  void mutt_attach_resend (FILE *, HEADER *, ATTACHPTR **, short, BODY *);
526 -void mutt_attach_forward (FILE *, HEADER *, ATTACHPTR **, short, BODY *);
527 +void mutt_attach_forward (FILE *, HEADER *, ATTACHPTR **, short, BODY *, int);
528  void mutt_attach_reply (FILE *, HEADER *, ATTACHPTR **, short, BODY *, int);
529  
530  #endif /* _ATTACH_H_ */
531 diff -udprP mutt-1.5.13.orig/browser.c mutt-1.5.13/browser.c
532 --- mutt-1.5.13.orig/browser.c  2006-08-06 01:17:37.000000000 +0300
533 +++ mutt-1.5.13/browser.c       2006-08-15 13:04:56.000000000 +0300
534 @@ -32,6 +32,9 @@
535  #ifdef USE_IMAP
536  #include "imap.h"
537  #endif
538 +#ifdef USE_NNTP
539 +#include "nntp.h"
540 +#endif
541  
542  #include <stdlib.h>
543  #include <dirent.h>
544 @@ -49,6 +52,19 @@ static struct mapping_t FolderHelp[] = {
545    { NULL }
546  };
547  
548 +#ifdef USE_NNTP
549 +static struct mapping_t FolderNewsHelp[] = {
550 +  { N_("Exit"),        OP_EXIT },
551 +  { N_("List"),        OP_TOGGLE_MAILBOXES },
552 +  { N_("Subscribe"),   OP_BROWSER_SUBSCRIBE },
553 +  { N_("Unsubscribe"), OP_BROWSER_UNSUBSCRIBE },
554 +  { N_("Catchup"),     OP_CATCHUP },
555 +  { N_("Mask"),        OP_ENTER_MASK },
556 +  { N_("Help"),        OP_HELP },
557 +  { NULL }
558 +};
559 +#endif
560 +
561  typedef struct folder_t
562  {
563    struct folder_file *ff;
564 @@ -114,9 +130,17 @@ static void browser_sort (struct browser
565      case SORT_ORDER:
566        return;
567      case SORT_DATE:
568 +#ifdef USE_NNTP
569 +      if (option (OPTNEWS))
570 +       return;
571 +#endif
572        f = browser_compare_date;
573        break;
574      case SORT_SIZE:
575 +#ifdef USE_NNTP
576 +      if (option (OPTNEWS))
577 +       return;
578 +#endif
579        f = browser_compare_size;
580        break;
581      case SORT_SUBJECT:
582 @@ -306,8 +330,106 @@ folder_format_str (char *dest, size_t de
583    return (src);
584  }
585  
586 +#ifdef USE_NNTP
587 +static const char *
588 +newsgroup_format_str (char *dest, size_t destlen, char op, const char *src,
589 +                      const char *fmt, const char *ifstring, const char *elsestring,
590 +                      unsigned long data, format_flag flags)
591 +{
592 +  char fn[SHORT_STRING], tmp[SHORT_STRING];
593 +  FOLDER *folder = (FOLDER *) data;
594 +
595 +  switch (op)
596 +  {
597 +    case 'C':
598 +      snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
599 +      snprintf (dest, destlen, tmp, folder->num + 1);
600 +      break;
601 +      
602 +    case 'f':
603 +      strncpy (fn, folder->ff->name, sizeof(fn) - 1);
604 +      snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
605 +      snprintf (dest, destlen, tmp, fn);
606 +      break;
607 +
608 +    case 'N':
609 +      snprintf (tmp, sizeof (tmp), "%%%sc", fmt);
610 +      if (folder->ff->nd->subscribed)
611 +       snprintf (dest, destlen, tmp, ' ');
612 +      else
613 +       snprintf (dest, destlen, tmp, folder->ff->new ? 'N' : 'u');
614 +      break;
615 +
616 +    case 'M':
617 +      snprintf (tmp, sizeof (tmp), "%%%sc", fmt);
618 +      if (folder->ff->nd->deleted)
619 +       snprintf (dest, destlen, tmp, 'D');
620 +      else
621 +       snprintf (dest, destlen, tmp, folder->ff->nd->allowed ? ' ' : '-');
622 +      break;
623 +
624 +    case 's':
625 +      if (flags & M_FORMAT_OPTIONAL)
626 +      {
627 +       if (folder->ff->nd->unread != 0)
628 +         mutt_FormatString (dest, destlen, ifstring, newsgroup_format_str,
629 +               data, flags);
630 +       else
631 +         mutt_FormatString (dest, destlen, elsestring, newsgroup_format_str,
632 +               data, flags);
633 +      }
634 +      else if (Context && Context->data == folder->ff->nd)
635 +      {
636 +       snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
637 +       snprintf (dest, destlen, tmp, Context->unread);
638 +      }
639 +      else
640 +      {
641 +       snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
642 +       snprintf (dest, destlen, tmp, folder->ff->nd->unread);
643 +      }
644 +      break;
645 +
646 +    case 'n':
647 +      if (Context && Context->data == folder->ff->nd)
648 +      {
649 +       snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
650 +       snprintf (dest, destlen, tmp, Context->new);
651 +      }
652 +      else if (option (OPTMARKOLD) &&
653 +               folder->ff->nd->lastCached >= folder->ff->nd->firstMessage &&
654 +               folder->ff->nd->lastCached <= folder->ff->nd->lastMessage)
655 +      {
656 +       snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
657 +       snprintf (dest, destlen, tmp, folder->ff->nd->lastMessage - folder->ff->nd->lastCached);
658 +      }
659 +      else
660 +      {
661 +       snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
662 +       snprintf (dest, destlen, tmp, folder->ff->nd->unread);
663 +      }
664 +      break;
665 +
666 +    case 'd':
667 +      if (folder->ff->nd->desc != NULL)
668 +      {
669 +       snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
670 +       snprintf (dest, destlen, tmp, folder->ff->nd->desc);
671 +      }
672 +      else
673 +      {
674 +       snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
675 +       snprintf (dest, destlen, tmp, "");
676 +      }
677 +      break;
678 +  }
679 +  return (src);
680 +}
681 +#endif /* USE_NNTP */
682 +
683  static void add_folder (MUTTMENU *m, struct browser_state *state,
684 -                       const char *name, const struct stat *s, int new)
685 +                       const char *name, const struct stat *s,
686 +                       void *data, int new)
687  {
688    if (state->entrylen == state->entrymax)
689    {
690 @@ -336,6 +458,10 @@ static void add_folder (MUTTMENU *m, str
691  #ifdef USE_IMAP
692    (state->entry)[state->entrylen].imap = 0;
693  #endif
694 +#ifdef USE_NNTP
695 +  if (option (OPTNEWS))
696 +    (state->entry)[state->entrylen].nd = (NNTP_DATA *) data;
697 +#endif
698    (state->entrylen)++;
699  }
700  
701 @@ -351,9 +477,35 @@ static void init_state (struct browser_s
702      menu->data = state->entry;
703  }
704  
705 +/* get list of all files/newsgroups with mask */
706  static int examine_directory (MUTTMENU *menu, struct browser_state *state,
707                               char *d, const char *prefix)
708  {
709 +#ifdef USE_NNTP
710 +  if (option (OPTNEWS))
711 +  {
712 +    LIST *tmp;
713 +    NNTP_DATA *data;
714 +    NNTP_SERVER *news = CurrentNewsSrv;
715 +
716 +/*  mutt_buffy_check (0); */
717 +    init_state (state, menu);
718 +
719 +    for (tmp = news->list; tmp; tmp = tmp->next)
720 +    {
721 +      if (!(data = (NNTP_DATA *)tmp->data))
722 +       continue;
723 +      if (prefix && *prefix && strncmp (prefix, data->group,
724 +           strlen (prefix)) != 0)
725 +       continue;
726 +      if (!((regexec (Mask.rx, data->group, 0, NULL, 0) == 0) ^ Mask.not))
727 +       continue;
728 +      add_folder (menu, state, data->group, NULL, data, data->new);
729 +    }
730 +  }
731 +  else
732 +#endif /* USE_NNTP */
733 +  {
734    struct stat s;
735    DIR *dp;
736    struct dirent *de;
737 @@ -414,17 +566,40 @@ static int examine_directory (MUTTMENU *
738      tmp = Incoming;
739      while (tmp && mutt_strcmp (buffer, tmp->path))
740        tmp = tmp->next;
741 -    add_folder (menu, state, de->d_name, &s, (tmp) ? tmp->new : 0);
742 +    add_folder (menu, state, de->d_name, &s, NULL, (tmp) ? tmp->new : 0);
743 +  }
744 +  closedir (dp);
745    }
746 -  closedir (dp);  
747    browser_sort (state);
748    return 0;
749  }
750  
751 +/* get list of mailboxes/subscribed newsgroups */
752  static int examine_mailboxes (MUTTMENU *menu, struct browser_state *state)
753  {
754    struct stat s;
755    char buffer[LONG_STRING];
756 +
757 +#ifdef USE_NNTP
758 +  if (option (OPTNEWS))
759 +  {
760 +    LIST *tmp;
761 +    NNTP_DATA *data;
762 +    NNTP_SERVER *news = CurrentNewsSrv;
763 +
764 +/*  mutt_buffy_check (0); */
765 +    init_state (state, menu);
766 +
767 +    for (tmp = news->list; tmp; tmp = tmp->next)
768 +    {
769 +      if ((data = (NNTP_DATA *) tmp->data) != NULL && (data->new ||
770 +         (data->subscribed && (!option (OPTSHOWONLYUNREAD) || data->unread))))
771 +        add_folder (menu, state, data->group, NULL, data, data->new);
772 +    }
773 +  }
774 +  else
775 +#endif
776 +  {
777    BUFFY *tmp = Incoming;
778  
779    if (!Incoming)
780 @@ -438,14 +613,21 @@ static int examine_mailboxes (MUTTMENU *
781  #ifdef USE_IMAP
782      if (mx_is_imap (tmp->path))
783      {
784 -      add_folder (menu, state, tmp->path, NULL, tmp->new);
785 +      add_folder (menu, state, tmp->path, NULL, NULL, tmp->new);
786        continue;
787      }
788  #endif
789  #ifdef USE_POP
790      if (mx_is_pop (tmp->path))
791      {
792 -      add_folder (menu, state, tmp->path, NULL, tmp->new);
793 +      add_folder (menu, state, tmp->path, NULL, NULL, tmp->new);
794 +      continue;
795 +    }
796 +#endif
797 +#ifdef USE_NNTP
798 +    if (mx_is_nntp (tmp->path))
799 +    {
800 +      add_folder (menu, state, tmp->path, NULL, NULL, tmp->new);
801        continue;
802      }
803  #endif
804 @@ -459,15 +641,20 @@ static int examine_mailboxes (MUTTMENU *
805      strfcpy (buffer, NONULL(tmp->path), sizeof (buffer));
806      mutt_pretty_mailbox (buffer);
807  
808 -    add_folder (menu, state, buffer, &s, tmp->new);
809 +    add_folder (menu, state, buffer, &s, NULL, tmp->new);
810    }
811    while ((tmp = tmp->next));
812 +  }
813    browser_sort (state);
814    return 0;
815  }
816  
817  static int select_file_search (MUTTMENU *menu, regex_t *re, int n)
818  {
819 +#ifdef USE_NNTP
820 +  if (option (OPTNEWS))
821 +    return (regexec (re, ((struct folder_file *) menu->data)[n].desc, 0, NULL, 0));
822 +#endif
823    return (regexec (re, ((struct folder_file *) menu->data)[n].name, 0, NULL, 0));
824  }
825  
826 @@ -478,7 +665,13 @@ static void folder_entry (char *s, size_
827    folder.ff = &((struct folder_file *) menu->data)[num];
828    folder.num = num;
829    
830 -  mutt_FormatString (s, slen, NONULL(FolderFormat), folder_format_str, 
831 +#ifdef USE_NNTP
832 +  if (option (OPTNEWS))
833 +    mutt_FormatString (s, slen, NONULL(GroupFormat), newsgroup_format_str, 
834 +      (unsigned long) &folder, M_FORMAT_ARROWCURSOR);
835 +  else
836 +#endif
837 +    mutt_FormatString (s, slen, NONULL(FolderFormat), folder_format_str, 
838        (unsigned long) &folder, M_FORMAT_ARROWCURSOR);
839  }
840  
841 @@ -498,6 +691,17 @@ static void init_menu (struct browser_st
842  
843    menu->tagged = 0;
844    
845 +#ifdef USE_NNTP
846 +  if (option (OPTNEWS))
847 +  {
848 +    if (buffy)
849 +      snprintf (title, titlelen, _("Subscribed newsgroups"));
850 +    else
851 +      snprintf (title, titlelen, _("Newsgroups on server [%s]"),
852 +               CurrentNewsSrv->conn->account.host);
853 +  }
854 +  else
855 +#endif
856    if (buffy)
857      snprintf (title, titlelen, _("Mailboxes [%d]"), mutt_buffy_check (0));
858    else
859 @@ -553,6 +757,31 @@ void _mutt_select_file (char *f, size_t 
860    if (!folder)
861      strfcpy (LastDirBackup, LastDir, sizeof (LastDirBackup));
862  
863 +#ifdef USE_NNTP
864 +  if (option (OPTNEWS))
865 +  {
866 +    if (*f)
867 +      strfcpy (prefix, f, sizeof (prefix));
868 +    else
869 +    {
870 +      LIST *list;
871 +
872 +      /* default state for news reader mode is browse subscribed newsgroups */
873 +      buffy = 0;
874 +      for (list = CurrentNewsSrv->list; list; list = list->next)
875 +      {
876 +       NNTP_DATA *data = (NNTP_DATA *) list->data;
877 +
878 +       if (data && data->subscribed)
879 +       {
880 +         buffy = 1;
881 +         break;
882 +       }
883 +      }
884 +    }
885 +  }
886 +  else
887 +#endif
888    if (*f)
889    {
890      mutt_expand_path (f, flen);
891 @@ -642,6 +871,9 @@ void _mutt_select_file (char *f, size_t 
892      menu->tag = file_tag;
893  
894    menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_FOLDER,
895 +#ifdef USE_NNTP
896 +    (option (OPTNEWS)) ? FolderNewsHelp :
897 +#endif
898      FolderHelp);
899  
900    init_menu (&state, menu, title, sizeof (title), buffy);
901 @@ -780,7 +1012,11 @@ void _mutt_select_file (char *f, size_t 
902           }
903         }
904  
905 +#ifdef USE_NNTP
906 +       if (buffy || option (OPTNEWS)) /* news have not path */
907 +#else
908         if (buffy)
909 +#endif
910         {
911           strfcpy (f, state.entry[menu->current].name, flen);
912           mutt_expand_path (f, flen);
913 @@ -838,14 +1074,6 @@ void _mutt_select_file (char *f, size_t 
914          break;
915  
916  #ifdef USE_IMAP
917 -      case OP_BROWSER_SUBSCRIBE:
918 -       imap_subscribe (state.entry[menu->current].name, 1);
919 -       break;
920 -
921 -      case OP_BROWSER_UNSUBSCRIBE:
922 -       imap_subscribe (state.entry[menu->current].name, 0);
923 -       break;
924 -
925        case OP_BROWSER_TOGGLE_LSUB:
926         if (option (OPTIMAPLSUB))
927         {
928 @@ -944,6 +1172,11 @@ void _mutt_select_file (char *f, size_t 
929        
930        case OP_CHANGE_DIRECTORY:
931  
932 +#ifdef USE_NNTP
933 +       if (option (OPTNEWS))
934 +         break;
935 +#endif
936 +
937         strfcpy (buf, LastDir, sizeof (buf));
938  #ifdef USE_IMAP
939         if (!state.imap_browse)
940 @@ -1200,6 +1433,190 @@ void _mutt_select_file (char *f, size_t 
941           else
942             mutt_error _("Error trying to view file");
943         }
944 +       break;
945 +
946 +#ifdef USE_NNTP
947 +      case OP_CATCHUP:
948 +      case OP_UNCATCHUP:
949 +       if (option (OPTNEWS))
950 +       {
951 +         struct folder_file *f = &state.entry[menu->current];
952 +         NNTP_DATA *nd;
953 +
954 +         if (i == OP_CATCHUP)
955 +           nd = mutt_newsgroup_catchup (CurrentNewsSrv, f->name);
956 +         else
957 +           nd = mutt_newsgroup_uncatchup (CurrentNewsSrv, f->name);
958 +
959 +         if (nd)
960 +         {
961 +/*         FOLDER folder;
962 +           struct folder_file ff;
963 +           char buffer[_POSIX_PATH_MAX + SHORT_STRING];
964 +
965 +           folder.ff = &ff;
966 +           folder.ff->name = f->name;
967 +           folder.ff->st = NULL;
968 +           folder.ff->is_new = nd->new;
969 +           folder.ff->nd = nd;
970 +           FREE (&f->desc);
971 +           mutt_FormatString (buffer, sizeof (buffer), NONULL(GroupFormat),
972 +                 newsgroup_format_str, (unsigned long) &folder,
973 +                 M_FORMAT_ARROWCURSOR);
974 +           f->desc = safe_strdup (buffer); */
975 +           if (menu->current + 1 < menu->max)
976 +             menu->current++;
977 +           menu->redraw = REDRAW_MOTION_RESYNCH;
978 +         }
979 +       }
980 +       break;
981 +
982 +      case OP_LOAD_ACTIVE:
983 +       if (!option (OPTNEWS))
984 +         break;
985 +
986 +       {
987 +         LIST *tmp;
988 +         NNTP_DATA *data;
989 +
990 +         for (tmp = CurrentNewsSrv->list; tmp; tmp = tmp->next)
991 +         {
992 +           if ((data = (NNTP_DATA *)tmp->data))
993 +             data->deleted = 1;
994 +         }
995 +       }
996 +       nntp_get_active (CurrentNewsSrv);
997 +
998 +       destroy_state (&state);
999 +       if (buffy)
1000 +         examine_mailboxes (menu, &state);
1001 +       else
1002 +         examine_directory (menu, &state, NULL, NULL);
1003 +       init_menu (&state, menu, title, sizeof (title), buffy);
1004 +       break;
1005 +#endif /* USE_NNTP */
1006 +
1007 +#if defined USE_IMAP || defined USE_NNTP
1008 +      case OP_BROWSER_SUBSCRIBE:
1009 +      case OP_BROWSER_UNSUBSCRIBE:
1010 +#endif
1011 +#ifdef USE_NNTP
1012 +      case OP_SUBSCRIBE_PATTERN:
1013 +      case OP_UNSUBSCRIBE_PATTERN:
1014 +        if (option (OPTNEWS))
1015 +       {
1016 +         regex_t *rx = (regex_t *) safe_malloc (sizeof (regex_t));
1017 +         char *s = buf;
1018 +         int j = menu->current;
1019 +         NNTP_DATA *nd;
1020 +         NNTP_SERVER *news = CurrentNewsSrv;
1021 +
1022 +         if (i == OP_SUBSCRIBE_PATTERN || i == OP_UNSUBSCRIBE_PATTERN)
1023 +         {
1024 +           char tmp[STRING];
1025 +           int err;
1026 +
1027 +           buf[0] = 0;
1028 +           if (i == OP_SUBSCRIBE_PATTERN)
1029 +             snprintf (tmp, sizeof (tmp), _("Subscribe pattern: "));
1030 +           else
1031 +             snprintf (tmp, sizeof (tmp), _("Unsubscribe pattern: "));
1032 +           if (mutt_get_field (tmp, buf, sizeof (buf), 0) != 0 || !buf[0])
1033 +           {
1034 +             FREE (&rx);
1035 +             break;
1036 +           }
1037 +
1038 +           if ((err = REGCOMP (rx, s, REG_NOSUB)) != 0)
1039 +           {
1040 +             regerror (err, rx, buf, sizeof (buf));
1041 +             regfree (rx);
1042 +             FREE (&rx);
1043 +             mutt_error ("%s", buf);
1044 +             break;
1045 +           }
1046 +           menu->redraw = REDRAW_FULL;
1047 +           j = 0;
1048 +         }
1049 +         else if (!state.entrylen)
1050 +         {
1051 +           mutt_error _("No newsgroups match the mask");
1052 +           break;
1053 +         }
1054 +
1055 +         for ( ; j < state.entrylen; j++)
1056 +         {
1057 +           struct folder_file *f = &state.entry[j];
1058 +
1059 +           if (i == OP_BROWSER_SUBSCRIBE || i == OP_BROWSER_UNSUBSCRIBE ||
1060 +                 regexec (rx, f->name, 0, NULL, 0) == 0)
1061 +           {
1062 +             if (i == OP_BROWSER_SUBSCRIBE || i == OP_SUBSCRIBE_PATTERN)
1063 +               nd = mutt_newsgroup_subscribe (news, f->name);
1064 +             else
1065 +               nd = mutt_newsgroup_unsubscribe (news, f->name);
1066 +/*           if (nd)
1067 +             {
1068 +               FOLDER folder;
1069 +               char buffer[_POSIX_PATH_MAX + SHORT_STRING];
1070 +
1071 +               folder.name = f->name;
1072 +               folder.f = NULL;
1073 +               folder.new = nd->new;
1074 +               folder.nd = nd;
1075 +               FREE (&f->desc);
1076 +               mutt_FormatString (buffer, sizeof (buffer), NONULL(GroupFormat),
1077 +                       newsgroup_format_str, (unsigned long) &folder,
1078 +                       M_FORMAT_ARROWCURSOR);
1079 +               f->desc = safe_strdup (buffer);
1080 +             } */
1081 +           }
1082 +           if (i == OP_BROWSER_SUBSCRIBE || i == OP_BROWSER_UNSUBSCRIBE)
1083 +           {
1084 +             if (menu->current + 1 < menu->max)
1085 +               menu->current++;
1086 +             menu->redraw = REDRAW_MOTION_RESYNCH;
1087 +             break;
1088 +           }
1089 +         }
1090 +         if (i == OP_SUBSCRIBE_PATTERN)
1091 +         {
1092 +           LIST *grouplist = NULL;
1093 +
1094 +           if (news)
1095 +             grouplist = news->list;
1096 +           for (; grouplist; grouplist = grouplist->next)
1097 +           {
1098 +             nd = (NNTP_DATA *) grouplist->data;
1099 +             if (nd && nd->group && !nd->subscribed)
1100 +             {
1101 +               if (regexec (rx, nd->group, 0, NULL, 0) == 0)
1102 +               {
1103 +                 mutt_newsgroup_subscribe (news, nd->group);
1104 +                 add_folder (menu, &state, nd->group, NULL, nd, nd->new);
1105 +               }
1106 +             }
1107 +           }
1108 +           init_menu (&state, menu, title, sizeof (title), buffy);
1109 +         }
1110 +         mutt_newsrc_update (news);
1111 +         nntp_clear_cacheindex (news);
1112 +         if (i != OP_BROWSER_SUBSCRIBE && i != OP_BROWSER_UNSUBSCRIBE)
1113 +           regfree (rx);
1114 +         FREE (&rx);
1115 +       }
1116 +#ifdef USE_IMAP
1117 +       else
1118 +#endif /* USE_IMAP && USE_NNTP */
1119 +#endif /* USE_NNTP */
1120 +#ifdef USE_IMAP
1121 +       {
1122 +         if (i == OP_BROWSER_SUBSCRIBE)
1123 +           imap_subscribe (state.entry[menu->current].name, 1);
1124 +         else
1125 +           imap_subscribe (state.entry[menu->current].name, 0);
1126 +       }
1127 +#endif /* USE_IMAP */
1128      }
1129    }
1130    
1131 diff -udprP mutt-1.5.13.orig/browser.h mutt-1.5.13/browser.h
1132 --- mutt-1.5.13.orig/browser.h  2005-09-18 11:22:21.000000000 +0300
1133 +++ mutt-1.5.13/browser.h       2006-08-15 13:04:56.000000000 +0300
1134 @@ -20,6 +20,10 @@
1135  #ifndef _BROWSER_H
1136  #define _BROWSER_H 1
1137  
1138 +#ifdef USE_NNTP
1139 +#include "nntp.h"
1140 +#endif
1141 +
1142  struct folder_file
1143  {
1144    mode_t mode;
1145 @@ -38,14 +42,17 @@ struct folder_file
1146    unsigned selectable : 1;
1147    unsigned inferiors : 1;
1148  #endif
1149 +#ifdef USE_NNTP
1150 +  NNTP_DATA *nd;
1151 +#endif
1152    unsigned tagged : 1;
1153  };
1154  
1155  struct browser_state
1156  {
1157    struct folder_file *entry;
1158 -  short entrylen; /* number of real entries */
1159 -  short entrymax;  /* max entry */
1160 +  unsigned int entrylen; /* number of real entries */
1161 +  unsigned int entrymax; /* max entry */
1162  #ifdef USE_IMAP
1163    short imap_browse;
1164    char *folder;
1165 diff -udprP mutt-1.5.13.orig/buffy.c mutt-1.5.13/buffy.c
1166 --- mutt-1.5.13.orig/buffy.c    2006-05-18 21:44:28.000000000 +0300
1167 +++ mutt-1.5.13/buffy.c 2006-08-15 13:04:56.000000000 +0300
1168 @@ -293,6 +293,9 @@ int mutt_buffy_check (int force)
1169  #ifdef USE_POP
1170    if (!Context || Context->magic != M_POP)
1171  #endif
1172 +#ifdef USE_NNTP
1173 +  if (!Context || Context->magic != M_NNTP)
1174 +#endif
1175    /* check device ID and serial number instead of comparing paths */
1176    if (!Context || !Context->path || stat (Context->path, &contex_sb) != 0)
1177    {
1178 @@ -316,6 +319,11 @@ int mutt_buffy_check (int force)
1179        tmp->magic = M_POP;
1180      else
1181  #endif
1182 +#ifdef USE_NNTP
1183 +    if ((tmp->magic == M_NNTP) || mx_is_nntp (tmp->path))
1184 +      tmp->magic = M_NNTP;
1185 +    else
1186 +#endif
1187      if (stat (tmp->path, &sb) != 0 || sb.st_size == 0 ||
1188         (!tmp->magic && (tmp->magic = mx_get_magic (tmp->path)) <= 0))
1189      {
1190 @@ -335,25 +343,21 @@ int mutt_buffy_check (int force)
1191      /* check to see if the folder is the currently selected folder
1192       * before polling */
1193      if (!Context || !Context->path ||
1194 -#if defined USE_IMAP || defined USE_POP
1195 -       ((
1196 +        (
1197 +          (0
1198  #ifdef USE_IMAP
1199 -       tmp->magic == M_IMAP
1200 +           || tmp->magic == M_IMAP
1201  #endif
1202  #ifdef USE_POP
1203 -#ifdef USE_IMAP
1204 -       ||
1205 -#endif
1206 -       tmp->magic == M_POP
1207 -#endif
1208 -       ) ? mutt_strcmp (tmp->path, Context->path) :
1209 +           || tmp->magic == M_POP
1210  #endif
1211 -        (sb.st_dev != contex_sb.st_dev || sb.st_ino != contex_sb.st_ino)
1212 -#if defined USE_IMAP || defined USE_POP         
1213 -           )
1214 +#ifdef USE_NNTP
1215 +           || tmp->magic == M_NNTP
1216  #endif
1217 -       )
1218 -       
1219 +          ) ? mutt_strcmp (tmp->path, Context->path) :
1220 +              (sb.st_dev != contex_sb.st_dev || sb.st_ino != contex_sb.st_ino)
1221 +        )
1222 +       )
1223      {
1224        switch (tmp->magic)
1225        {
1226 diff -udprP mutt-1.5.13.orig/complete.c mutt-1.5.13/complete.c
1227 --- mutt-1.5.13.orig/complete.c 2005-09-18 11:22:21.000000000 +0300
1228 +++ mutt-1.5.13/complete.c      2006-08-15 13:04:56.000000000 +0300
1229 @@ -25,6 +25,9 @@
1230  #include "mailbox.h"
1231  #include "imap.h"
1232  #endif
1233 +#ifdef USE_NNTP
1234 +#include "nntp.h"
1235 +#endif
1236  
1237  #include <dirent.h>
1238  #include <string.h>
1239 @@ -48,9 +51,71 @@ int mutt_complete (char *s, size_t slen)
1240    char filepart[_POSIX_PATH_MAX];
1241  #ifdef USE_IMAP
1242    char imap_path[LONG_STRING];
1243 +#endif
1244  
1245    dprint (2, (debugfile, "mutt_complete: completing %s\n", s));
1246  
1247 +#ifdef USE_NNTP
1248 +  if (option (OPTNEWS))
1249 +  {
1250 +    LIST *l = CurrentNewsSrv->list;
1251 +
1252 +    strfcpy (filepart, s, sizeof (filepart));
1253 +
1254 +    /*
1255 +     * special case to handle when there is no filepart yet.
1256 +     * find the first subscribed newsgroup
1257 +     */
1258 +    if ((len = mutt_strlen (filepart)) == 0)
1259 +    {
1260 +      for (; l; l = l->next)
1261 +      {
1262 +       NNTP_DATA *data = (NNTP_DATA *)l->data;
1263 +
1264 +       if (data && data->subscribed)
1265 +       {
1266 +         strfcpy (filepart, data->group, sizeof (filepart));
1267 +         init++;
1268 +         l = l->next;
1269 +         break;
1270 +       }
1271 +      }
1272 +    }
1273 +
1274 +    for (; l; l = l->next)
1275 +    {
1276 +      NNTP_DATA *data = (NNTP_DATA *)l->data;
1277 +
1278 +      if (data && data->subscribed &&
1279 +         mutt_strncmp (data->group, filepart, len) == 0)
1280 +      {
1281 +       if (init)
1282 +       {
1283 +         for (i = 0; filepart[i] && data->group[i]; i++)
1284 +         {
1285 +           if (filepart[i] != data->group[i])
1286 +           {
1287 +             filepart[i] = 0;
1288 +             break;
1289 +           }
1290 +         }
1291 +         filepart[i] = 0;
1292 +       }
1293 +       else
1294 +       {
1295 +         strfcpy (filepart, data->group, sizeof (filepart));
1296 +         init = 1;
1297 +       }
1298 +      }
1299 +    }
1300 +
1301 +    strcpy (s, filepart);
1302 +
1303 +    return (init ? 0 : -1);
1304 +  }
1305 +#endif
1306 +
1307 +#ifdef USE_IMAP
1308    /* we can use '/' as a delimiter, imap_complete rewrites it */
1309    if (*s == '=' || *s == '+' || *s == '!')
1310    {
1311 diff -udprP mutt-1.5.13.orig/compose.c mutt-1.5.13/compose.c
1312 --- mutt-1.5.13.orig/compose.c  2005-09-18 11:22:21.000000000 +0300
1313 +++ mutt-1.5.13/compose.c       2006-08-15 13:04:56.000000000 +0300
1314 @@ -32,10 +32,15 @@
1315  #include "mailbox.h"
1316  #include "sort.h"
1317  #include "charset.h"
1318 +#include "mx.h"
1319  
1320  #ifdef MIXMASTER
1321  #include "remailer.h"
1322  #endif
1323 +  
1324 +#ifdef USE_NNTP
1325 +#include "nntp.h"
1326 +#endif
1327  
1328  #include <errno.h>
1329  #include <string.h>
1330 @@ -60,18 +65,21 @@ enum
1331    HDR_REPLYTO,
1332    HDR_FCC,
1333  
1334 -#ifdef MIXMASTER
1335 -  HDR_MIX,
1336 -#endif
1337  
1338    HDR_CRYPT,
1339    HDR_CRYPTINFO,
1340  
1341 +#ifdef USE_NNTP
1342 +  HDR_NEWSGROUPS,
1343 +  HDR_FOLLOWUPTO,
1344 +  HDR_XCOMMENTTO,
1345 +#endif
1346 +
1347    HDR_ATTACH  = (HDR_FCC + 5) /* where to start printing the attachments */
1348  };
1349  
1350 -#define HDR_XOFFSET 10
1351 -#define TITLE_FMT "%10s" /* Used for Prompts, which are ASCII */
1352 +#define HDR_XOFFSET 14
1353 +#define TITLE_FMT "%14s" /* Used for Prompts, which are ASCII */
1354  #define W (COLS - HDR_XOFFSET)
1355  
1356  static char *Prompts[] =
1357 @@ -83,6 +91,16 @@ static char *Prompts[] =
1358    "Subject: ",
1359    "Reply-To: ",
1360    "Fcc: "
1361 +#ifdef USE_NNTP
1362 +#ifdef MIXMASTER
1363 +  ,""
1364 +#endif
1365 +  ,""
1366 +  ,""
1367 +  ,"Newsgroups: "
1368 +  ,"Followup-To: "
1369 +  ,"X-Comment-To: "
1370 +#endif
1371  };
1372  
1373  static struct mapping_t ComposeHelp[] = {
1374 @@ -97,6 +115,19 @@ static struct mapping_t ComposeHelp[] = 
1375    { NULL }
1376  };
1377  
1378 +#ifdef USE_NNTP
1379 +static struct mapping_t ComposeNewsHelp[] = {
1380 +  { N_("Send"),    OP_COMPOSE_SEND_MESSAGE },
1381 +  { N_("Abort"),   OP_EXIT },
1382 +  { "Newsgroups",  OP_COMPOSE_EDIT_NEWSGROUPS },
1383 +  { "Subj",        OP_COMPOSE_EDIT_SUBJECT },
1384 +  { N_("Attach file"),  OP_COMPOSE_ATTACH_FILE },
1385 +  { N_("Descrip"), OP_COMPOSE_EDIT_DESCRIPTION },
1386 +  { N_("Help"),    OP_HELP },
1387 +  { NULL }
1388 +};
1389 +#endif
1390 +
1391  static void snd_entry (char *b, size_t blen, MUTTMENU *menu, int num)
1392  {
1393      mutt_FormatString (b, blen, NONULL (AttachFormat), mutt_attach_fmt,
1394 @@ -115,16 +146,16 @@ static void redraw_crypt_lines (HEADER *
1395    if ((WithCrypto & APPLICATION_PGP) && (WithCrypto & APPLICATION_SMIME))
1396    {     
1397      if (!msg->security)
1398 -      mvaddstr (HDR_CRYPT, 0,     "Security: ");
1399 +      mvaddstr (HDR_CRYPT, 0,     "    Security: ");
1400      else if (msg->security & APPLICATION_SMIME)
1401 -      mvaddstr (HDR_CRYPT, 0,     "  S/MIME: ");
1402 +      mvaddstr (HDR_CRYPT, 0,     "      S/MIME: ");
1403      else if (msg->security & APPLICATION_PGP)
1404 -      mvaddstr (HDR_CRYPT, 0,     "     PGP: ");
1405 +      mvaddstr (HDR_CRYPT, 0,     "         PGP: ");
1406    }
1407    else if ((WithCrypto & APPLICATION_SMIME))
1408 -    mvaddstr (HDR_CRYPT, 0,     "  S/MIME: ");
1409 +    mvaddstr (HDR_CRYPT, 0,     "      S/MIME: ");
1410    else if ((WithCrypto & APPLICATION_PGP))
1411 -    mvaddstr (HDR_CRYPT, 0,     "     PGP: ");
1412 +    mvaddstr (HDR_CRYPT, 0,     "         PGP: ");
1413    else
1414      return;
1415  
1416 @@ -252,9 +283,28 @@ static void draw_envelope_addr (int line
1417  static void draw_envelope (HEADER *msg, char *fcc)
1418  {
1419    draw_envelope_addr (HDR_FROM, msg->env->from);
1420 +#ifdef USE_NNTP
1421 +  if (!option (OPTNEWSSEND))
1422 +  {
1423 +#endif
1424    draw_envelope_addr (HDR_TO, msg->env->to);
1425    draw_envelope_addr (HDR_CC, msg->env->cc);
1426    draw_envelope_addr (HDR_BCC, msg->env->bcc);
1427 +#ifdef USE_NNTP
1428 +  }
1429 +  else
1430 +  {
1431 +    mvprintw (HDR_TO, 0, TITLE_FMT , Prompts[HDR_NEWSGROUPS - 1]);
1432 +    mutt_paddstr (W, NONULL (msg->env->newsgroups));
1433 +    mvprintw (HDR_CC, 0, TITLE_FMT , Prompts[HDR_FOLLOWUPTO - 1]);
1434 +    mutt_paddstr (W, NONULL (msg->env->followup_to));
1435 +    if (option (OPTXCOMMENTTO))
1436 +    {
1437 +      mvprintw (HDR_BCC, 0, TITLE_FMT , Prompts[HDR_XCOMMENTTO - 1]);
1438 +      mutt_paddstr (W, NONULL (msg->env->x_comment_to));
1439 +    }
1440 +  }
1441 +#endif
1442    mvprintw (HDR_SUBJECT, 0, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
1443    mutt_paddstr (W, NONULL (msg->env->subject));
1444    draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
1445 @@ -507,6 +557,12 @@ int mutt_compose_menu (HEADER *msg,   /*
1446    /* Sort, SortAux could be changed in mutt_index_menu() */
1447    int oldSort, oldSortAux;
1448    struct stat st;
1449 +#ifdef USE_NNTP
1450 +  int news = 0;               /* is it a news article ? */
1451 +
1452 +  if (option (OPTNEWSSEND))
1453 +    news++;
1454 +#endif
1455  
1456    mutt_attach_init (msg->content);
1457    idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
1458 @@ -518,10 +574,18 @@ int mutt_compose_menu (HEADER *msg,   /*
1459    menu->make_entry = snd_entry;
1460    menu->tag = mutt_tag_attach;
1461    menu->data = idx;
1462 +#ifdef USE_NNTP
1463 +  if (news)
1464 +  menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE, ComposeNewsHelp);
1465 +  else
1466 +#endif
1467    menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE, ComposeHelp);
1468    
1469    while (loop)
1470    {
1471 +#ifdef USE_NNTP
1472 +    unset_option (OPTNEWS);    /* for any case */
1473 +#endif
1474      switch (op = mutt_menuLoop (menu))
1475      {
1476        case OP_REDRAW:
1477 @@ -534,17 +598,87 @@ int mutt_compose_menu (HEADER *msg,   /*
1478          mutt_message_hook (NULL, msg, M_SEND2HOOK);
1479         break;
1480        case OP_COMPOSE_EDIT_TO:
1481 +#ifdef USE_NNTP
1482 +       if (news)
1483 +         break;
1484 +#endif
1485         menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
1486          mutt_message_hook (NULL, msg, M_SEND2HOOK);
1487          break;
1488        case OP_COMPOSE_EDIT_BCC:
1489 +#ifdef USE_NNTP
1490 +       if (news)
1491 +         break;
1492 +#endif
1493         menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
1494          mutt_message_hook (NULL, msg, M_SEND2HOOK);
1495         break;
1496        case OP_COMPOSE_EDIT_CC:
1497 +#ifdef USE_NNTP
1498 +       if (news)
1499 +         break;
1500 +#endif
1501         menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
1502          mutt_message_hook (NULL, msg, M_SEND2HOOK);    
1503          break;
1504 +#ifdef USE_NNTP
1505 +      case OP_COMPOSE_EDIT_NEWSGROUPS:
1506 +       if (news)
1507 +       {
1508 +         if (msg->env->newsgroups)
1509 +           strfcpy (buf, msg->env->newsgroups, sizeof (buf));
1510 +         else
1511 +           buf[0] = 0;
1512 +         if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) == 0 && buf[0])
1513 +         {
1514 +           FREE (&msg->env->newsgroups);
1515 +           mutt_remove_trailing_ws (buf);
1516 +           msg->env->newsgroups = safe_strdup (mutt_skip_whitespace (buf));
1517 +           move (HDR_TO, HDR_XOFFSET);
1518 +           clrtoeol ();
1519 +           if (msg->env->newsgroups)
1520 +             printw ("%-*.*s", W, W, msg->env->newsgroups);
1521 +         }
1522 +       }
1523 +       break;
1524 +
1525 +      case OP_COMPOSE_EDIT_FOLLOWUP_TO:
1526 +       if (news)
1527 +       {
1528 +         buf[0] = 0;
1529 +         if (msg->env->followup_to)
1530 +           strfcpy (buf, msg->env->followup_to, sizeof (buf));
1531 +         if (mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) == 0 && buf[0])
1532 +         {
1533 +           FREE (&msg->env->followup_to);
1534 +           mutt_remove_trailing_ws (buf);
1535 +           msg->env->followup_to = safe_strdup (mutt_skip_whitespace (buf));
1536 +           move (HDR_CC, HDR_XOFFSET);
1537 +           clrtoeol();
1538 +           if (msg->env->followup_to)
1539 +             printw ("%-*.*s", W, W, msg->env->followup_to);
1540 +         }
1541 +       }
1542 +       break;
1543 +
1544 +      case OP_COMPOSE_EDIT_X_COMMENT_TO:
1545 +       if (news && option (OPTXCOMMENTTO))
1546 +       {
1547 +         buf[0] = 0;
1548 +         if (msg->env->x_comment_to)
1549 +           strfcpy (buf, msg->env->x_comment_to, sizeof (buf));
1550 +         if (mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) == 0 && buf[0])
1551 +         {
1552 +           FREE (&msg->env->x_comment_to);
1553 +           msg->env->x_comment_to = safe_strdup (buf);
1554 +           move (HDR_BCC, HDR_XOFFSET);
1555 +           clrtoeol();
1556 +           if (msg->env->x_comment_to)
1557 +             printw ("%-*.*s", W, W, msg->env->x_comment_to);
1558 +         }
1559 +       }
1560 +       break;
1561 +#endif
1562        case OP_COMPOSE_EDIT_SUBJECT:
1563         if (msg->env->subject)
1564           strfcpy (buf, msg->env->subject, sizeof (buf));
1565 @@ -707,6 +841,9 @@ int mutt_compose_menu (HEADER *msg,   /*
1566          break;
1567  
1568        case OP_COMPOSE_ATTACH_MESSAGE:
1569 +#ifdef USE_NNTP
1570 +      case OP_COMPOSE_ATTACH_NEWS_MESSAGE:
1571 +#endif
1572         {
1573           char *prompt;
1574           HEADER *h;
1575 @@ -714,7 +851,22 @@ int mutt_compose_menu (HEADER *msg,   /*
1576           fname[0] = 0;
1577           prompt = _("Open mailbox to attach message from");
1578  
1579 +#ifdef USE_NNTP
1580 +         unset_option (OPTNEWS);
1581 +         if (op == OP_COMPOSE_ATTACH_NEWS_MESSAGE)
1582 +         {
1583 +           if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1584 +             break;
1585 +
1586 +           prompt = _("Open newsgroup to attach message from");
1587 +           set_option (OPTNEWS);
1588 +         }
1589 +#endif
1590 +
1591           if (Context)
1592 +#ifdef USE_NNTP
1593 +         if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->magic == M_NNTP))
1594 +#endif
1595           {
1596             strfcpy (fname, NONULL (Context->path), sizeof (fname));
1597             mutt_pretty_mailbox (fname);
1598 @@ -723,6 +875,11 @@ int mutt_compose_menu (HEADER *msg,   /*
1599           if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1) == -1 || !fname[0])
1600             break;
1601  
1602 +#ifdef USE_NNTP
1603 +         if (option (OPTNEWS))
1604 +           nntp_expand_path (fname, sizeof (fname), &CurrentNewsSrv->conn->account);
1605 +         else
1606 +#endif
1607           mutt_expand_path (fname, sizeof (fname));
1608  #ifdef USE_IMAP
1609            if (!mx_is_imap (fname))
1610 @@ -730,6 +887,9 @@ int mutt_compose_menu (HEADER *msg,   /*
1611  #ifdef USE_POP
1612            if (!mx_is_pop (fname))
1613  #endif
1614 +#ifdef USE_NNTP
1615 +          if (!mx_is_nntp (fname) && !option (OPTNEWS))
1616 +#endif
1617           /* check to make sure the file exists and is readable */
1618           if (access (fname, R_OK) == -1)
1619           {
1620 diff -udprP mutt-1.5.13.orig/config.h.in mutt-1.5.13/config.h.in
1621 --- mutt-1.5.13.orig/config.h.in        2006-08-14 17:09:46.000000000 +0300
1622 +++ mutt-1.5.13/config.h.in     2006-08-15 13:04:56.000000000 +0300
1623 @@ -37,6 +37,9 @@
1624     significant more memory when defined. */
1625  #undef EXACT_ADDRESS
1626  
1627 +/* Compiling with newsreading support with NNTP */
1628 +#undef USE_NNTP
1629 +
1630  /* program to use for shell commands */
1631  #undef EXECSHELL
1632  
1633 diff -udprP mutt-1.5.13.orig/configure.in mutt-1.5.13/configure.in
1634 --- mutt-1.5.13.orig/configure.in       2006-08-14 17:09:18.000000000 +0300
1635 +++ mutt-1.5.13/configure.in    2006-08-15 13:04:56.000000000 +0300
1636 @@ -574,6 +574,14 @@ if test x"$need_imap" = xyes -o x"$need_
1637    MUTT_LIB_OBJECTS="$MUTT_LIB_OBJECTS bcache.o"
1638  fi
1639  
1640 +AC_ARG_ENABLE(nntp, [  --enable-nntp              Enable NNTP support],
1641 +[      if test x$enableval = xyes ; then
1642 +               AC_DEFINE(USE_NNTP,1,[ Define if you want support for the NNTP protocol. ])
1643 +               MUTT_LIB_OBJECTS="$MUTT_LIB_OBJECTS nntp.o newsrc.o"
1644 +               need_socket="yes"
1645 +       fi
1646 +])
1647 +
1648  dnl -- end socket dependencies --
1649  
1650  if test "$need_socket" = "yes"
1651 diff -udprP mutt-1.5.13.orig/curs_main.c mutt-1.5.13/curs_main.c
1652 --- mutt-1.5.13.orig/curs_main.c        2006-06-08 14:50:29.000000000 +0300
1653 +++ mutt-1.5.13/curs_main.c     2006-08-15 13:04:56.000000000 +0300
1654 @@ -22,6 +22,7 @@
1655  
1656  #include "mutt.h"
1657  #include "mutt_curses.h"
1658 +#include "mx.h"
1659  #include "mutt_menu.h"
1660  #include "attach.h"
1661  #include "mailbox.h"
1662 @@ -40,6 +41,10 @@
1663  
1664  #include "mutt_crypt.h"
1665  
1666 +#ifdef USE_NNTP
1667 +#include "nntp.h"
1668 +#endif
1669 +
1670  
1671  #include <ctype.h>
1672  #include <stdlib.h>
1673 @@ -415,12 +420,27 @@ struct mapping_t IndexHelp[] = {
1674    { NULL }
1675  };
1676  
1677 +#ifdef USE_NNTP
1678 +struct mapping_t IndexNewsHelp[] = {
1679 +  { N_("Quit"),     OP_QUIT },
1680 +  { N_("Del"),      OP_DELETE },
1681 +  { N_("Undel"),    OP_UNDELETE },
1682 +  { N_("Save"),     OP_SAVE },
1683 +  { N_("Post"),     OP_POST },
1684 +  { N_("Followup"), OP_FOLLOWUP },
1685 +  { N_("Catchup"),  OP_CATCHUP },
1686 +  { N_("Help"),     OP_HELP },
1687 +  { NULL }
1688 +};
1689 +#endif
1690 +
1691  /* This function handles the message index window as well as commands returned
1692   * from the pager (MENU_PAGER).
1693   */
1694  int mutt_index_menu (void)
1695  {
1696    char buf[LONG_STRING], helpstr[SHORT_STRING];
1697 +  int flags;
1698    int op = OP_NULL;
1699    int done = 0;                /* controls when to exit the "event" loop */
1700    int i = 0, j;
1701 @@ -442,7 +462,11 @@ int mutt_index_menu (void)
1702    menu->make_entry = index_make_entry;
1703    menu->color = index_color;
1704    menu->current = ci_first_message ();
1705 -  menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN, IndexHelp);
1706 +  menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1707 +#ifdef USE_NNTP
1708 +       (Context && (Context->magic == M_NNTP)) ? IndexNewsHelp :
1709 +#endif
1710 +       IndexHelp);
1711    
1712    if (!attach_msg) 
1713      mutt_buffy_check(1); /* force the buffy check after we enter the folder */
1714 @@ -694,6 +718,9 @@ int mutt_index_menu (void)
1715        mutt_curs_set (1);       /* fallback from the pager */
1716      }
1717  
1718 +#ifdef USE_NNTP
1719 +    unset_option (OPTNEWS);    /* for any case */
1720 +#endif
1721      switch (op)
1722      {
1723  
1724 @@ -744,6 +771,120 @@ int mutt_index_menu (void)
1725         menu_current_bottom (menu);
1726         break;
1727  
1728 +#ifdef USE_NNTP
1729 +      case OP_GET_MESSAGE:
1730 +      case OP_GET_PARENT:
1731 +       CHECK_MSGCOUNT;
1732 +       if (Context->magic == M_NNTP)
1733 +       {
1734 +         HEADER *h;
1735 +
1736 +         if (op == OP_GET_MESSAGE)
1737 +         {
1738 +           buf[0] = 0;
1739 +           if (mutt_get_field (_("Enter Message-Id: "), buf, sizeof (buf), 0) != 0
1740 +                 || !buf[0])
1741 +             break;
1742 +         }
1743 +         else
1744 +         {
1745 +           LIST *ref = CURHDR->env->references;
1746 +           if (!ref)
1747 +           {
1748 +             mutt_error _("Article has no parent reference!");
1749 +             break;
1750 +           }
1751 +           strfcpy (buf, ref->data, sizeof (buf));
1752 +         }
1753 +         if (!Context->id_hash)
1754 +           Context->id_hash = mutt_make_id_hash (Context);
1755 +         if ((h = hash_find (Context->id_hash, buf)))
1756 +         {
1757 +           if (h->virtual != -1)
1758 +           {
1759 +             menu->current = h->virtual;
1760 +             menu->redraw = REDRAW_MOTION_RESYNCH;
1761 +           }
1762 +           else if (h->collapsed)
1763 +           {
1764 +             mutt_uncollapse_thread (Context, h);
1765 +             mutt_set_virtual (Context);
1766 +             menu->current = h->virtual;
1767 +             menu->redraw = REDRAW_MOTION_RESYNCH;
1768 +           }
1769 +           else
1770 +             mutt_error _("Message not visible in limited view.");
1771 +         }
1772 +         else
1773 +         {
1774 +           if (nntp_check_msgid (Context, buf) == 0)
1775 +           {
1776 +             h = Context->hdrs[Context->msgcount-1];
1777 +             mutt_sort_headers (Context, 0);
1778 +             menu->current = h->virtual;
1779 +             menu->redraw = REDRAW_FULL;
1780 +           }
1781 +           else
1782 +             mutt_error (_("Article %s not found on server"), buf); 
1783 +         }
1784 +       }
1785 +       break;
1786 +
1787 +      case OP_GET_CHILDREN:
1788 +      case OP_RECONSTRUCT_THREAD:
1789 +       CHECK_MSGCOUNT;
1790 +       if (Context->magic == M_NNTP)
1791 +       {
1792 +         HEADER *h;
1793 +         int old = CURHDR->index, i;
1794 +
1795 +         if (!CURHDR->env->message_id)
1796 +         {
1797 +           mutt_error _("No Message-Id. Unable to perform operation");
1798 +           break;
1799 +         }
1800 +
1801 +         if (!Context->id_hash)
1802 +           Context->id_hash = mutt_make_id_hash (Context);
1803 +         strfcpy (buf, CURHDR->env->message_id, sizeof (buf));
1804 +
1805 +         if (op == OP_RECONSTRUCT_THREAD)
1806 +         {
1807 +           LIST *ref = CURHDR->env->references;
1808 +           while (ref)
1809 +           {
1810 +             nntp_check_msgid (Context, ref->data);
1811 +             /* the last msgid in References is the root message */
1812 +             if (!ref->next)
1813 +               strfcpy (buf, ref->data, sizeof (buf));
1814 +             ref = ref->next;
1815 +           }
1816 +         }
1817 +         mutt_message _("Check for children of message...");
1818 +         if (nntp_check_children (Context, buf) == 0)
1819 +         {
1820 +           mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
1821 +           h = hash_find (Context->id_hash, buf);
1822 +           /* if the root message was retrieved, move to it */
1823 +           if (h)
1824 +             menu->current = h->virtual;
1825 +           else /* try to restore old position */
1826 +             for (i = 0; i < Context->msgcount; i++)
1827 +               if (Context->hdrs[i]->index == old)
1828 +               {
1829 +                 menu->current = Context->hdrs[i]->virtual;
1830 +                 /* As an added courtesy, recenter the menu
1831 +                  * with the current entry at the middle of the screen */
1832 +                 menu_check_recenter (menu);
1833 +                 menu_current_middle (menu);
1834 +               }
1835 +         }
1836 +         menu->redraw = REDRAW_FULL;
1837 +         mutt_clear_error ();
1838 +       }
1839 +       break;
1840 +#endif
1841 +
1842        case OP_JUMP:
1843  
1844         CHECK_MSGCOUNT;
1845 @@ -841,11 +982,33 @@ int mutt_index_menu (void)
1846          break;
1847  
1848        case OP_MAIN_LIMIT:
1849 +      case OP_TOGGLE_READ:
1850  
1851         CHECK_IN_MAILBOX;
1852         menu->oldcurrent = (Context->vcount && menu->current >= 0 && menu->current < Context->vcount) ?
1853                 CURHDR->index : -1;
1854 -       if (mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
1855 +       if (op == OP_TOGGLE_READ)
1856 +       {
1857 +         char buf[LONG_STRING];
1858 +
1859 +         if (!Context->pattern || strncmp (Context->pattern, "!~R!~D~s", 8) != 0)
1860 +         {
1861 +           snprintf (buf, sizeof (buf), "!~R!~D~s%s",
1862 +                     Context->pattern ? Context->pattern : ".*");
1863 +           set_option (OPTHIDEREAD);
1864 +         }
1865 +         else
1866 +         {
1867 +           strfcpy (buf, Context->pattern + 8, sizeof(buf));
1868 +           if (!*buf || strncmp (buf, ".*", 2) == 0)
1869 +             snprintf (buf, sizeof(buf), "~A");
1870 +           unset_option (OPTHIDEREAD);
1871 +         }
1872 +         FREE (&Context->pattern);
1873 +         Context->pattern = safe_strdup (buf);
1874 +       }
1875 +       if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
1876 +           mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
1877         {
1878           if (menu->oldcurrent >= 0)
1879           {
1880 @@ -1052,20 +1215,43 @@ int mutt_index_menu (void)
1881         break;
1882  
1883        case OP_MAIN_CHANGE_FOLDER:
1884 -      
1885 -       if (attach_msg)
1886 -         op = OP_MAIN_CHANGE_FOLDER_READONLY;
1887 -
1888 -       /* fallback to the readonly case */
1889 -
1890        case OP_MAIN_CHANGE_FOLDER_READONLY:
1891 +#ifdef USE_NNTP
1892 +      case OP_MAIN_CHANGE_GROUP:
1893 +      case OP_MAIN_CHANGE_GROUP_READONLY:
1894 +#endif
1895  
1896 -        if ((op == OP_MAIN_CHANGE_FOLDER_READONLY) || option (OPTREADONLY))
1897 +       if (attach_msg || option (OPTREADONLY) ||
1898 +#ifdef USE_NNTP
1899 +           op == OP_MAIN_CHANGE_GROUP_READONLY ||
1900 +#endif
1901 +           op == OP_MAIN_CHANGE_FOLDER_READONLY)
1902 +         flags = M_READONLY;
1903 +       else
1904 +         flags = 0;
1905 +
1906 +       if (flags)
1907            cp = _("Open mailbox in read-only mode");
1908          else
1909            cp = _("Open mailbox");
1910  
1911         buf[0] = '\0';
1912 +#ifdef USE_NNTP
1913 +       unset_option (OPTNEWS);
1914 +       if (op == OP_MAIN_CHANGE_GROUP ||
1915 +           op == OP_MAIN_CHANGE_GROUP_READONLY)
1916 +       {
1917 +         set_option (OPTNEWS);
1918 +         if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1919 +           break;
1920 +         if (flags)
1921 +           cp = _("Open newsgroup in read-only mode");
1922 +         else
1923 +           cp = _("Open newsgroup");
1924 +         nntp_buffy (buf);
1925 +       }
1926 +       else
1927 +#endif
1928         mutt_buffy (buf, sizeof (buf));
1929  
1930         if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1)
1931 @@ -1084,6 +1270,14 @@ int mutt_index_menu (void)
1932           break;
1933         }
1934  
1935 +#ifdef USE_NNTP
1936 +        if (option (OPTNEWS))
1937 +       {
1938 +         unset_option (OPTNEWS);
1939 +          nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1940 +       }
1941 +        else
1942 +#endif
1943         mutt_expand_path (buf, sizeof (buf));
1944         if (mx_get_magic (buf) <= 0)
1945         {
1946 @@ -1121,15 +1315,18 @@ int mutt_index_menu (void)
1947         CurrentMenu = MENU_MAIN;
1948         mutt_folder_hook (buf);
1949  
1950 -       if ((Context = mx_open_mailbox (buf, 
1951 -                                       (option (OPTREADONLY) || op == OP_MAIN_CHANGE_FOLDER_READONLY) ?
1952 -                                       M_READONLY : 0, NULL)) != NULL)
1953 +       if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL)
1954         {
1955           menu->current = ci_first_message ();
1956         }
1957         else
1958           menu->current = 0;
1959  
1960 +#ifdef USE_NNTP
1961 +       /* mutt_buffy_check() must be done with mail-reader mode! */
1962 +       menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1963 +         (Context && (Context->magic == M_NNTP)) ? IndexNewsHelp : IndexHelp);
1964 +#endif
1965         mutt_clear_error ();
1966         mutt_buffy_check(1); /* force the buffy check after we have changed
1967                               the folder */
1968 @@ -1509,6 +1706,15 @@ int mutt_index_menu (void)
1969         }
1970  #endif
1971  
1972 +#ifdef USE_NNTP
1973 +       if (Context->magic == M_NNTP)
1974 +       {
1975 +         mutt_flushinp ();
1976 +         mutt_error _("Can't change 'important' flag on NNTP server.");
1977 +         break;
1978 +       }
1979 +#endif
1980 +
1981          if (tag)
1982          {
1983           for (j = 0; j < Context->vcount; j++)
1984 @@ -1856,6 +2062,17 @@ int mutt_index_menu (void)
1985         }
1986         break;
1987  
1988 +#ifdef USE_NNTP
1989 +      case OP_CATCHUP:
1990 +       if (Context && Context->magic == M_NNTP)
1991 +       {
1992 +         if (mutt_newsgroup_catchup (CurrentNewsSrv,
1993 +               ((NNTP_DATA *)Context->data)->group))
1994 +           menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1995 +       }
1996 +       break;
1997 +#endif
1998 +
1999        case OP_DISPLAY_ADDRESS:
2000  
2001         CHECK_MSGCOUNT;
2002 @@ -1890,6 +2107,15 @@ int mutt_index_menu (void)
2003           break;
2004         }
2005  #endif
2006 +  
2007 +#ifdef USE_NNTP
2008 +       if (Context->magic == M_NNTP)
2009 +       {
2010 +         mutt_flushinp ();
2011 +         mutt_error _("Can't edit message on newsserver.");
2012 +         break;
2013 +       }
2014 +#endif
2015  
2016         if (option (OPTPGPAUTODEC) && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))) 
2017           mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2018 @@ -2063,6 +2289,37 @@ int mutt_index_menu (void)
2019        
2020          menu->redraw = REDRAW_FULL;
2021          break;
2022 +
2023 +#ifdef USE_NNTP
2024 +      case OP_POST:
2025 +      case OP_FOLLOWUP:
2026 +      case OP_FORWARD_TO_GROUP:
2027 +
2028 +       CHECK_ATTACH;
2029 +       if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2030 +           mutt_strcasecmp (CURHDR->env->followup_to, "poster") ||
2031 +           query_quadoption (OPT_FOLLOWUPTOPOSTER,_("Reply by mail as poster prefers?")) != M_YES)
2032 +       {
2033 +         if (Context && Context->magic == M_NNTP &&
2034 +             !((NNTP_DATA *)Context->data)->allowed &&
2035 +             query_quadoption (OPT_TOMODERATED, _("Posting to this group not allowed, may be moderated. Continue?")) != M_YES)
2036 +           break;
2037 +         if (op == OP_POST)
2038 +           ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2039 +         else
2040 +         {
2041 +           CHECK_MSGCOUNT;
2042 +           if (op == OP_FOLLOWUP)
2043 +             ci_send_message (SENDNEWS|SENDREPLY, NULL, NULL, Context,
2044 +                              tag ? NULL : CURHDR);
2045 +           else
2046 +             ci_send_message (SENDNEWS|SENDFORWARD, NULL, NULL, Context,
2047 +                              tag ? NULL : CURHDR);
2048 +         }
2049 +         menu->redraw = REDRAW_FULL;
2050 +         break;
2051 +       }
2052 +#endif
2053        
2054        case OP_REPLY:
2055  
2056 @@ -2136,6 +2393,12 @@ int mutt_index_menu (void)
2057         CHECK_READONLY;
2058         CHECK_IMAP_ACL(IMAP_ACL_DELETE);
2059  
2060 +#ifdef USE_NNTP
2061 +       /* Close all open NNTP connections */
2062 +       if (!attach_msg)
2063 +         nntp_logout_all ();
2064 +#endif
2065 +
2066         rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2067                                    op == OP_UNDELETE_THREAD ? 0 : 1);
2068  
2069 diff -udprP mutt-1.5.13.orig/doc/manual.xml.head mutt-1.5.13/doc/manual.xml.head
2070 --- mutt-1.5.13.orig/doc/manual.xml.head        2006-08-11 12:23:28.000000000 +0300
2071 +++ mutt-1.5.13/doc/manual.xml.head     2006-08-15 13:04:56.000000000 +0300
2072 @@ -1204,6 +1204,22 @@ have a look at the mixmaster documentati
2073  
2074  </sect2>
2075  
2076 +<sect2>
2077 +<title>Reading news via NNTP</title>
2078 +
2079 +<para>
2080 +If compiled with <emphasis>--enable-nntp</emphasis> option, Mutt can
2081 +read news from newsserver via NNTP.  You can open a newsgroup with
2082 +function ``change-newsgroup'' (default: ``i'').  Default newsserver
2083 +can be obtained from <emphasis>NNTPSERVER</emphasis> environment
2084 +variable.  Like other news readers, info about subscribed newsgroups
2085 +is saved in file by <link linkend="newsrc">&dollar;newsrc</link>
2086 +variable.  Article headers are cached and can be loaded from file when
2087 +newsgroup entered instead loading from newsserver.
2088 +</para>
2089 +
2090 +</sect2>
2091 +
2092  </sect1>
2093  
2094  <sect1 id="forwarding-mail">
2095 diff -udprP mutt-1.5.13.orig/doc/mutt.man mutt-1.5.13/doc/mutt.man
2096 --- mutt-1.5.13.orig/doc/mutt.man       2005-09-18 11:22:22.000000000 +0300
2097 +++ mutt-1.5.13/doc/mutt.man    2006-08-15 13:04:56.000000000 +0300
2098 @@ -23,8 +23,8 @@ mutt \- The Mutt Mail User Agent
2099  .SH SYNOPSIS
2100  .PP
2101  .B mutt
2102 -[-nRyzZ] 
2103 -[-e \fIcmd\fP] [-F \fIfile\fP] [-m \fItype\fP] [-f \fIfile\fP]
2104 +[-GnRyzZ] 
2105 +[-e \fIcmd\fP] [-F \fIfile\fP] [-g \fIserver\fP] [-m \fItype\fP] [-f \fIfile\fP]
2106  .PP
2107  .B mutt 
2108  [-nx] 
2109 @@ -75,6 +75,10 @@ files.
2110  Specify which mailbox to load.
2111  .IP "-F \fImuttrc\fP"
2112  Specify an initialization file to read instead of ~/.muttrc
2113 +.IP "-g \fIserver\fP"
2114 +Start Mutt with a listing of subscribed newsgroups at specified newsserver.
2115 +.IP "-G"
2116 +Start Mutt with a listing of subscribed newsgroups.
2117  .IP "-h"
2118  Display help.
2119  .IP "-H \fIdraft\fP"
2120 diff -udprP mutt-1.5.13.orig/functions.h mutt-1.5.13/functions.h
2121 --- mutt-1.5.13.orig/functions.h        2005-09-18 11:22:21.000000000 +0300
2122 +++ mutt-1.5.13/functions.h     2006-08-15 13:04:56.000000000 +0300
2123 @@ -72,6 +72,10 @@ struct binding_t OpMain[] = {
2124    { "break-thread",            OP_MAIN_BREAK_THREAD,           "#" },
2125    { "change-folder",           OP_MAIN_CHANGE_FOLDER,          "c" },
2126    { "change-folder-readonly",  OP_MAIN_CHANGE_FOLDER_READONLY, "\033c" },
2127 +#ifdef USE_NNTP
2128 +  { "change-newsgroup",                OP_MAIN_CHANGE_GROUP,           "i" },
2129 +  { "change-newsgroup-readonly",OP_MAIN_CHANGE_GROUP_READONLY, "\033i" },
2130 +#endif
2131    { "collapse-thread",         OP_MAIN_COLLAPSE_THREAD,        "\033v" },
2132    { "collapse-all",            OP_MAIN_COLLAPSE_ALL,           "\033V" },
2133    { "copy-message",            OP_COPY_MESSAGE,                "C" },
2134 @@ -84,7 +88,15 @@ struct binding_t OpMain[] = {
2135    { "edit",                    OP_EDIT_MESSAGE,                "e" },
2136    { "edit-type",               OP_EDIT_TYPE,                   "\005" },
2137    { "forward-message",         OP_FORWARD_MESSAGE,             "f" },
2138 -  { "flag-message",            OP_FLAG_MESSAGE,                "F" },
2139 +#ifdef USE_NNTP
2140 +  { "forward-to-group",                OP_FORWARD_TO_GROUP,            "\033F" },
2141 +  { "followup-message",                OP_FOLLOWUP,                    "F" },
2142 +  { "get-children",            OP_GET_CHILDREN,                NULL },
2143 +  { "get-message",             OP_GET_MESSAGE,                 "\007" },
2144 +  { "get-parent",              OP_GET_PARENT,                  "\033G" },
2145 +  { "reconstruct-thread",      OP_RECONSTRUCT_THREAD,          NULL },
2146 +#endif
2147 +  { "flag-message",            OP_FLAG_MESSAGE,                "\033f" },
2148    { "group-reply",             OP_GROUP_REPLY,                 "g" },
2149  #ifdef USE_POP
2150    { "fetch-mail",              OP_MAIN_FETCH_MAIL,             "G" },
2151 @@ -110,6 +122,9 @@ struct binding_t OpMain[] = {
2152    { "sort-mailbox",            OP_SORT,                        "o" },
2153    { "sort-reverse",            OP_SORT_REVERSE,                "O" },
2154    { "print-message",           OP_PRINT,                       "p" },
2155 +#ifdef USE_NNTP
2156 +  { "post-message",            OP_POST,                        "P" },
2157 +#endif
2158    { "previous-thread",         OP_MAIN_PREV_THREAD,            "\020" },
2159    { "previous-subthread",      OP_MAIN_PREV_SUBTHREAD,         "\033p" },
2160    { "recall-message",          OP_RECALL_MESSAGE,              "R" },
2161 @@ -129,6 +144,10 @@ struct binding_t OpMain[] = {
2162    { "show-version",            OP_VERSION,                     "V" },
2163    { "set-flag",                        OP_MAIN_SET_FLAG,               "w" },
2164    { "clear-flag",              OP_MAIN_CLEAR_FLAG,             "W" },
2165 +  { "toggle-read",             OP_TOGGLE_READ,                 "X" },
2166 +#ifdef USE_NNTP
2167 +  { "catchup",                 OP_CATCHUP,                     "y" },
2168 +#endif
2169    { "display-message",         OP_DISPLAY_MESSAGE,             M_ENTER_S },
2170    { "buffy-list",              OP_BUFFY_LIST,                  "." },
2171    { "sync-mailbox",            OP_MAIN_SYNC_FOLDER,            "$" },
2172 @@ -140,7 +159,7 @@ struct binding_t OpMain[] = {
2173    { "previous-new-then-unread",        OP_MAIN_PREV_NEW_THEN_UNREAD,   "\033\t" },
2174    { "next-unread",             OP_MAIN_NEXT_UNREAD,            NULL },
2175    { "previous-unread",         OP_MAIN_PREV_UNREAD,            NULL },
2176 -  { "parent-message",          OP_MAIN_PARENT_MESSAGE,         "P" },
2177 +  { "parent-message",          OP_MAIN_PARENT_MESSAGE,         NULL },
2178  
2179  
2180    { "extract-keys",            OP_EXTRACT_KEYS,                "\013" },
2181 @@ -160,6 +179,10 @@ struct binding_t OpPager[] = {
2182    { "bounce-message",  OP_BOUNCE_MESSAGE,              "b" },
2183    { "change-folder",   OP_MAIN_CHANGE_FOLDER,          "c" },
2184    { "change-folder-readonly",  OP_MAIN_CHANGE_FOLDER_READONLY, "\033c" },
2185 +#ifdef USE_NNTP
2186 +  { "change-newsgroup",                OP_MAIN_CHANGE_GROUP,           "i" },
2187 +  { "change-newsgroup-readonly",OP_MAIN_CHANGE_GROUP_READONLY, "\033i" },
2188 +#endif
2189    { "copy-message",    OP_COPY_MESSAGE,                "C" },
2190    { "decode-copy",     OP_DECODE_COPY,                 "\033C" },
2191    { "delete-message",  OP_DELETE,                      "d" },
2192 @@ -167,8 +190,12 @@ struct binding_t OpPager[] = {
2193    { "delete-subthread",        OP_DELETE_SUBTHREAD,            "\033d" },
2194    { "edit",            OP_EDIT_MESSAGE,                "e" },
2195    { "edit-type",       OP_EDIT_TYPE,                   "\005" },
2196 +#ifdef USE_NNTP
2197 +  { "followup-message",        OP_FOLLOWUP,                    "F" },
2198 +  { "forward-to-group",        OP_FORWARD_TO_GROUP,            "\033F" },
2199 +#endif
2200    { "forward-message", OP_FORWARD_MESSAGE,             "f" },
2201 -  { "flag-message",    OP_FLAG_MESSAGE,                "F" },
2202 +  { "flag-message",    OP_FLAG_MESSAGE,                "\033f" },
2203    { "group-reply",     OP_GROUP_REPLY,                 "g" },
2204  #ifdef USE_IMAP
2205    { "imap-fetch-mail",  OP_MAIN_IMAP_FETCH,            NULL },
2206 @@ -187,6 +214,9 @@ struct binding_t OpPager[] = {
2207    { "next-thread",     OP_MAIN_NEXT_THREAD,            "\016" },
2208    { "next-subthread",  OP_MAIN_NEXT_SUBTHREAD,         "\033n" },
2209    { "print-message",   OP_PRINT,                       "p" },
2210 +#ifdef USE_NNTP
2211 +  { "post-message",    OP_POST,                        "P" },
2212 +#endif
2213    { "previous-thread", OP_MAIN_PREV_THREAD,            "\020" },
2214    { "previous-subthread",OP_MAIN_PREV_SUBTHREAD,       "\033p" },
2215    { "quit",            OP_QUIT,                        "Q" },
2216 @@ -234,7 +264,7 @@ struct binding_t OpPager[] = {
2217    { "half-down",       OP_HALF_DOWN,                   NULL },
2218    { "previous-line",   OP_PREV_LINE,                   NULL },
2219    { "bottom",          OP_PAGER_BOTTOM,                NULL },
2220 -  { "parent-message",  OP_MAIN_PARENT_MESSAGE,         "P" },
2221 +  { "parent-message",  OP_MAIN_PARENT_MESSAGE,         NULL },
2222  
2223  
2224  
2225 @@ -254,6 +284,10 @@ struct binding_t OpAttach[] = {
2226    { "bounce-message",  OP_BOUNCE_MESSAGE,              "b" },
2227    { "display-toggle-weed",     OP_DISPLAY_HEADERS,     "h" },
2228    { "edit-type",       OP_EDIT_TYPE,                   "\005" },
2229 +#ifdef USE_NNTP
2230 +  { "followup-message",        OP_FOLLOWUP,                    "F" },
2231 +  { "forward-to-group",        OP_FORWARD_TO_GROUP,            "\033F" },
2232 +#endif
2233    { "print-entry",     OP_PRINT,                       "p" },
2234    { "save-entry",      OP_SAVE,                        "s" },
2235    { "pipe-entry",      OP_PIPE,                        "|" },
2236 @@ -279,6 +313,7 @@ struct binding_t OpAttach[] = {
2237  struct binding_t OpCompose[] = {
2238    { "attach-file",     OP_COMPOSE_ATTACH_FILE,         "a" },
2239    { "attach-message",  OP_COMPOSE_ATTACH_MESSAGE,      "A" },
2240 +  { "attach-news-message",OP_COMPOSE_ATTACH_NEWS_MESSAGE,"\033a" },
2241    { "edit-bcc",                OP_COMPOSE_EDIT_BCC,            "b" },
2242    { "edit-cc",         OP_COMPOSE_EDIT_CC,             "c" },
2243    { "copy-file",       OP_SAVE,                        "C" },
2244 @@ -298,6 +333,11 @@ struct binding_t OpCompose[] = {
2245    { "print-entry",     OP_PRINT,                       "l" },
2246    { "edit-mime",       OP_COMPOSE_EDIT_MIME,           "m" },
2247    { "new-mime",                OP_COMPOSE_NEW_MIME,            "n" },
2248 +#ifdef USE_NNTP
2249 +  { "edit-newsgroups", OP_COMPOSE_EDIT_NEWSGROUPS,     "N" },
2250 +  { "edit-followup-to",        OP_COMPOSE_EDIT_FOLLOWUP_TO,    "o" },
2251 +  { "edit-x-comment-to",OP_COMPOSE_EDIT_X_COMMENT_TO,  "x" },
2252 +#endif
2253    { "postpone-message",        OP_COMPOSE_POSTPONE_MESSAGE,    "P" },
2254    { "edit-reply-to",   OP_COMPOSE_EDIT_REPLY_TO,       "r" },
2255    { "rename-file",     OP_COMPOSE_RENAME_FILE,         "R" },
2256 @@ -349,14 +389,25 @@ struct binding_t OpBrowser[] = {
2257    { "select-new",      OP_BROWSER_NEW_FILE,    "N" },
2258    { "check-new",       OP_CHECK_NEW,           NULL },
2259    { "toggle-mailboxes", OP_TOGGLE_MAILBOXES,   "\t" },
2260 +#ifdef USE_NNTP
2261 +  { "reload-active",   OP_LOAD_ACTIVE,         "g" },
2262 +  { "subscribe-pattern", OP_SUBSCRIBE_PATTERN, "S" },
2263 +  { "unsubscribe-pattern", OP_UNSUBSCRIBE_PATTERN, "U" },
2264 +  { "catchup",         OP_CATCHUP,             "y" },
2265 +  { "uncatchup",       OP_UNCATCHUP,           "Y" },
2266 +#endif
2267    { "view-file",       OP_BROWSER_VIEW_FILE,   " " },
2268    { "buffy-list",      OP_BUFFY_LIST,          "." },
2269  #ifdef USE_IMAP
2270    { "create-mailbox",   OP_CREATE_MAILBOX,      "C" },
2271    { "delete-mailbox",   OP_DELETE_MAILBOX,      "d" },
2272    { "rename-mailbox",   OP_RENAME_MAILBOX,      "r" },
2273 +#endif
2274 +#if defined USE_IMAP || defined USE_NNTP
2275    { "subscribe",       OP_BROWSER_SUBSCRIBE,   "s" },
2276    { "unsubscribe",     OP_BROWSER_UNSUBSCRIBE, "u" },
2277 +#endif
2278 +#ifdef USE_IMAP
2279    { "toggle-subscribed", OP_BROWSER_TOGGLE_LSUB, "T" },
2280  #endif
2281    { NULL,              0,                      NULL }
2282 diff -udprP mutt-1.5.13.orig/globals.h mutt-1.5.13/globals.h
2283 --- mutt-1.5.13.orig/globals.h  2006-08-11 12:07:12.000000000 +0300
2284 +++ mutt-1.5.13/globals.h       2006-08-15 13:04:56.000000000 +0300
2285 @@ -93,6 +93,15 @@ WHERE char *MixEntryFormat;
2286  #endif
2287  
2288  WHERE char *Muttrc INITVAL (NULL);
2289 +#ifdef USE_NNTP
2290 +WHERE char *NewsCacheDir;
2291 +WHERE char *GroupFormat;
2292 +WHERE char *Inews;
2293 +WHERE char *NewsServer;
2294 +WHERE char *NntpUser;
2295 +WHERE char *NntpPass;
2296 +WHERE char *NewsRc;
2297 +#endif
2298  WHERE char *Outbox;
2299  WHERE char *Pager;
2300  WHERE char *PagerFmt;
2301 @@ -183,6 +192,11 @@ extern unsigned char QuadOptions[];
2302  
2303  WHERE unsigned short Counter INITVAL (0);
2304  
2305 +#ifdef USE_NNTP
2306 +WHERE short NewsPollTimeout;
2307 +WHERE short NntpContext;
2308 +#endif
2309 +
2310  WHERE short ConnectTimeout;
2311  WHERE short HistSize;
2312  WHERE short MenuContext;
2313 diff -udprP mutt-1.5.13.orig/hash.c mutt-1.5.13/hash.c
2314 --- mutt-1.5.13.orig/hash.c     2006-05-18 21:44:29.000000000 +0300
2315 +++ mutt-1.5.13/hash.c  2006-08-15 13:04:56.000000000 +0300
2316 @@ -51,10 +51,35 @@ HASH *hash_create (int nelem)
2317    if (nelem == 0)
2318      nelem = 2;
2319    table->nelem = nelem;
2320 +  table->curnelem = 0;
2321    table->table = safe_calloc (nelem, sizeof (struct hash_elem *));
2322    return table;
2323  }
2324  
2325 +HASH *hash_resize (HASH *ptr, int nelem)
2326 +{
2327 +  HASH *table;
2328 +  struct hash_elem *elem, *tmp;
2329 +  int i;
2330 +
2331 +  table = hash_create (nelem);
2332 +
2333 +  for (i = 0; i < ptr->nelem; i++)
2334 +  {
2335 +    for (elem = ptr->table[i]; elem; )
2336 +    {
2337 +      tmp = elem;
2338 +      elem = elem->next;
2339 +      hash_insert (table, tmp->key, tmp->data, 1);
2340 +      FREE (&tmp);
2341 +    }
2342 +  }
2343 +  FREE (&ptr->table);
2344 +  FREE (&ptr);
2345 +
2346 +  return table;
2347 +}
2348 +
2349  /* table        hash table to update
2350   * key          key to hash on
2351   * data         data to associate with `key'
2352 @@ -74,6 +99,7 @@ int hash_insert (HASH * table, const cha
2353    {
2354      ptr->next = table->table[h];
2355      table->table[h] = ptr;
2356 +    table->curnelem++;
2357    }
2358    else
2359    {
2360 @@ -96,6 +122,7 @@ int hash_insert (HASH * table, const cha
2361      else
2362        table->table[h] = ptr;
2363      ptr->next = tmp;
2364 +    table->curnelem++;
2365    }
2366    return h;
2367  }
2368 @@ -126,6 +153,7 @@ void hash_delete_hash (HASH * table, int
2369        if (destroy)
2370         destroy (ptr->data);
2371        FREE (&ptr);
2372 +      table->curnelem--;
2373        
2374        ptr = *last;
2375      }
2376 diff -udprP mutt-1.5.13.orig/hash.h mutt-1.5.13/hash.h
2377 --- mutt-1.5.13.orig/hash.h     2005-09-18 11:22:22.000000000 +0300
2378 +++ mutt-1.5.13/hash.h  2006-08-15 13:04:56.000000000 +0300
2379 @@ -28,7 +28,7 @@ struct hash_elem
2380  
2381  typedef struct
2382  {
2383 -  int nelem;
2384 +  int nelem, curnelem;
2385    struct hash_elem **table;
2386  }
2387  HASH;
2388 @@ -40,6 +40,7 @@ HASH;
2389  HASH *hash_create (int nelem);
2390  int hash_string (const unsigned char *s, int n);
2391  int hash_insert (HASH * table, const char *key, void *data, int allow_dup);
2392 +HASH *hash_resize (HASH * table, int nelem);
2393  void *hash_find_hash (const HASH * table, int hash, const char *key);
2394  void hash_delete_hash (HASH * table, int hash, const char *key, const void *data,
2395                        void (*destroy) (void *));
2396 diff -udprP mutt-1.5.13.orig/hdrline.c mutt-1.5.13/hdrline.c
2397 --- mutt-1.5.13.orig/hdrline.c  2006-04-28 22:43:51.000000000 +0300
2398 +++ mutt-1.5.13/hdrline.c       2006-08-15 13:04:56.000000000 +0300
2399 @@ -205,6 +205,7 @@ int mutt_user_is_recipient (HEADER *h)
2400   * %E = number of messages in current thread
2401   * %f = entire from line
2402   * %F = like %n, unless from self
2403 + * %g = newsgroup name (if compiled with nntp support)
2404   * %i = message-id
2405   * %l = number of lines in the message
2406   * %L = like %F, except `lists' are displayed first
2407 @@ -218,6 +219,7 @@ int mutt_user_is_recipient (HEADER *h)
2408   * %T = $to_chars
2409   * %u = user (login) name of author
2410   * %v = first name of author, unless from self
2411 + * %W = where user is (organization)
2412   * %X = number of MIME attachments
2413   * %y = `x-label:' field (if present)
2414   * %Y = `x-label:' field (if present, tree unfolded, and != parent's x-label)
2415 @@ -455,6 +457,12 @@ hdr_format_str (char *dest,
2416  
2417        break;
2418  
2419 +#ifdef USE_NNTP
2420 +    case 'g':
2421 +      mutt_format_s (dest, destlen, prefix, hdr->env->newsgroups ? hdr->env->newsgroups : "");
2422 +      break;
2423 +#endif
2424 +
2425      case 'i':
2426        mutt_format_s (dest, destlen, prefix, hdr->env->message_id ? hdr->env->message_id : "<no.id>");
2427        break;
2428 @@ -631,6 +639,13 @@ hdr_format_str (char *dest,
2429        mutt_format_s (dest, destlen, prefix, buf2);
2430        break;
2431  
2432 +    case 'W':
2433 +      if (!optional)
2434 +       mutt_format_s (dest, destlen, prefix, hdr->env->organization ? hdr->env->organization : "");
2435 +      else if (!hdr->env->organization)
2436 +       optional = 0;
2437 +      break;
2438 +
2439      case 'Z':
2440      
2441        ch = ' ';
2442 diff -udprP mutt-1.5.13.orig/headers.c mutt-1.5.13/headers.c
2443 --- mutt-1.5.13.orig/headers.c  2006-04-20 19:46:28.000000000 +0300
2444 +++ mutt-1.5.13/headers.c       2006-08-15 13:04:56.000000000 +0300
2445 @@ -118,6 +118,9 @@ void mutt_edit_headers (const char *edit
2446    msg->env = n; n = NULL;
2447  
2448    if (!msg->env->in_reply_to)
2449 +#ifdef USE_NNTP
2450 +  if (!option (OPTNEWSSEND))
2451 +#endif
2452      mutt_free_list (&msg->env->references);
2453  
2454    mutt_expand_aliases_env (msg->env);
2455 diff -udprP mutt-1.5.13.orig/init.c mutt-1.5.13/init.c
2456 --- mutt-1.5.13.orig/init.c     2006-07-05 11:40:05.000000000 +0300
2457 +++ mutt-1.5.13/init.c  2006-08-15 13:04:56.000000000 +0300
2458 @@ -2839,6 +2839,28 @@ void mutt_init (int skip_sys_rc, LIST *c
2459    else
2460      Fqdn = safe_strdup(NONULL(Hostname));
2461  
2462 +#ifdef USE_NNTP
2463 +  {
2464 +    FILE *f;
2465 +    char *i;
2466 +
2467 +    if ((f = safe_fopen (SYSCONFDIR "/nntpserver", "r")))
2468 +    {
2469 +      buffer[0] = '\0';
2470 +      fgets (buffer, sizeof (buffer), f);
2471 +      p = &buffer;
2472 +      SKIPWS (p);
2473 +      i = p;
2474 +      while (*i && (*i != ' ') && (*i != '\t') && (*i != '\r') && (*i != '\n')) i++;
2475 +      *i = '\0';
2476 +      NewsServer = safe_strdup (p);
2477 +      fclose (f);
2478 +    }
2479 +  }
2480 +  if ((p = getenv ("NNTPSERVER")))
2481 +    NewsServer = safe_strdup (p);
2482 +#endif
2483 +
2484    if ((p = getenv ("MAIL")))
2485      Spoolfile = safe_strdup (p);
2486    else if ((p = getenv ("MAILDIR")))
2487 diff -udprP mutt-1.5.13.orig/init.h mutt-1.5.13/init.h
2488 --- mutt-1.5.13.orig/init.h     2006-08-11 12:04:04.000000000 +0300
2489 +++ mutt-1.5.13/init.h  2006-08-15 13:04:56.000000000 +0300
2490 @@ -215,6 +215,20 @@ struct option_t MuttVars[] = {
2491    ** If set, Mutt will prompt you for carbon-copy (Cc) recipients before
2492    ** editing the body of an outgoing message.
2493    */  
2494 +#ifdef USE_NNTP
2495 +  { "ask_follow_up",   DT_BOOL, R_NONE, OPTASKFOLLOWUP, 0 },
2496 +  /*
2497 +  ** .pp
2498 +  ** If set, Mutt will prompt you for follow-up groups before editing
2499 +  ** the body of an outgoing message.
2500 +  */  
2501 +  { "ask_x_comment_to",        DT_BOOL, R_NONE, OPTASKXCOMMENTTO, 0 },
2502 +  /*
2503 +  ** .pp
2504 +  ** If set, Mutt will prompt you for x-comment-to field before editing
2505 +  ** the body of an outgoing message.
2506 +  */  
2507 +#endif
2508    { "attach_format",   DT_STR,  R_NONE, UL &AttachFormat, UL "%u%D%I %t%4n %T%.40d%> [%.7m/%.10M, %.6e%?C?, %C?, %s] " },
2509    /*
2510    ** .pp
2511 @@ -318,6 +332,14 @@ struct option_t MuttVars[] = {
2512    ** follow these menus.  The option is disabled by default because many 
2513    ** visual terminals don't permit making the cursor invisible.
2514    */
2515 +#ifdef USE_NNTP
2516 +  { "catchup_newsgroup", DT_QUAD, R_NONE, OPT_CATCHUP, M_ASKYES },
2517 +  /*
2518 +  ** .pp
2519 +  ** If this variable is \fIset\fP, Mutt will mark all articles in newsgroup
2520 +  ** as read when you quit the newsgroup (catchup newsgroup).
2521 +  */
2522 +#endif
2523    { "charset",         DT_STR,  R_NONE, UL &Charset, UL 0 },
2524    /*
2525    ** .pp
2526 @@ -639,6 +661,16 @@ struct option_t MuttVars[] = {
2527    ** sent to both the list and your address, resulting in two copies
2528    ** of the same email for you.
2529    */
2530 +#ifdef USE_NNTP
2531 +  { "followup_to_poster", DT_QUAD, R_NONE, OPT_FOLLOWUPTOPOSTER, M_ASKYES },
2532 +  /*
2533 +  ** .pp
2534 +  ** If this variable is \fIset\fP and the keyword "poster" is present in
2535 +  ** \fIFollowup-To\fP header, follow-up to newsgroup function is not
2536 +  ** permitted.  The message will be mailed to the submitter of the
2537 +  ** message via mail.
2538 +  */
2539 +#endif
2540    { "force_name",      DT_BOOL, R_NONE, OPTFORCENAME, 0 },
2541    /*
2542    ** .pp
2543 @@ -710,6 +742,27 @@ struct option_t MuttVars[] = {
2544    ** a regular expression that will match the whole name so mutt will expand
2545    ** "Franklin" to "Franklin, Steve".
2546    */
2547 +#ifdef USE_NNTP
2548 +  { "group_index_format", DT_STR, R_BOTH, UL &GroupFormat, UL "%4C %M%N %5s  %-45.45f %d" },
2549 +  /*
2550 +  ** .pp
2551 +  ** This variable allows you to customize the newsgroup browser display to
2552 +  ** your personal taste.  This string is similar to ``$index_format'', but
2553 +  ** has its own set of printf()-like sequences:
2554 +  ** .pp
2555 +  ** .ts
2556 +  ** %C      current newsgroup number
2557 +  ** %d      description of newsgroup (becomes from server)
2558 +  ** %f      newsgroup name
2559 +  ** %M      - if newsgroup not allowed for direct post (moderated for example)
2560 +  ** %N      N if newsgroup is new, u if unsubscribed, blank otherwise
2561 +  ** %n      number of new articles in newsgroup
2562 +  ** %s      number of unread articles in newsgroup
2563 +  ** %>X     right justify the rest of the string and pad with character "X"
2564 +  ** %|X     pad to the end of the line with character "X"
2565 +  ** .te
2566 +  */
2567 +#endif
2568    { "hdr_format",      DT_SYN,  R_NONE, UL "index_format", 0 },
2569    /*
2570    */
2571 @@ -995,6 +1048,7 @@ struct option_t MuttVars[] = {
2572    ** .dt %E .dd number of messages in current thread
2573    ** .dt %f .dd entire From: line (address + real name)
2574    ** .dt %F .dd author name, or recipient name if the message is from you
2575 +  ** .dt %g .dd newsgroup name (if compiled with nntp support)
2576    ** .dt %H .dd spam attribute(s) of this message
2577    ** .dt %i .dd message-id of the current message
2578    ** .dt %l .dd number of lines in the message (does not work with maildir,
2579 @@ -1014,6 +1068,7 @@ struct option_t MuttVars[] = {
2580    ** .dt %T .dd the appropriate character from the $$to_chars string
2581    ** .dt %u .dd user (login) name of the author
2582    ** .dt %v .dd first name of the author, or the recipient if the message is from you
2583 +  ** .dt %W .dd name of organization of author (`organization:' field)
2584    ** .dt %X .dd number of attachments
2585    **            (please see the ``$attachments'' section for possible speed effects)
2586    ** .dt %y .dd `x-label:' field, if present
2587 @@ -1038,6 +1093,21 @@ struct option_t MuttVars[] = {
2588    ** .pp
2589    ** See also: ``$$to_chars''.
2590    */
2591 +#ifdef USE_NNTP
2592 +  { "inews",          DT_PATH, R_NONE, UL &Inews, UL "" },
2593 +  /*
2594 +  ** .pp
2595 +  ** If set, specifies the program and arguments used to deliver news posted
2596 +  ** by Mutt.  Otherwise, mutt posts article using current connection to
2597 +  ** news server.  The following printf-style sequence is understood:
2598 +  ** .pp
2599 +  ** .ts
2600 +  ** %s      newsserver name
2601 +  ** .te
2602 +  ** .pp
2603 +  ** Example: set inews="/usr/local/bin/inews -hS"
2604 +  */
2605 +#endif
2606    { "ispell",          DT_PATH, R_NONE, UL &Ispell, UL ISPELL },
2607    /*
2608    ** .pp
2609 @@ -1252,6 +1322,16 @@ struct option_t MuttVars[] = {
2610    ** be attached to the newly composed message if this option is set.
2611    */
2612  
2613 +#ifdef USE_NNTP
2614 +  { "mime_subject",   DT_BOOL, R_NONE, OPTMIMESUBJECT, 1 },
2615 +  /*
2616 +  ** .pp
2617 +  ** If \fIunset\fP, 8-bit ``subject:'' line in article header will not be
2618 +  ** encoded according to RFC2047 to base64.  This is useful when message
2619 +  ** is Usenet article, because MIME for news is nonstandard feature.
2620 +  */
2621 +#endif
2622 +
2623  #ifdef MIXMASTER
2624    { "mix_entry_format", DT_STR,  R_NONE, UL &MixEntryFormat, UL "%4n %c %-16s %a" },
2625    /*
2626 @@ -1322,6 +1402,77 @@ struct option_t MuttVars[] = {
2627     ** See also ``$$read_inc'' and ``$$write_inc''.
2628     */
2629  #endif  
2630 +#ifdef USE_NNTP
2631 +  { "news_cache_dir", DT_PATH, R_NONE, UL &NewsCacheDir, UL "~/.mutt" },
2632 +  /*
2633 +  ** .pp
2634 +  ** This variable pointing to directory where Mutt will save cached news
2635 +  ** articles headers in. If \fIunset\fP, headers will not be saved at all
2636 +  ** and will be reloaded each time when you enter to newsgroup.
2637 +  */
2638 +  { "news_server",    DT_STR,  R_NONE, UL &NewsServer, 0 },
2639 +  /*
2640 +  ** .pp
2641 +  ** This variable specifies domain name or address of NNTP server. It
2642 +  ** defaults to the newsserver specified in the environment variable
2643 +  ** $$$NNTPSERVER or contained in the file /etc/nntpserver.  You can also
2644 +  ** specify username and an alternative port for each newsserver, ie:
2645 +  ** .pp
2646 +  ** [nntp[s]://][username[:password]@]newsserver[:port]
2647 +  */
2648 +  { "newsrc",         DT_PATH, R_NONE, UL &NewsRc, UL "~/.newsrc" },
2649 +  /*
2650 +  ** .pp
2651 +  ** The file, containing info about subscribed newsgroups - names and
2652 +  ** indexes of read articles.  The following printf-style sequence
2653 +  ** is understood:
2654 +  ** .pp
2655 +  ** .ts
2656 +  ** %s      newsserver name
2657 +  ** .te
2658 +  */
2659 +  { "nntp_context",   DT_NUM,  R_NONE, UL &NntpContext, 1000 },
2660 +  /*
2661 +  ** .pp
2662 +  ** This variable defines number of articles which will be in index when
2663 +  ** newsgroup entered.  If active newsgroup have more articles than this
2664 +  ** number, oldest articles will be ignored.  Also controls how many
2665 +  ** articles headers will be saved in cache when you quit newsgroup.
2666 +  */
2667 +  { "nntp_load_description", DT_BOOL, R_NONE, OPTLOADDESC, 1 },
2668 +  /*
2669 +  ** .pp
2670 +  ** This variable controls whether or not descriptions for each newsgroup
2671 +  ** must be loaded when newsgroup is added to list (first time list
2672 +  ** loading or new newsgroup adding).
2673 +  */
2674 +  { "nntp_user",      DT_STR,  R_NONE, UL &NntpUser, UL "" },
2675 +  /*
2676 +  ** .pp
2677 +  ** Your login name on the NNTP server.  If \fIunset\fP and NNTP server requires
2678 +  ** authentification, Mutt will prompt you for your account name when you
2679 +  ** connect to newsserver.
2680 +  */
2681 +  { "nntp_pass",      DT_STR,  R_NONE, UL &NntpPass, UL "" },
2682 +  /*
2683 +  ** .pp
2684 +  ** Your password for NNTP account.
2685 +  */
2686 +  { "nntp_poll",      DT_NUM,  R_NONE, UL &NewsPollTimeout, 60 },
2687 +  /*
2688 +  ** .pp
2689 +  ** The time in seconds until any operations on newsgroup except post new
2690 +  ** article will cause recheck for new news.  If set to 0, Mutt will
2691 +  ** recheck newsgroup on each operation in index (stepping, read article,
2692 +  ** etc.).
2693 +  */
2694 +  { "nntp_reconnect", DT_QUAD, R_NONE, OPT_NNTPRECONNECT, M_ASKYES },
2695 +  /*
2696 +  ** .pp
2697 +  ** Controls whether or not Mutt will try to reconnect to newsserver when
2698 +  ** connection lost.
2699 +  */
2700 +#endif
2701    { "pager",           DT_PATH, R_NONE, UL &Pager, UL "builtin" },
2702    /*
2703    ** .pp
2704 @@ -2132,6 +2283,16 @@ struct option_t MuttVars[] = {
2705    { "post_indent_str",  DT_SYN,  R_NONE, UL "post_indent_string", 0 },
2706    /*
2707    */
2708 +#ifdef USE_NNTP
2709 +  { "post_moderated", DT_QUAD, R_NONE, OPT_TOMODERATED, M_ASKYES },
2710 +  /*
2711 +  ** .pp
2712 +  ** If set to \fIyes\fP, Mutt will post article to newsgroup that have
2713 +  ** not permissions to posting (e.g. moderated).  \fBNote:\fP if newsserver
2714 +  ** does not support posting to that newsgroup or totally read-only, that
2715 +  ** posting will not have an effect.
2716 +  */
2717 +#endif
2718    { "postpone",                DT_QUAD, R_NONE, OPT_POSTPONE, M_ASKYES },
2719    /*
2720    ** .pp
2721 @@ -2480,6 +2641,28 @@ struct option_t MuttVars[] = {
2722    ** Command to use when spawning a subshell.  By default, the user's login
2723    ** shell from /etc/passwd is used.
2724    */
2725 +#ifdef USE_NNTP
2726 +  { "save_unsubscribed",DT_BOOL, R_NONE, OPTSAVEUNSUB, 0 },
2727 +  /*
2728 +  ** .pp
2729 +  ** When \fIset\fP, info about unsubscribed newsgroups will be saved into
2730 +  ** ``newsrc'' file and into cache.
2731 +  */
2732 +  { "show_new_news",  DT_BOOL, R_NONE, OPTSHOWNEWNEWS, 1 },
2733 +  /*
2734 +  ** .pp
2735 +  ** If \fIset\fP, newsserver will be asked for new newsgroups on entering
2736 +  ** the browser.  Otherwise, it will be done only once for a newsserver.
2737 +  ** Also controls whether or not number of new articles of subscribed
2738 +  ** newsgroups will be then checked.
2739 +  */
2740 +  { "show_only_unread",  DT_BOOL, R_NONE, OPTSHOWONLYUNREAD, 0 },
2741 +  /*
2742 +  ** .pp
2743 +  ** If \fIset\fP, only subscribed newsgroups that contain unread articles
2744 +  ** will be displayed in browser.
2745 +  */
2746 +#endif
2747    { "sig_dashes",      DT_BOOL, R_NONE, OPTSIGDASHES, 1 },
2748    /*
2749    ** .pp
2750 @@ -2939,6 +3122,14 @@ struct option_t MuttVars[] = {
2751    ** Controls whether mutt writes out the Bcc header when preparing
2752    ** messages to be sent.  Exim users may wish to unset this.
2753    */
2754 +#ifdef USE_NNTP
2755 +  { "x_comment_to",   DT_BOOL, R_NONE, OPTXCOMMENTTO, 0 },
2756 +  /*
2757 +  ** .pp
2758 +  ** If \fIset\fP, Mutt will add ``X-Comment-To:'' field (that contains full
2759 +  ** name of original article author) to article that followuped to newsgroup.
2760 +  */
2761 +#endif
2762    /*--*/
2763    { NULL }
2764  };
2765 diff -udprP mutt-1.5.13.orig/keymap.c mutt-1.5.13/keymap.c
2766 --- mutt-1.5.13.orig/keymap.c   2005-09-18 11:22:22.000000000 +0300
2767 +++ mutt-1.5.13/keymap.c        2006-08-15 13:04:56.000000000 +0300
2768 @@ -629,7 +629,6 @@ void km_init (void)
2769    km_bindkey ("<enter>", MENU_MAIN, OP_DISPLAY_MESSAGE);
2770  
2771    km_bindkey ("x", MENU_PAGER, OP_EXIT);
2772 -  km_bindkey ("i", MENU_PAGER, OP_EXIT);
2773    km_bindkey ("<backspace>", MENU_PAGER, OP_PREV_LINE);
2774    km_bindkey ("<pagedown>", MENU_PAGER, OP_NEXT_PAGE);
2775    km_bindkey ("<pageup>", MENU_PAGER, OP_PREV_PAGE);
2776 diff -udprP mutt-1.5.13.orig/mailbox.h mutt-1.5.13/mailbox.h
2777 --- mutt-1.5.13.orig/mailbox.h  2005-09-18 11:22:22.000000000 +0300
2778 +++ mutt-1.5.13/mailbox.h       2006-08-15 13:04:56.000000000 +0300
2779 @@ -74,6 +74,9 @@ int mx_is_imap (const char *);
2780  #ifdef USE_POP
2781  int mx_is_pop (const char *);
2782  #endif
2783 +#ifdef USE_NNTP
2784 +int mx_is_nntp (const char *);
2785 +#endif
2786  
2787  int mx_access (const char*, int);
2788  int mx_check_empty (const char *);
2789 diff -udprP mutt-1.5.13.orig/main.c mutt-1.5.13/main.c
2790 --- mutt-1.5.13.orig/main.c     2006-08-11 12:07:12.000000000 +0300
2791 +++ mutt-1.5.13/main.c  2006-08-15 13:04:56.000000000 +0300
2792 @@ -56,6 +56,10 @@
2793  #include <stringprep.h>
2794  #endif
2795  
2796 +#ifdef USE_NNTP
2797 +#include <nntp.h>
2798 +#endif
2799 +
2800  static const char *ReachingUs = N_("\
2801  To contact the developers, please mail to <mutt-dev@mutt.org>.\n\
2802  To report a bug, please visit http://bugs.mutt.org/.\n");
2803 @@ -127,6 +131,8 @@ options:\n\
2804  "  -e <command>\tspecify a command to be executed after initialization\n\
2805    -f <file>\tspecify which mailbox to read\n\
2806    -F <file>\tspecify an alternate muttrc file\n\
2807 +  -g <server>\tspecify a newsserver (if compiled with NNTP)\n\
2808 +  -G\t\tselect a newsgroup (if compiled with NNTP)\n\
2809    -H <file>\tspecify a draft file to read header and body from\n\
2810    -i <file>\tspecify a file which Mutt should include in the body\n\
2811    -m <type>\tspecify a default mailbox type\n\
2812 @@ -251,6 +257,12 @@ static void show_version (void)
2813         "-USE_POP  "
2814  #endif
2815  
2816 +#ifdef USE_NNTP
2817 +       "+USE_NNTP  "
2818 +#else
2819 +       "-USE_NNTP  "
2820 +#endif
2821 +
2822  #ifdef USE_IMAP
2823          "+USE_IMAP  "
2824  #else
2825 @@ -518,6 +530,9 @@ static void start_curses (void)
2826  #define M_NOSYSRC (1<<2)       /* -n */
2827  #define M_RO      (1<<3)       /* -R */
2828  #define M_SELECT  (1<<4)       /* -y */
2829 +#ifdef USE_NNTP
2830 +#define M_NEWS    (1<<5)       /* -g and -G */
2831 +#endif
2832  
2833  int main (int argc, char **argv)
2834  {
2835 @@ -566,7 +581,11 @@ int main (int argc, char **argv)
2836    memset (Options, 0, sizeof (Options));
2837    memset (QuadOptions, 0, sizeof (QuadOptions));
2838    
2839 +#ifdef USE_NNTP
2840 +  while ((i = getopt (argc, argv, "A:a:b:F:f:c:Dd:e:g:GH:s:i:hm:npQ:RvxyzZ")) != EOF)
2841 +#else
2842    while ((i = getopt (argc, argv, "A:a:b:F:f:c:Dd:e:H:s:i:hm:npQ:RvxyzZ")) != EOF)
2843 +#endif
2844      switch (i)
2845      {
2846        case 'A':
2847 @@ -659,6 +678,20 @@ int main (int argc, char **argv)
2848         flags |= M_SELECT;
2849         break;
2850  
2851 +#ifdef USE_NNTP
2852 +      case 'g': /* Specify a newsserver */
2853 +       {
2854 +         char buf[LONG_STRING];
2855 +
2856 +         snprintf (buf, sizeof (buf), "set news_server=%s", optarg);
2857 +         commands = mutt_add_list (commands, buf);
2858 +       }
2859 +
2860 +      case 'G': /* List of newsgroups */
2861 +       flags |= M_SELECT | M_NEWS;
2862 +       break;
2863 +#endif
2864 +
2865        case 'z':
2866         flags |= M_IGNORE;
2867         break;
2868 @@ -921,6 +954,18 @@ int main (int argc, char **argv)
2869      }
2870      else if (flags & M_SELECT)
2871      {
2872 +#ifdef USE_NNTP
2873 +      if (flags & M_NEWS)
2874 +      {
2875 +       set_option (OPTNEWS);
2876 +       if(!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
2877 +       {
2878 +         mutt_endwin (Errorbuf);
2879 +         exit (1);
2880 +       }
2881 +      }
2882 +      else
2883 +#endif
2884        if (!Incoming) {
2885         mutt_endwin _("No incoming mailboxes defined.");
2886         exit (1);
2887 @@ -936,6 +981,15 @@ int main (int argc, char **argv)
2888  
2889      if (!folder[0])
2890        strfcpy (folder, NONULL(Spoolfile), sizeof (folder));
2891 +
2892 +#ifdef USE_NNTP
2893 +    if (option (OPTNEWS))
2894 +    {
2895 +      unset_option (OPTNEWS);
2896 +      nntp_expand_path (folder, sizeof (folder), &CurrentNewsSrv->conn->account);
2897 +    }
2898 +    else
2899 +#endif
2900      mutt_expand_path (folder, sizeof (folder));
2901  
2902      mutt_str_replace (&CurrentFolder, folder);
2903 diff -udprP mutt-1.5.13.orig/mutt.h mutt-1.5.13/mutt.h
2904 --- mutt-1.5.13.orig/mutt.h     2006-08-11 12:22:15.000000000 +0300
2905 +++ mutt-1.5.13/mutt.h  2006-08-15 13:04:56.000000000 +0300
2906 @@ -240,6 +240,9 @@ enum
2907    M_PGP_KEY,
2908    M_XLABEL,
2909    M_MIMEATTACH,
2910 +#ifdef USE_NNTP
2911 +  M_NEWSGROUPS,
2912 +#endif
2913    
2914    /* Options for Mailcap lookup */
2915    M_EDIT,
2916 @@ -295,6 +298,12 @@ enum
2917  #endif
2918    OPT_SUBJECT,
2919    OPT_VERIFYSIG,      /* verify PGP signatures */
2920 +#ifdef USE_NNTP
2921 +  OPT_TOMODERATED,
2922 +  OPT_NNTPRECONNECT,
2923 +  OPT_CATCHUP,
2924 +  OPT_FOLLOWUPTOPOSTER,
2925 +#endif /* USE_NNTP */
2926      
2927    /* THIS MUST BE THE LAST VALUE. */
2928    OPT_MAX
2929 @@ -310,6 +319,7 @@ enum
2930  #define SENDMAILX      (1<<6)
2931  #define SENDKEY                (1<<7)
2932  #define SENDRESEND     (1<<8)
2933 +#define SENDNEWS       (1<<9)
2934  
2935  /* flags to _mutt_select_file() */
2936  #define M_SEL_BUFFY    (1<<0)
2937 @@ -329,6 +339,8 @@ enum
2938    OPTASCIICHARS,
2939    OPTASKBCC,
2940    OPTASKCC,
2941 +  OPTASKFOLLOWUP,
2942 +  OPTASKXCOMMENTTO,
2943    OPTATTACHSPLIT,
2944    OPTAUTOEDIT,
2945    OPTAUTOTAG,
2946 @@ -399,6 +411,9 @@ enum
2947    OPTMETOO,
2948    OPTMHPURGE,
2949    OPTMIMEFORWDECODE,
2950 +#ifdef USE_NNTP
2951 +  OPTMIMESUBJECT,      /* encode subject line with RFC2047 */
2952 +#endif
2953    OPTNARROWTREE,
2954    OPTPAGERSTOP,
2955    OPTPIPEDECODE,
2956 @@ -479,6 +494,16 @@ enum
2957    OPTPGPAUTOINLINE,
2958    OPTPGPREPLYINLINE,
2959  
2960 +  /* news options */
2961 +
2962 +#ifdef USE_NNTP
2963 +  OPTSHOWNEWNEWS,
2964 +  OPTSHOWONLYUNREAD,
2965 +  OPTSAVEUNSUB,
2966 +  OPTLOADDESC,
2967 +  OPTXCOMMENTTO,
2968 +#endif /* USE_NNTP */
2969 +
2970    /* pseudo options */
2971  
2972    OPTAUXSORT,          /* (pseudo) using auxillary sort function */
2973 @@ -499,6 +524,7 @@ enum
2974    OPTSORTSUBTHREADS,   /* (pseudo) used when $sort_aux changes */
2975    OPTNEEDRESCORE,      /* (pseudo) set when the `score' command is used */
2976    OPTATTACHMSG,                /* (pseudo) used by attach-message */
2977 +  OPTHIDEREAD,         /* (pseudo) whether or not hide read messages */
2978    OPTKEEPQUIET,                /* (pseudo) shut up the message and refresh
2979                          *          functions while we are executing an
2980                          *          external program.
2981 @@ -509,6 +535,12 @@ enum
2982    OPTDONTHANDLEPGPKEYS,        /* (pseudo) used to extract PGP keys */
2983    OPTUNBUFFEREDINPUT,   /* (pseudo) don't use key buffer */
2984  
2985 +#ifdef USE_NNTP
2986 +  OPTNEWS,             /* (pseudo) used to change reader mode */
2987 +  OPTNEWSSEND,         /* (pseudo) used to change behavior when posting */
2988 +  OPTNEWSCACHE,                /* (pseudo) used to indicate if news cache exist */
2989 +#endif
2990 +
2991    OPTMAX
2992  };
2993  
2994 @@ -586,6 +618,13 @@ typedef struct envelope
2995    char *supersedes;
2996    char *date;
2997    char *x_label;
2998 +  char *organization;
2999 +#ifdef USE_NNTP
3000 +  char *newsgroups;
3001 +  char *xref;
3002 +  char *followup_to;
3003 +  char *x_comment_to;
3004 +#endif
3005    BUFFER *spam;
3006    LIST *references;            /* message references (in reverse order) */
3007    LIST *in_reply_to;           /* in-reply-to header content */
3008 @@ -751,6 +790,9 @@ typedef struct header
3009    ENVELOPE *env;               /* envelope information */
3010    BODY *content;               /* list of MIME parts */
3011    char *path;
3012 +#ifdef USE_NNTP
3013 +  int article_num;
3014 +#endif
3015    
3016    char *tree;                  /* character string to print thread tree */
3017    struct thread *thread;
3018 @@ -766,7 +808,7 @@ typedef struct header
3019    int refno;                   /* message number on server */
3020  #endif
3021  
3022 -#if defined USE_POP || defined USE_IMAP
3023 +#if defined USE_POP || defined USE_IMAP || defined USE_NNTP
3024    void *data;                  /* driver-specific data */
3025  #endif
3026    
3027 @@ -857,7 +899,7 @@ typedef struct
3028    int deleted;                 /* how many deleted messages */
3029    int flagged;                 /* how many flagged messages */
3030    int msgnotreadyet;           /* which msg "new" in pager, -1 if none */
3031 -#if defined USE_POP || defined USE_IMAP
3032 +#if defined USE_POP || defined USE_IMAP || defined USE_NNTP
3033    void *data;                  /* driver specific data */
3034  #endif /* USE_IMAP */
3035  
3036 diff -udprP mutt-1.5.13.orig/muttlib.c mutt-1.5.13/muttlib.c
3037 --- mutt-1.5.13.orig/muttlib.c  2006-06-08 14:51:03.000000000 +0300
3038 +++ mutt-1.5.13/muttlib.c       2006-08-15 13:04:56.000000000 +0300
3039 @@ -286,7 +286,7 @@ void mutt_free_header (HEADER **h)
3040  #ifdef MIXMASTER
3041    mutt_free_list (&(*h)->chain);
3042  #endif
3043 -#if defined USE_POP || defined USE_IMAP
3044 +#if defined USE_POP || defined USE_IMAP || defined USE_NNTP
3045    FREE (&(*h)->data);
3046  #endif
3047    FREE (h);            /* __FREE_CHECKED__ */
3048 @@ -671,6 +671,13 @@ void mutt_free_envelope (ENVELOPE **p)
3049    FREE (&(*p)->supersedes);
3050    FREE (&(*p)->date);
3051    FREE (&(*p)->x_label);
3052 +  FREE (&(*p)->organization);
3053 +#ifdef USE_NNTP
3054 +  FREE (&(*p)->newsgroups);
3055 +  FREE (&(*p)->xref);
3056 +  FREE (&(*p)->followup_to);
3057 +  FREE (&(*p)->x_comment_to);
3058 +#endif
3059  
3060    mutt_buffer_free (&(*p)->spam);
3061  
3062 @@ -1275,6 +1282,14 @@ int mutt_save_confirm (const char *s, st
3063      }
3064    }
3065  
3066 +#ifdef USE_NNTP
3067 +  if (magic == M_NNTP)
3068 +  {
3069 +    mutt_error _("Can't save message to newsserver.");
3070 +    return 0;
3071 +  }
3072 +#endif
3073 +
3074    if (stat (s, st) != -1)
3075    {
3076      if (magic == -1)
3077 diff -udprP mutt-1.5.13.orig/mx.c mutt-1.5.13/mx.c
3078 --- mutt-1.5.13.orig/mx.c       2006-05-18 21:44:29.000000000 +0300
3079 +++ mutt-1.5.13/mx.c    2006-08-15 13:04:56.000000000 +0300
3080 @@ -38,6 +38,10 @@
3081  #include "pop.h"
3082  #endif
3083  
3084 +#ifdef USE_NNTP
3085 +#include "nntp.h"
3086 +#endif
3087 +
3088  #ifdef BUFFY_SIZE
3089  #include "buffy.h"
3090  #endif
3091 @@ -352,6 +356,22 @@ int mx_is_pop (const char *p)
3092  }
3093  #endif
3094  
3095 +#ifdef USE_NNTP
3096 +int mx_is_nntp (const char *p)
3097 +{
3098 +  url_scheme_t scheme;
3099 +
3100 +  if (!p)
3101 +    return 0;
3102 +
3103 +  scheme = url_check_scheme (p);
3104 +  if (scheme == U_NNTP || scheme == U_NNTPS)
3105 +    return 1;
3106 +
3107 +  return 0;
3108 +}
3109 +#endif
3110 +
3111  int mx_get_magic (const char *path)
3112  {
3113    struct stat st;
3114 @@ -369,6 +389,11 @@ int mx_get_magic (const char *path)
3115      return M_POP;
3116  #endif /* USE_POP */
3117  
3118 +#ifdef USE_NNTP
3119 +  if (mx_is_nntp (path))
3120 +    return M_NNTP;
3121 +#endif /* USE_NNTP */
3122 +
3123    if (stat (path, &st) == -1)
3124    {
3125      dprint (1, (debugfile, "mx_get_magic(): unable to stat %s: %s (errno %d).\n",
3126 @@ -705,6 +730,12 @@ CONTEXT *mx_open_mailbox (const char *pa
3127        break;
3128  #endif /* USE_POP */
3129  
3130 +#ifdef USE_NNTP
3131 +    case M_NNTP:
3132 +      rc = nntp_open_mailbox (ctx);
3133 +      break;
3134 +#endif /* USE_NNTP */
3135 +
3136      default:
3137        rc = -1;
3138        break;
3139 @@ -750,6 +781,10 @@ void mx_fastclose_mailbox (CONTEXT *ctx)
3140    if (ctx->magic == M_POP)
3141      pop_close_mailbox (ctx);
3142  #endif /* USE_POP */
3143 +#ifdef USE_NNTP
3144 +  if (ctx->magic == M_NNTP)
3145 +    nntp_fastclose_mailbox (ctx);
3146 +#endif /* USE_NNTP */
3147    if (ctx->subj_hash)
3148      hash_destroy (&ctx->subj_hash, NULL);
3149    if (ctx->id_hash)
3150 @@ -805,6 +840,12 @@ static int sync_mailbox (CONTEXT *ctx, i
3151        rc = pop_sync_mailbox (ctx, index_hint);
3152        break;
3153  #endif /* USE_POP */
3154 +
3155 +#ifdef USE_NNTP
3156 +    case M_NNTP:
3157 +      rc = nntp_sync_mailbox (ctx);
3158 +      break;
3159 +#endif /* USE_NNTP */
3160    }
3161  
3162  #if 0
3163 @@ -833,6 +874,16 @@ int mx_close_mailbox (CONTEXT *ctx, int 
3164  
3165    ctx->closing = 1;
3166  
3167 +#ifdef USE_NNTP
3168 +  if (ctx->magic == M_NNTP)
3169 +  {
3170 +    int ret;
3171 +
3172 +    ret = nntp_close_mailbox (ctx);
3173 +    mx_fastclose_mailbox (ctx);
3174 +    return ret;
3175 +  }
3176 +#endif
3177    if (ctx->readonly || ctx->dontwrite)
3178    {
3179      /* mailbox is readonly or we don't want to write */
3180 @@ -1370,6 +1421,11 @@ int mx_check_mailbox (CONTEXT *ctx, int 
3181        case M_POP:
3182         return (pop_check_mailbox (ctx, index_hint));
3183  #endif /* USE_POP */
3184 +
3185 +#ifdef USE_NNTP
3186 +      case M_NNTP:
3187 +       return (nntp_check_mailbox (ctx));
3188 +#endif /* USE_NNTP */
3189      }
3190    }
3191  
3192 @@ -1430,6 +1486,15 @@ MESSAGE *mx_open_message (CONTEXT *ctx, 
3193      }
3194  #endif /* USE_POP */
3195  
3196 +#ifdef USE_NNTP
3197 +    case M_NNTP:
3198 +    {
3199 +      if (nntp_fetch_message (msg, ctx, msgno) != 0)
3200 +       FREE (&msg);
3201 +      break;
3202 +    }
3203 +#endif /* USE_NNTP */
3204 +
3205      default:
3206        dprint (1, (debugfile, "mx_open_message(): function not implemented for mailbox type %d.\n", ctx->magic));
3207        FREE (&msg);
3208 @@ -1511,6 +1576,9 @@ int mx_close_message (MESSAGE **msg)
3209  #ifdef USE_POP
3210        || (*msg)->magic == M_POP
3211  #endif
3212 +#ifdef USE_NNTP
3213 +      || (*msg)->magic == M_NNTP
3214 +#endif
3215        )
3216    {
3217      r = safe_fclose (&(*msg)->fp);
3218 diff -udprP mutt-1.5.13.orig/mx.h mutt-1.5.13/mx.h
3219 --- mutt-1.5.13.orig/mx.h       2005-09-18 11:22:22.000000000 +0300
3220 +++ mutt-1.5.13/mx.h    2006-08-15 13:04:56.000000000 +0300
3221 @@ -40,6 +40,9 @@ enum
3222  #ifdef USE_POP
3223    , M_POP
3224  #endif
3225 +#ifdef USE_NNTP
3226 +  , M_NNTP
3227 +#endif
3228  };
3229  
3230  WHERE short DefaultMagic INITVAL (M_MBOX);
3231 diff -udprP mutt-1.5.13.orig/newsrc.c mutt-1.5.13/newsrc.c
3232 --- mutt-1.5.13.orig/newsrc.c   1970-01-01 03:00:00.000000000 +0300
3233 +++ mutt-1.5.13/newsrc.c        2006-08-15 13:04:56.000000000 +0300
3234 @@ -0,0 +1,1170 @@
3235 +/*
3236 + * Copyright (C) 1998 Brandon Long <blong@fiction.net>
3237 + * Copyright (C) 1999 Andrej Gritsenko <andrej@lucky.net>
3238 + * Copyright (C) 2000-2006 Vsevolod Volkov <vvv@mutt.org.ua>
3239 + * 
3240 + *     This program is free software; you can redistribute it and/or modify
3241 + *     it under the terms of the GNU General Public License as published by
3242 + *     the Free Software Foundation; either version 2 of the License, or
3243 + *     (at your option) any later version.
3244 + * 
3245 + *     This program is distributed in the hope that it will be useful,
3246 + *     but WITHOUT ANY WARRANTY; without even the implied warranty of
3247 + *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
3248 + *     GNU General Public License for more details.
3249 + * 
3250 + *     You should have received a copy of the GNU General Public License
3251 + *     along with this program; if not, write to the Free Software
3252 + *     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
3253 + */ 
3254 +
3255 +#if HAVE_CONFIG_H
3256 +# include "config.h"
3257 +#endif
3258 +
3259 +#include "mutt.h"
3260 +#include "mutt_curses.h"
3261 +#include "sort.h"
3262 +#include "mx.h"
3263 +#include "mime.h"
3264 +#include "mailbox.h"
3265 +#include "nntp.h"
3266 +#include "rfc822.h"
3267 +#include "rfc1524.h"
3268 +#include "rfc2047.h"
3269 +
3270 +#include <unistd.h>
3271 +#include <string.h>
3272 +#include <ctype.h>
3273 +#include <stdlib.h>
3274 +#include <sys/stat.h>
3275 +
3276 +void nntp_add_to_list (NNTP_SERVER *s, NNTP_DATA *d)
3277 +{
3278 +  LIST *l;
3279 +
3280 +  if (!s || !d)
3281 +    return;
3282 +
3283 +  l = safe_calloc (1, sizeof (LIST));
3284 +  if (s->list)
3285 +    s->tail->next = l;
3286 +  else
3287 +    s->list = l;
3288 +  s->tail = l;
3289 +  l->data = (void *) d;
3290 +}
3291 +
3292 +static int nntp_parse_newsrc_line (NNTP_SERVER *news, char *line)
3293 +{
3294 +  NNTP_DATA *data;
3295 +  char group[LONG_STRING];
3296 +  int x = 1;
3297 +  char *p = line, *b, *h;
3298 +  size_t len;
3299 +
3300 +  while (*p)
3301 +  {
3302 +    if (*p++ == ',')
3303 +      x++;
3304 +  }
3305 +
3306 +  p = line;
3307 +  while (*p && (*p != ':' && *p != '!')) p++;
3308 +  if (!*p)
3309 +    return -1;
3310 +  len = p + 1 - line;
3311 +  if (len > sizeof (group))
3312 +    len = sizeof (group);
3313 +  strfcpy (group, line, len);
3314 +  if ((data = (NNTP_DATA *)hash_find (news->newsgroups, group)) == NULL)
3315 +  {
3316 +    data = (NNTP_DATA *) safe_calloc (1, sizeof (NNTP_DATA) + strlen (group) + 1);
3317 +    data->group = (char *) data + sizeof (NNTP_DATA);
3318 +    strcpy (data->group, group);
3319 +    data->nserv = news;
3320 +    data->deleted = 1;
3321 +    if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
3322 +      news->newsgroups = hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
3323 +    hash_insert (news->newsgroups, data->group, data, 0);
3324 +    nntp_add_to_list (news, data);
3325 +  }
3326 +  else
3327 +    FREE ((void **) &data->entries);
3328 +
3329 +  data->rc = 1;
3330 +  data->entries = safe_calloc (x*2, sizeof (NEWSRC_ENTRY));
3331 +  data->max = x*2;
3332 +
3333 +  if (*p == ':')
3334 +    data->subscribed = 1;
3335 +  else
3336 +    data->subscribed = 0;
3337 +
3338 +  p++;
3339 +  b = p;
3340 +  x = 0;
3341 +  while (*b)
3342 +  {
3343 +    while (*p && *p != ',' && *p != '\n') p++;
3344 +    if (*p)
3345 +    {
3346 +      *p = '\0';
3347 +      p++;
3348 +    }
3349 +    if ((h = strchr(b, '-')))
3350 +    {
3351 +      *h = '\0';
3352 +      h++;
3353 +      data->entries[x].first = atoi(b);
3354 +      data->entries[x].last = atoi(h);
3355 +    }
3356 +    else
3357 +    {
3358 +      data->entries[x].first = atoi(b);
3359 +      data->entries[x].last = data->entries[x].first;
3360 +    }
3361 +    b = p;
3362 +    if (data->entries[x].last != 0)
3363 +      x++;
3364 +  }
3365 +  if (x && !data->lastMessage)
3366 +    data->lastMessage = data->entries[x-1].last;
3367 +  data->num = x;
3368 +  mutt_newsgroup_stat (data);
3369 +  dprint (2, (debugfile, "parse_line: Newsgroup %s\n", data->group));
3370 +  
3371 +  return 0;
3372 +}
3373 +
3374 +static int slurp_newsrc (NNTP_SERVER *news)
3375 +{
3376 +  FILE *fp;
3377 +  char *buf;
3378 +  struct stat sb;
3379 +
3380 +  news->stat = stat (news->newsrc, &sb);
3381 +  news->size = sb.st_size;
3382 +  news->mtime = sb.st_mtime;
3383 +
3384 +  if ((fp = safe_fopen (news->newsrc, "r")) == NULL)
3385 +    return -1;
3386 +  /* hmm, should we use dotlock? */
3387 +  if (mx_lock_file (news->newsrc, fileno (fp), 0, 0, 1))
3388 +  {
3389 +    fclose (fp);
3390 +    return -1;
3391 +  }
3392 +
3393 +  buf = safe_malloc (sb.st_size + 1);
3394 +  while (sb.st_size && fgets (buf, sb.st_size + 1, fp))
3395 +    nntp_parse_newsrc_line (news, buf);
3396 +  FREE (&buf);
3397 +
3398 +  mx_unlock_file (news->newsrc, fileno (fp), 0);
3399 +  fclose (fp);
3400 +  return 0;
3401 +}
3402 +
3403 +void nntp_cache_expand (char *dst, const char *src)
3404 +{
3405 +  snprintf (dst, _POSIX_PATH_MAX, "%s/%s", NewsCacheDir, src);
3406 +  mutt_expand_path (dst, _POSIX_PATH_MAX);
3407 +}
3408 +
3409 +/* Loads $news_cache_dir/.index into memory, loads newsserver data
3410 + * and newsgroup cache names */
3411 +static int nntp_parse_cacheindex (NNTP_SERVER *news)
3412 +{
3413 +  struct stat st;
3414 +  char buf[HUGE_STRING], *cp;
3415 +  char dir[_POSIX_PATH_MAX], file[_POSIX_PATH_MAX];
3416 +  FILE *index;
3417 +  NNTP_DATA *data;
3418 +  int l, m, t;
3419 +
3420 +  /* check is server name defined or not */
3421 +  if (!news || !news->conn || !news->conn->account.host)
3422 +    return -1;
3423 +  unset_option (OPTNEWSCACHE);
3424 +  if (!NewsCacheDir || !*NewsCacheDir)
3425 +    return 0;
3426 +
3427 +  strfcpy (dir, NewsCacheDir, sizeof (dir));
3428 +  mutt_expand_path (dir, sizeof(dir));
3429 +
3430 +  if (lstat (dir, &st) || (st.st_mode & S_IFDIR) == 0)
3431 +  {
3432 +    snprintf (buf, sizeof(buf), _("Directory %s not exist. Create it?"), dir);
3433 +    if (mutt_yesorno (buf, M_YES) != M_YES || mkdir (dir, (S_IRWXU+S_IRWXG+
3434 +         S_IRWXO)))
3435 +    {
3436 +      mutt_error _("Cache directory not created!");
3437 +      return -1;
3438 +    }
3439 +    mutt_clear_error();
3440 +  }
3441 +
3442 +  set_option (OPTNEWSCACHE);
3443 +
3444 +  FREE (&news->cache);
3445 +  snprintf (buf, sizeof(buf), "%s/.index", dir);
3446 +  if (!(index = safe_fopen (buf, "a+")))
3447 +    return 0;
3448 +  rewind (index);
3449 +  while (fgets (buf, sizeof(buf), index))
3450 +  {
3451 +    buf[strlen(buf) - 1] = 0;  /* strip ending '\n' */
3452 +    if (!mutt_strncmp (buf, "#: ", 3) &&
3453 +       !mutt_strcasecmp (buf+3, news->conn->account.host))
3454 +      break;
3455 +  }
3456 +  while (fgets (buf, sizeof(buf), index))
3457 +  {
3458 +    cp = buf;
3459 +    while (*cp && *cp != ' ') cp++;
3460 +    if (!*cp) continue;
3461 +    cp[0] = 0;
3462 +    if (!mutt_strcmp (buf, "#:"))
3463 +      break;
3464 +    sscanf (cp + 1, "%s %d %d", file, &l, &m);
3465 +    if (!mutt_strcmp (buf, "ALL"))
3466 +    {
3467 +      news->cache = safe_strdup (file);
3468 +      news->newgroups_time = m;
3469 +    }
3470 +    else if (news->newsgroups)
3471 +    {
3472 +      if ((data = (NNTP_DATA *)hash_find (news->newsgroups, buf)) == NULL)
3473 +      {
3474 +       data = (NNTP_DATA *) safe_calloc (1, sizeof (NNTP_DATA) + strlen (buf) + 1);
3475 +       data->group = (char *) data + sizeof (NNTP_DATA);
3476 +       strcpy(data->group, buf);
3477 +       data->nserv = news;
3478 +       data->deleted = 1;
3479 +       if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
3480 +         news->newsgroups = hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
3481 +       hash_insert (news->newsgroups, data->group, data, 0);
3482 +       nntp_add_to_list (news, data);
3483 +      }
3484 +      data->cache = safe_strdup (file);
3485 +      t = 0;
3486 +      if (!data->firstMessage || data->lastMessage < m)
3487 +       t = 1;
3488 +      if (!data->firstMessage)
3489 +       data->firstMessage = l;
3490 +      if (data->lastMessage < m)
3491 +       data->lastMessage = m;
3492 +      data->lastCached = m;
3493 +      if (t || !data->unread)
3494 +       mutt_newsgroup_stat (data);
3495 +    }
3496 +  }
3497 +  fclose (index);
3498 +  return 0;
3499 +}
3500 +
3501 +const char *
3502 +nntp_format_str (char *dest, size_t destlen, char op, const char *src,
3503 +               const char *fmt, const char *ifstring, const char *elsestring,
3504 +               unsigned long data, format_flag flags)
3505 +{
3506 +  char fn[SHORT_STRING], tmp[SHORT_STRING];
3507 +
3508 +  switch (op)
3509 +  {
3510 +    case 's':
3511 +      strncpy (fn, NewsServer, sizeof(fn) - 1);
3512 +      mutt_strlower (fn);
3513 +      snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
3514 +      snprintf (dest, destlen, tmp, fn);
3515 +      break;
3516 +  }
3517 +  return (src);
3518 +}
3519 +
3520 +/* nntp_parse_url: given an NNPT URL, return host, port,
3521 + * username, password and newsgroup will recognise. */
3522 +int nntp_parse_url (const char *server, ACCOUNT *acct,
3523 +                   char *group, size_t group_len)
3524 +{
3525 +  ciss_url_t url;
3526 +  char *c;
3527 +  int ret = -1;
3528 +
3529 +  /* Defaults */
3530 +  acct->flags = 0;
3531 +  acct->port = NNTP_PORT;
3532 +  acct->type = M_ACCT_TYPE_NNTP;
3533 +
3534 +  c = safe_strdup (server);
3535 +  url_parse_ciss (&url, c);
3536 +
3537 +  if (url.scheme == U_NNTP || url.scheme == U_NNTPS)
3538 +  {
3539 +    if (url.scheme == U_NNTPS)
3540 +    {
3541 +      acct->flags |= M_ACCT_SSL;
3542 +      acct->port = NNTP_SSL_PORT;
3543 +    }
3544 +
3545 +    *group = '\0';
3546 +    if (url.path)
3547 +      strfcpy (group, url.path, group_len);
3548 +
3549 +    ret = mutt_account_fromurl (acct, &url);
3550 +  }
3551 +
3552 +  FREE (&c);
3553 +  return ret;
3554 +}
3555 +
3556 +void nntp_expand_path (char *line, size_t len, ACCOUNT *acct)
3557 +{
3558 +  ciss_url_t url;
3559 +
3560 +  url.path = safe_strdup (line);
3561 +  mutt_account_tourl (acct, &url);
3562 +  url_ciss_tostring (&url, line, len, 0);
3563 +  FREE (&url.path);
3564 +}
3565 +
3566 +/*
3567 + * Automatically loads a newsrc into memory, if necessary.
3568 + * Checks the size/mtime of a newsrc file, if it doesn't match, load
3569 + * again.  Hmm, if a system has broken mtimes, this might mean the file
3570 + * is reloaded every time, which we'd have to fix.
3571 + *
3572 + * a newsrc file is a line per newsgroup, with the newsgroup, then a 
3573 + * ':' denoting subscribed or '!' denoting unsubscribed, then a 
3574 + * comma separated list of article numbers and ranges.
3575 + */
3576 +NNTP_SERVER *mutt_select_newsserver (char *server)
3577 +{
3578 +  char file[_POSIX_PATH_MAX];
3579 +  char *buf, *p;
3580 +  LIST *list;
3581 +  ACCOUNT acct;
3582 +  NNTP_SERVER *serv;
3583 +  CONNECTION *conn;
3584 +
3585 +  if (!server || !*server)
3586 +  {
3587 +    mutt_error _("No newsserver defined!");
3588 +    return NULL;
3589 +  }
3590 +
3591 +  buf = p = safe_calloc (strlen (server) + 10, sizeof (char));
3592 +  if (url_check_scheme (server) == U_UNKNOWN)
3593 +  {
3594 +    strcpy (buf, "nntp://");
3595 +    p = strchr (buf, '\0');
3596 +  }
3597 +  strcpy (p, server);
3598 +
3599 +  if ((nntp_parse_url (buf, &acct, file, sizeof (file))) < 0 || *file)
3600 +  {
3601 +    FREE (&buf);
3602 +    mutt_error (_("%s is an invalid newsserver specification!"), server);
3603 +    return NULL;
3604 +  }
3605 +  FREE (&buf);
3606 +
3607 +  conn = mutt_conn_find (NULL, &acct);
3608 +  if (!conn)
3609 +    return NULL;
3610 +
3611 +  mutt_FormatString (file, sizeof (file), NONULL (NewsRc), nntp_format_str, 0, 0);
3612 +  mutt_expand_path (file, sizeof (file));
3613 +
3614 +  serv = (NNTP_SERVER *)conn->data;
3615 +  if (serv)
3616 +  {
3617 +    struct stat sb;
3618 +
3619 +    /* externally modified? */
3620 +    if (serv->stat != stat (file, &sb) || (!serv->stat &&
3621 +       (serv->size != sb.st_size || serv->mtime != sb.st_mtime)))
3622 +    {
3623 +      for (list = serv->list; list; list = list->next)
3624 +      {
3625 +       NNTP_DATA *data = (NNTP_DATA *) list->data;
3626 +
3627 +       if (data)
3628 +       {
3629 +         data->subscribed = 0;
3630 +         data->rc = 0;
3631 +         data->num = 0;
3632 +       }
3633 +      }
3634 +      slurp_newsrc (serv);
3635 +      nntp_clear_cacheindex (serv);
3636 +    }
3637 +
3638 +    if (serv->status == NNTP_BYE)
3639 +      serv->status = NNTP_NONE;
3640 +    nntp_check_newgroups (serv, 0);
3641 +    return serv;
3642 +  }
3643 +
3644 +  /* New newsserver */
3645 +  serv = safe_calloc (1, sizeof (NNTP_SERVER));
3646 +  serv->conn = conn;
3647 +  serv->newsrc = safe_strdup (file);
3648 +  serv->newsgroups = hash_create (1009);
3649 +  slurp_newsrc (serv);                 /* load .newsrc */
3650 +  nntp_parse_cacheindex (serv);                /* load .index */
3651 +  if (option (OPTNEWSCACHE) && serv->cache && nntp_get_cache_all (serv) >= 0)
3652 +    nntp_check_newgroups (serv, 1);
3653 +  else if (nntp_get_active (serv) < 0)
3654 +  {
3655 +    hash_destroy (&serv->newsgroups, nntp_delete_data);
3656 +    for (list = serv->list; list; list = list->next)
3657 +      list->data = NULL;
3658 +    mutt_free_list (&serv->list);
3659 +    FREE (&serv->newsrc);
3660 +    FREE (&serv->cache);
3661 +    FREE (&serv);
3662 +    return NULL;
3663 +  }
3664 +  nntp_clear_cacheindex (serv);
3665 +  conn->data = (void *)serv;
3666 +
3667 +  return serv;
3668 +}
3669 +
3670 +/* 
3671 + * full status flags are not supported by nntp, but we can fake some
3672 + * of them.  This is how:
3673 + * Read = a read message number is in the .newsrc
3674 + * New = a message is new since we last read this newsgroup
3675 + * Old = anything else
3676 + * So, Read is marked as such in the newsrc, old is anything that is 
3677 + * "skipped" in the newsrc, and new is anything not in the newsrc nor
3678 + * in the cache. By skipped, I mean before the last unread message
3679 + */
3680 +void nntp_get_status (CONTEXT *ctx, HEADER *h, char *group, int article)
3681 +{
3682 +  NNTP_DATA *data = (NNTP_DATA *) ctx->data;
3683 +  int x;
3684 +
3685 +  if (group)
3686 +    data = (NNTP_DATA *) hash_find (data->nserv->newsgroups, group);
3687 +
3688 +  if (!data)
3689 +  {
3690 +#ifdef DEBUG
3691 +    if (group)
3692 +      dprint (3, (debugfile, "newsgroup %s not found\n", group));
3693 +#endif
3694 +    return;
3695 +  }
3696 +
3697 +  for (x = 0; x < data->num; x++)
3698 +  {
3699 +    if ((article >= data->entries[x].first) &&
3700 +       (article <= data->entries[x].last))
3701 +    {
3702 +      /* we cannot use mutt_set_flag() because mx_update_context()
3703 +        didn't called yet */
3704 +      h->read = 1;
3705 +      return;
3706 +    }
3707 +  }
3708 +  /* If article was not cached yet, it is new! :) */
3709 +  if (!data->cache || article > data->lastCached)
3710 +    return;
3711 +  /* Old articles are articles which aren't read but an article after them
3712 +   * has been cached */
3713 +  if (option (OPTMARKOLD))
3714 +    h->old = 1;
3715 +}
3716 +
3717 +void mutt_newsgroup_stat (NNTP_DATA *data)
3718 +{
3719 +  int i;
3720 +  unsigned int first, last;
3721 +
3722 +  data->unread = 0;
3723 +  if (data->lastMessage == 0 || data->firstMessage > data->lastMessage)
3724 +    return;
3725 +
3726 +  data->unread = data->lastMessage - data->firstMessage + 1;
3727 +  for (i = 0; i < data->num; i++)
3728 +  {
3729 +    first = data->entries[i].first;
3730 +    if (first < data->firstMessage)
3731 +      first = data->firstMessage;
3732 +    last = data->entries[i].last;
3733 +    if (last > data->lastMessage)
3734 +      last = data->lastMessage;
3735 +    if (first <= last)
3736 +      data->unread -= last - first + 1;
3737 +  }
3738 +}
3739 +
3740 +static int puti (char *line, int num)
3741 +{
3742 +  char *p, s[32];
3743 +
3744 +  for (p = s; num; )
3745 +  {
3746 +    *p++ = '0' + num % 10;
3747 +    num /= 10;
3748 +  }
3749 +  while (p > s)
3750 +    *line++ = *--p, num++;
3751 +  *line = '\0';
3752 +  return num;
3753 +}
3754 +
3755 +static void nntp_create_newsrc_line (NNTP_DATA *data, char **buf, char **pline, size_t *buflen)
3756 +{
3757 +  char *line = *pline;
3758 +  size_t len = *buflen - (*pline - *buf);
3759 +  int x, i;
3760 +
3761 +  if (len < LONG_STRING * 10)
3762 +  {
3763 +    len += *buflen;
3764 +    *buflen *= 2;
3765 +    line = *buf;
3766 +    safe_realloc (buf, *buflen);
3767 +    line = *buf + (*pline - line);
3768 +  }
3769 +  strcpy (line, data->group);
3770 +  len -= strlen (line) + 1;
3771 +  line += strlen (line);
3772 +  *line++ = data->subscribed ? ':' : '!';
3773 +  *line++ = ' ';
3774 +  *line = '\0';
3775 +
3776 +  for (x = 0; x < data->num; x++)
3777 +  {
3778 +    if (len < LONG_STRING)
3779 +    {
3780 +      len += *buflen;
3781 +      *buflen *= 2;
3782 +      *pline = line;
3783 +      line = *buf;
3784 +      safe_realloc (buf, *buflen);
3785 +      line = *buf + (*pline - line);
3786 +    }
3787 +    if (x)
3788 +    {
3789 +      *line++ = ',';
3790 +      len--;
3791 +    }
3792 +
3793 +#if 0
3794 +    if (data->entries[x].first == data->entries[x].last)
3795 +      snprintf (line, len, "%d%n", data->entries[x].first, &i);
3796 +    else
3797 +      snprintf (line, len, "%d-%d%n", 
3798 +           data->entries[x].first, data->entries[x].last, &i);
3799 +    len -= i;
3800 +    line += i;
3801 +#else
3802 +    i = puti (line, data->entries[x].first);
3803 +    line +=i; len -= i;
3804 +    if (data->entries[x].first != data->entries[x].last)
3805 +    {
3806 +      *line++ = '-';
3807 +      len--;
3808 +      i = puti (line, data->entries[x].last);
3809 +      line +=i; len -= i;
3810 +    }
3811 +#endif
3812 +  }
3813 +  *line++ = '\n';
3814 +  *line = '\0';
3815 +  *pline = line;
3816 +}
3817 +
3818 +void newsrc_gen_entries (CONTEXT *ctx)
3819 +{
3820 +  NNTP_DATA *data = (NNTP_DATA *)ctx->data;
3821 +  int series, x;
3822 +  unsigned int last = 0, first = 1;
3823 +  int save_sort = SORT_ORDER;
3824 +
3825 +  if (Sort != SORT_ORDER)
3826 +  {
3827 +    save_sort = Sort;
3828 +    Sort = SORT_ORDER;
3829 +    mutt_sort_headers (ctx, 0);
3830 +  }
3831 +
3832 +  if (!data->max)
3833 +  {
3834 +    data->entries = safe_calloc (5, sizeof (NEWSRC_ENTRY));
3835 +    data->max = 5;
3836 +  }
3837 +
3838 +  /*
3839 +   * Set up to fake initial sequence from 1 to the article before the 
3840 +   * first article in our list
3841 +   */
3842 +  data->num = 0;
3843 +  series = 1;
3844 +
3845 +  for (x = 0; x < ctx->msgcount; x++)
3846 +  {
3847 +    if (series) /* search for first unread */
3848 +    {
3849 +      /*
3850 +       * We don't actually check sequential order, since we mark 
3851 +       * "missing" entries as read/deleted
3852 +       */
3853 +      last = ctx->hdrs[x]->article_num;
3854 +      if (last >= data->firstMessage && !ctx->hdrs[x]->deleted &&
3855 +           !ctx->hdrs[x]->read)
3856 +      {
3857 +       if (data->num >= data->max)
3858 +       {
3859 +         data->max = data->max * 2;
3860 +         safe_realloc (&data->entries, 
3861 +             data->max * sizeof (NEWSRC_ENTRY));
3862 +       }
3863 +       data->entries[data->num].first = first;
3864 +       data->entries[data->num].last = last - 1;
3865 +       data->num++;
3866 +       series = 0;
3867 +      }
3868 +    }
3869 +    else /* search for first read */
3870 +    {
3871 +      if (ctx->hdrs[x]->deleted || ctx->hdrs[x]->read)
3872 +      {
3873 +       first = last + 1;
3874 +       series = 1;
3875 +      }
3876 +      last = ctx->hdrs[x]->article_num;
3877 +    }
3878 +  }
3879 +  if (series && first <= data->lastLoaded)
3880 +  {
3881 +    if (data->num >= data->max)
3882 +    {
3883 +      data->max = data->max * 2;
3884 +      safe_realloc (&data->entries, 
3885 +                   data->max * sizeof (NEWSRC_ENTRY));
3886 +    }
3887 +    data->entries[data->num].first = first;
3888 +    data->entries[data->num].last = data->lastLoaded;
3889 +    data->num++;
3890 +  }
3891 +
3892 +  if (save_sort != Sort)
3893 +  {
3894 +    Sort = save_sort;
3895 +    mutt_sort_headers (ctx, 0);
3896 +  }
3897 +}
3898 +
3899 +static int mutt_update_list_file (char *filename, char *section,
3900 +                                 char *key, char *line)
3901 +{
3902 +  FILE *ifp;
3903 +  FILE *ofp;
3904 +  char buf[HUGE_STRING];
3905 +  char tmpfile[_POSIX_PATH_MAX];
3906 +  char *c;
3907 +  int ext = 0, done = 0, r = 0;
3908 +
3909 +  /* if file not exist, create it */
3910 +  if ((ifp = safe_fopen (filename, "a")))
3911 +    fclose (ifp);
3912 +  dprint (1, (debugfile, "Opening %s\n", filename));
3913 +  if (!(ifp = safe_fopen (filename, "r")))
3914 +  {
3915 +    mutt_error (_("Unable to open %s for reading"), filename);
3916 +    return -1;
3917 +  }
3918 +  if (mx_lock_file (filename, fileno (ifp), 0, 0, 1))
3919 +  {
3920 +    fclose (ifp);
3921 +    mutt_error (_("Unable to lock %s"), filename);
3922 +    return -1;
3923 +  }
3924 +  snprintf (tmpfile, sizeof(tmpfile), "%s.tmp", filename);
3925 +  dprint (1, (debugfile, "Opening %s\n", tmpfile));
3926 +  if (!(ofp = fopen (tmpfile, "w")))
3927 +  {
3928 +    fclose (ifp);
3929 +    mutt_error (_("Unable to open %s for writing"), tmpfile);
3930 +    return -1;
3931 +  }
3932 +
3933 +  if (section)
3934 +  {
3935 +    while (r != EOF && !done && fgets (buf, sizeof (buf), ifp))
3936 +    {
3937 +      r = fputs (buf, ofp);
3938 +      c = buf;
3939 +      while (*c && *c != '\n') c++;
3940 +      c[0] = 0;        /* strip EOL */
3941 +      if (!strncmp (buf, "#: ", 3) && !mutt_strcasecmp (buf+3, section))
3942 +       done++;
3943 +    }
3944 +    if (r != EOF && !done)
3945 +    {
3946 +      snprintf (buf, sizeof(buf), "#: %s\n", section);
3947 +      r = fputs (buf, ofp);
3948 +    }
3949 +    done = 0;
3950 +  }
3951 +
3952 +  while (r != EOF && fgets (buf, sizeof (buf), ifp))
3953 +  {
3954 +    if (ext)
3955 +    {
3956 +      c = buf;
3957 +      while (*c && (*c != '\r') && (*c != '\n')) c++;
3958 +      c--;
3959 +      if (*c != '\\') ext = 0;
3960 +    }
3961 +    else if ((section && !strncmp (buf, "#: ", 3)))
3962 +    {
3963 +      if (!done && line)
3964 +      {
3965 +       fputs (line, ofp);
3966 +       fputc ('\n', ofp);
3967 +      }
3968 +      r = fputs (buf, ofp);
3969 +      done++;
3970 +      break;
3971 +    }
3972 +    else if (key && !strncmp (buf, key, strlen(key)) &&
3973 +           (!*key || buf[strlen(key)] == ' '))
3974 +    {
3975 +      c = buf;
3976 +      ext = 0;
3977 +      while (*c && (*c != '\r') && (*c != '\n')) c++;
3978 +      c--;
3979 +      if (*c == '\\') ext = 1;
3980 +      if (!done && line)
3981 +      {
3982 +       r = fputs (line, ofp);
3983 +       if (*key)
3984 +         r = fputc ('\n', ofp);
3985 +       done++;
3986 +      }
3987 +    }
3988 +    else
3989 +    {
3990 +      r = fputs (buf, ofp);
3991 +    }
3992 +  }
3993 +
3994 +  while (r != EOF && fgets (buf, sizeof (buf), ifp))
3995 +    r = fputs (buf, ofp);
3996 +
3997 +  /* If there wasn't a line to replace, put it on the end of the file */
3998 +  if (r != EOF && !done && line)
3999 +  {
4000 +    fputs (line, ofp);
4001 +    r = fputc ('\n', ofp);
4002 +  }
4003 +  mx_unlock_file (filename, fileno (ifp), 0);
4004 +  fclose (ofp);
4005 +  fclose (ifp);
4006 +  if (r == EOF)
4007 +  {
4008 +    unlink (tmpfile);
4009 +    mutt_error (_("Can't write %s"), tmpfile);
4010 +    return -1;
4011 +  }
4012 +  if (rename (tmpfile, filename) < 0)
4013 +  {
4014 +    unlink (tmpfile);
4015 +    mutt_error (_("Can't rename %s to %s"), tmpfile, filename);
4016 +    return -1;
4017 +  }
4018 +  return 0;
4019 +}
4020 +
4021 +int mutt_newsrc_update (NNTP_SERVER *news)
4022 +{
4023 +  char *buf, *line;
4024 +  NNTP_DATA *data;
4025 +  LIST *tmp;
4026 +  int r = -1;
4027 +  size_t len, llen;
4028 +
4029 +  if (!news)
4030 +    return -1;
4031 +  llen = len = 10 * LONG_STRING;
4032 +  line = buf = safe_calloc (1, len);
4033 +  /* we will generate full newsrc here */
4034 +  for (tmp = news->list; tmp; tmp = tmp->next)
4035 +  {
4036 +    data = (NNTP_DATA *) tmp->data;
4037 +    if (!data || !data->rc)
4038 +      continue;
4039 +    nntp_create_newsrc_line (data, &buf, &line, &llen);
4040 +    if (*line)
4041 +      dprint (2, (debugfile, "Added to newsrc: %s\n", line));
4042 +    line += strlen (line);
4043 +  }
4044 +  /* newrc being fully rewritten */
4045 +  if (news->newsrc &&
4046 +     (r = mutt_update_list_file (news->newsrc, NULL, "", buf)) == 0)
4047 +  {
4048 +    struct stat st;
4049 +
4050 +    stat (news->newsrc, &st);
4051 +    news->size = st.st_size;
4052 +    news->mtime = st.st_mtime;
4053 +  }
4054 +  FREE (&buf);
4055 +  return r;
4056 +}
4057 +
4058 +static FILE *mutt_mkname (char *s)
4059 +{
4060 +  char buf[_POSIX_PATH_MAX], *pc;
4061 +  int fd;
4062 +  FILE *fp;
4063 +
4064 +  nntp_cache_expand (buf, s);
4065 +  if ((fp = safe_fopen (buf, "w")))
4066 +    return fp;
4067 +
4068 +  nntp_cache_expand (buf, "cache-XXXXXX");
4069 +  pc = buf + strlen (buf) - 12;        /* positioning to "cache-XXXXXX" */
4070 +  if ((fd = mkstemp (buf)) == -1)
4071 +    return NULL;
4072 +  strcpy (s, pc);      /* generated name */
4073 +  return fdopen (fd, "w");
4074 +}
4075 +
4076 +/* Updates info into .index file: ALL or about selected newsgroup */
4077 +static int nntp_update_cacheindex (NNTP_SERVER *serv, NNTP_DATA *data)
4078 +{
4079 +  char buf[LONG_STRING], *key = "ALL";
4080 +  char file[_POSIX_PATH_MAX];
4081 +
4082 +  if (!serv || !serv->conn || !serv->conn->account.host)
4083 +    return -1;
4084 +
4085 +  if (data && data->group)
4086 +  {
4087 +    key = data->group;
4088 +    snprintf (buf, sizeof (buf), "%s %s %d %d", key, data->cache,
4089 +         data->firstMessage, data->lastLoaded);
4090 +  }
4091 +  else
4092 +  {
4093 +    strfcpy (file, serv->cache, sizeof (file));
4094 +    snprintf (buf, sizeof (buf), "ALL %s 0 %d", file, (int)serv->newgroups_time);
4095 +  }
4096 +  nntp_cache_expand (file, ".index");
4097 +  return mutt_update_list_file (file, serv->conn->account.host, key, buf);
4098 +}
4099 +
4100 +/* Remove cache files of unsubscribed newsgroups */
4101 +void nntp_clear_cacheindex (NNTP_SERVER *news)
4102 +{
4103 +  NNTP_DATA *data;
4104 +  LIST *tmp;
4105 +
4106 +  if (option (OPTSAVEUNSUB) || !news)
4107 +    return;
4108 +
4109 +  for (tmp = news->list; tmp; tmp = tmp->next)
4110 +  {
4111 +    data = (NNTP_DATA *) tmp->data;
4112 +    if (!data || data->subscribed || !data->cache)
4113 +      continue;
4114 +    nntp_delete_cache (data);
4115 +    dprint (2, (debugfile, "Removed from .index: %s\n", data->group));
4116 +  }
4117 +  return;
4118 +}
4119 +
4120 +int nntp_save_cache_index (NNTP_SERVER *news)
4121 +{
4122 +  char buf[HUGE_STRING];
4123 +  char file[_POSIX_PATH_MAX];
4124 +  NNTP_DATA *d;
4125 +  FILE *f;
4126 +  LIST *l;
4127 +
4128 +  if (!news || !news->newsgroups)
4129 +    return -1;
4130 +  if (!option (OPTNEWSCACHE))
4131 +    return 0;
4132 +
4133 +  if (news->cache)
4134 +  {
4135 +    nntp_cache_expand (file, news->cache);
4136 +    unlink (file);
4137 +    f = safe_fopen (file, "w");
4138 +  }
4139 +  else
4140 +  {
4141 +    strfcpy (buf, news->conn->account.host, sizeof(buf));
4142 +    f = mutt_mkname (buf);
4143 +    news->cache = safe_strdup (buf);
4144 +    nntp_cache_expand (file, buf);
4145 +  }
4146 +  if (!f)
4147 +    return -1;
4148 +
4149 +  for (l = news->list; l; l = l->next)
4150 +  {
4151 +    if ((d = (NNTP_DATA *)l->data) && !d->deleted)
4152 +    {
4153 +      if (d->desc)
4154 +       snprintf (buf, sizeof(buf), "%s %d %d %c %s\n", d->group,
4155 +             d->lastMessage, d->firstMessage, d->allowed ? 'y' : 'n',
4156 +             d->desc);
4157 +      else
4158 +       snprintf (buf, sizeof(buf), "%s %d %d %c\n", d->group,
4159 +             d->lastMessage, d->firstMessage, d->allowed ? 'y' : 'n');
4160 +      if (fputs (buf, f) == EOF)
4161 +      {
4162 +       fclose (f);
4163 +       unlink (file);
4164 +       return -1;
4165 +      }
4166 +    }
4167 +  }
4168 +  fclose (f);
4169 +
4170 +  if (nntp_update_cacheindex (news, NULL))
4171 +  {
4172 +    unlink (file);
4173 +    return -1;
4174 +  }
4175 +  return 0;
4176 +}
4177 +
4178 +int nntp_save_cache_group (CONTEXT *ctx)
4179 +{
4180 +  char buf[HUGE_STRING], addr[STRING];
4181 +  char file[_POSIX_PATH_MAX];
4182 +  FILE *f;
4183 +  HEADER *h;
4184 +  struct tm *tm;
4185 +  int i = 0, save = SORT_ORDER;
4186 +  int prev = 0;
4187 +
4188 +  if (!option (OPTNEWSCACHE))
4189 +    return 0;
4190 +  if (!ctx || !ctx->data || ctx->magic != M_NNTP)
4191 +    return -1;
4192 +
4193 +  if (((NNTP_DATA *)ctx->data)->cache)
4194 +  {
4195 +    nntp_cache_expand (file, ((NNTP_DATA *)ctx->data)->cache);
4196 +    unlink (file);
4197 +    f = safe_fopen (file, "w");
4198 +  }
4199 +  else
4200 +  {
4201 +    snprintf (buf, sizeof(buf), "%s-%s",
4202 +       ((NNTP_DATA *)ctx->data)->nserv->conn->account.host,
4203 +       ((NNTP_DATA *)ctx->data)->group);
4204 +    f = mutt_mkname (buf);
4205 +    ((NNTP_DATA *)ctx->data)->cache = safe_strdup (buf);
4206 +    nntp_cache_expand (file, buf);
4207 +  }
4208 +  if (!f)
4209 +    return -1;
4210 +
4211 +  if (Sort != SORT_ORDER)
4212 +  {
4213 +    save = Sort;
4214 +    Sort = SORT_ORDER;
4215 +    mutt_sort_headers (ctx, 0);
4216 +  }
4217 +
4218 +  /* Save only $nntp_context messages... */
4219 +  ((NNTP_DATA *)ctx->data)->lastCached = 0;
4220 +  if (NntpContext && ctx->msgcount > NntpContext)
4221 +    i = ctx->msgcount - NntpContext;
4222 +  for (; i < ctx->msgcount; i++)
4223 +  {
4224 +    if (!ctx->hdrs[i]->deleted && ctx->hdrs[i]->article_num != prev)
4225 +    {
4226 +      h = ctx->hdrs[i];
4227 +      addr[0] = 0;
4228 +      rfc822_write_address (addr, sizeof(addr), h->env->from, 0);
4229 +      tm = gmtime (&h->date_sent);
4230 +      snprintf (buf, sizeof(buf),
4231 +           "%d\t%s\t%s\t%d %s %d %02d:%02d:%02d GMT\t%s\t",
4232 +           h->article_num, h->env->subject, addr, tm->tm_mday,
4233 +           Months[tm->tm_mon], tm->tm_year+1900, tm->tm_hour, tm->tm_min,
4234 +           tm->tm_sec, h->env->message_id);
4235 +      fputs (buf, f);
4236 +      if (h->env->references)
4237 +       mutt_write_references (h->env->references, f);
4238 +      snprintf (buf, sizeof(buf), "\t%ld\t%d\tXref: %s\n", NONULL(h->content->length),
4239 +           NONULL(h->lines), NONULL(h->env->xref));
4240 +      if (fputs (buf, f) == EOF)
4241 +      {
4242 +       fclose (f);
4243 +       unlink (file);
4244 +       return -1;
4245 +      }
4246 +    }
4247 +    prev = ctx->hdrs[i]->article_num;
4248 +  }
4249 +
4250 +  if (save != Sort)
4251 +  {
4252 +    Sort = save;
4253 +    mutt_sort_headers (ctx, 0);
4254 +  }
4255 +  fclose (f);
4256 +
4257 +  if (nntp_update_cacheindex (((NNTP_DATA *)ctx->data)->nserv,
4258 +       (NNTP_DATA *)ctx->data))
4259 +  {
4260 +    unlink (file);
4261 +    return -1;
4262 +  }
4263 +  ((NNTP_DATA *)ctx->data)->lastCached = ((NNTP_DATA *)ctx->data)->lastLoaded;
4264 +  return 0;
4265 +}
4266 +
4267 +void nntp_delete_cache (NNTP_DATA *data)
4268 +{
4269 +  char buf[_POSIX_PATH_MAX];
4270 +
4271 +  if (!option (OPTNEWSCACHE) || !data || !data->cache || !data->nserv)
4272 +    return;
4273 +
4274 +  nntp_cache_expand (buf, data->cache);
4275 +  unlink (buf);
4276 +  FREE (&data->cache);
4277 +  data->lastCached = 0;
4278 +  nntp_cache_expand (buf, ".index");
4279 +  mutt_update_list_file (buf, data->nserv->conn->account.host, data->group, NULL);
4280 +}
4281 +
4282 +NNTP_DATA *mutt_newsgroup_subscribe (NNTP_SERVER *news, char *group)
4283 +{
4284 +  NNTP_DATA *data;
4285 +
4286 +  if (!news || !news->newsgroups || !group || !*group)
4287 +    return NULL;
4288 +  if (!(data = (NNTP_DATA *)hash_find (news->newsgroups, group)))
4289 +  {
4290 +    data = (NNTP_DATA *) safe_calloc (1, sizeof (NNTP_DATA) + strlen (group) + 1);
4291 +    data->group = (char *) data + sizeof (NNTP_DATA);
4292 +    strcpy (data->group, group);
4293 +    data->nserv = news;
4294 +    data->deleted = 1;
4295 +    if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
4296 +      news->newsgroups = hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
4297 +    hash_insert (news->newsgroups, data->group, data, 0);
4298 +    nntp_add_to_list (news, data);
4299 +  }
4300 +  if (!data->subscribed)
4301 +  {
4302 +    data->subscribed = 1;
4303 +    data->rc = 1;
4304 +  }
4305 +  return data;
4306 +}
4307 +
4308 +NNTP_DATA *mutt_newsgroup_unsubscribe (NNTP_SERVER *news, char *group)
4309 +{
4310 +  NNTP_DATA *data;
4311 +
4312 +  if (!news || !news->newsgroups || !group || !*group ||
4313 +       !(data = (NNTP_DATA *)hash_find (news->newsgroups, group)))
4314 +    return NULL;
4315 +  if (data->subscribed)
4316 +  {
4317 +    data->subscribed = 0;
4318 +    if (!option (OPTSAVEUNSUB))
4319 +      data->rc = 0;
4320 +  }
4321 +  return data;
4322 +}
4323 +
4324 +NNTP_DATA *mutt_newsgroup_catchup (NNTP_SERVER *news, char *group)
4325 +{
4326 +  NNTP_DATA *data;
4327 +
4328 +  if (!news || !news->newsgroups || !group || !*group ||
4329 +      !(data = (NNTP_DATA *)hash_find (news->newsgroups, group)))
4330 +    return NULL;
4331 +  if (!data->max)
4332 +  {
4333 +    data->entries = safe_calloc (5, sizeof (NEWSRC_ENTRY));
4334 +    data->max = 5;
4335 +  }
4336 +  data->num = 1;
4337 +  data->entries[0].first = 1;
4338 +  data->unread = 0;
4339 +  data->entries[0].last = data->lastMessage;
4340 +  if (Context && Context->data == data)
4341 +  {
4342 +    int x;
4343 +
4344 +    for (x = 0; x < Context->msgcount; x++)
4345 +      mutt_set_flag (Context, Context->hdrs[x], M_READ, 1);
4346 +  }
4347 +  return data;
4348 +}
4349 +
4350 +NNTP_DATA *mutt_newsgroup_uncatchup (NNTP_SERVER *news, char *group)
4351 +{
4352 +  NNTP_DATA *data;
4353 +
4354 +  if (!news || !news->newsgroups || !group || !*group ||
4355 +      !(data = (NNTP_DATA *)hash_find (news->newsgroups, group)))
4356 +    return NULL;
4357 +  if (!data->max)
4358 +  {
4359 +    data->entries = safe_calloc (5, sizeof (NEWSRC_ENTRY));
4360 +    data->max = 5;
4361 +  }
4362 +  data->num = 1;
4363 +  data->entries[0].first = 1;
4364 +  data->entries[0].last = data->firstMessage - 1;
4365 +  if (Context && Context->data == data)
4366 +  {
4367 +    int x;
4368 +
4369 +    data->unread = Context->msgcount;
4370 +    for (x = 0; x < Context->msgcount; x++)
4371 +      mutt_set_flag (Context, Context->hdrs[x], M_READ, 0);
4372 +  }
4373 +  else
4374 +    data->unread = data->lastMessage - data->entries[0].last;
4375 +  return data;
4376 +}
4377 +
4378 +/* this routine gives the first newsgroup with new messages */
4379 +void nntp_buffy (char *s)
4380 +{
4381 +  LIST *list;
4382 +
4383 +  for (list = CurrentNewsSrv->list; list; list = list->next)
4384 +  {
4385 +    NNTP_DATA *data = (NNTP_DATA *) list->data;
4386 +
4387 +    if (data && data->subscribed && data->unread)
4388 +    {
4389 +      if (Context && Context->magic == M_NNTP &&
4390 +         !mutt_strcmp (data->group, ((NNTP_DATA *) Context->data)->group))
4391 +      {
4392 +       unsigned int i, unread = 0;
4393 +
4394 +       for (i = 0; i < Context->msgcount; i++)
4395 +         if (!Context->hdrs[i]->read && !Context->hdrs[i]->deleted)
4396 +           unread++;
4397 +       if (!unread)
4398 +         continue;
4399 +      }
4400 +      strcpy (s, data->group);
4401 +      break;
4402 +    }
4403 +  }
4404 +}
4405 diff -udprP mutt-1.5.13.orig/nntp.c mutt-1.5.13/nntp.c
4406 --- mutt-1.5.13.orig/nntp.c     1970-01-01 03:00:00.000000000 +0300
4407 +++ mutt-1.5.13/nntp.c  2006-08-15 13:04:56.000000000 +0300
4408 @@ -0,0 +1,1573 @@
4409 +/*
4410 + * Copyright (C) 1998 Brandon Long <blong@fiction.net>
4411 + * Copyright (C) 1999 Andrej Gritsenko <andrej@lucky.net>
4412 + * Copyright (C) 2000-2004 Vsevolod Volkov <vvv@mutt.org.ua>
4413 + * 
4414 + *     This program is free software; you can redistribute it and/or modify
4415 + *     it under the terms of the GNU General Public License as published by
4416 + *     the Free Software Foundation; either version 2 of the License, or
4417 + *     (at your option) any later version.
4418 + * 
4419 + *     This program is distributed in the hope that it will be useful,
4420 + *     but WITHOUT ANY WARRANTY; without even the implied warranty of
4421 + *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4422 + *     GNU General Public License for more details.
4423 + * 
4424 + *     You should have received a copy of the GNU General Public License
4425 + *     along with this program; if not, write to the Free Software
4426 + *     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
4427 + */ 
4428 +
4429 +#if HAVE_CONFIG_H
4430 +# include "config.h"
4431 +#endif
4432 +
4433 +#include "mutt.h"
4434 +#include "mutt_curses.h"
4435 +#include "sort.h"
4436 +#include "mx.h"
4437 +#include "mime.h"
4438 +#include "rfc1524.h"
4439 +#include "rfc2047.h"
4440 +#include "mailbox.h"
4441 +#include "nntp.h"
4442 +
4443 +#ifdef HAVE_PGP
4444 +#include "pgp.h"
4445 +#endif
4446 +
4447 +#ifdef HAVE_SMIME
4448 +#include "smime.h"
4449 +#endif
4450 +
4451 +#include <unistd.h>
4452 +#include <string.h>
4453 +#include <ctype.h>
4454 +#include <stdlib.h>
4455 +
4456 +static unsigned int _checked = 0;
4457 +
4458 +#ifdef DEBUG
4459 +static void nntp_error (const char *where, const char *msg)
4460 +{
4461 +  dprint (1, (debugfile, "nntp_error(): unexpected response in %s: %s\n", where, msg));
4462 +}
4463 +#endif /* DEBUG */
4464 +
4465 +static int nntp_auth (NNTP_SERVER *serv)
4466 +{
4467 +  CONNECTION *conn = serv->conn;
4468 +  char buf[STRING];
4469 +  unsigned char flags = conn->account.flags;
4470 +
4471 +  if (mutt_account_getuser (&conn->account) || !conn->account.user[0] ||
4472 +      mutt_account_getpass (&conn->account) || !conn->account.pass[0])
4473 +  {
4474 +    conn->account.flags = flags;
4475 +    return -2;
4476 +  }
4477 +
4478 +  mutt_message _("Logging in...");
4479 +
4480 +  snprintf (buf, sizeof (buf), "AUTHINFO USER %s\r\n", conn->account.user);
4481 +  mutt_socket_write (conn, buf);
4482 +  if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
4483 +  {
4484 +    conn->account.flags = flags;
4485 +    return -1;
4486 +  }
4487 +
4488 +#ifdef DEBUG
4489 +  /* don't print the password unless we're at the ungodly debugging level */
4490 +  if (debuglevel < M_SOCK_LOG_FULL)
4491 +    dprint (M_SOCK_LOG_CMD, (debugfile, "> AUTHINFO PASS *\n"));
4492 +#endif
4493 +  snprintf (buf, sizeof (buf), "AUTHINFO PASS %s\r\n", conn->account.pass);
4494 +  mutt_socket_write_d (conn, buf, -1, M_SOCK_LOG_FULL);
4495 +  if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
4496 +  {
4497 +    conn->account.flags = flags;
4498 +    return -1;
4499 +  }
4500 +
4501 +  if (mutt_strncmp ("281", buf, 3))
4502 +  {
4503 +    conn->account.flags = flags;
4504 +    mutt_error _("Login failed.");
4505 +    sleep (2);
4506 +    return -3;
4507 +  }
4508 +
4509 +  return 0;
4510 +}
4511 +
4512 +static int nntp_connect_error (NNTP_SERVER *serv)
4513 +{
4514 +  serv->status = NNTP_NONE;
4515 +  mutt_socket_close (serv->conn);
4516 +  mutt_error _("Server closed connection!");
4517 +  sleep (2);
4518 +  return -1;
4519 +}
4520 +
4521 +static int nntp_connect_and_auth (NNTP_SERVER *serv)
4522 +{
4523 +  CONNECTION *conn = serv->conn;
4524 +  char buf[STRING];
4525 +  int rc;
4526 +
4527 +  serv->status = NNTP_NONE;
4528 +
4529 +  if (mutt_socket_open (conn) < 0)
4530 +    return -1;
4531 +
4532 +  if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
4533 +    return nntp_connect_error (serv);
4534 +
4535 +  if (!mutt_strncmp ("200", buf, 3))
4536 +    mutt_message (_("Connected to %s. Posting ok."), conn->account.host);
4537 +  else if (!mutt_strncmp ("201", buf, 3))
4538 +    mutt_message (_("Connected to %s. Posting NOT ok."), conn->account.host);
4539 +  else
4540 +  {
4541 +    mutt_socket_close (conn);
4542 +    mutt_remove_trailing_ws (buf);
4543 +    mutt_error ("%s", buf);
4544 +    sleep (2);
4545 +    return -1;
4546 +  }
4547 +
4548 +  sleep (1);
4549 +
4550 +  /* Tell INN to switch to mode reader if it isn't so. Ignore all
4551 +   returned codes and messages. */
4552 +  mutt_socket_write (conn, "MODE READER\r\n");
4553 +  if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
4554 +    return nntp_connect_error (serv);
4555 +
4556 +  mutt_socket_write (conn, "STAT\r\n");
4557 +  if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
4558 +    return nntp_connect_error (serv);
4559 +
4560 +  if (!(conn->account.flags & M_ACCT_USER) && mutt_strncmp ("480", buf, 3))
4561 +  {
4562 +    serv->status = NNTP_OK;
4563 +    return 0;
4564 +  }
4565 +
4566 +  rc = nntp_auth (serv);
4567 +  if (rc == -1)
4568 +    return nntp_connect_error (serv);
4569 +  if (rc == -2)
4570 +  {
4571 +    mutt_socket_close (conn);
4572 +    serv->status = NNTP_BYE;
4573 +    return -1;
4574 +  }
4575 +  if (rc < 0)
4576 +  {
4577 +    mutt_socket_close (conn);
4578 +    mutt_error _("Login failed.");
4579 +    sleep (2);
4580 +    return -1;
4581 +  }
4582 +  serv->status = NNTP_OK;
4583 +  return 0;
4584 +}
4585 +
4586 +static int nntp_attempt_features (NNTP_SERVER *serv)
4587 +{
4588 +  char buf[LONG_STRING];
4589 +  CONNECTION *conn = serv->conn;
4590 +
4591 +  mutt_socket_write (conn, "XOVER\r\n");
4592 +  if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
4593 +    return nntp_connect_error (serv);
4594 +  if (mutt_strncmp ("500", buf, 3))
4595 +    serv->hasXOVER = 1;
4596 +
4597 +  mutt_socket_write (conn, "XPAT\r\n");
4598 +  if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
4599 +    return nntp_connect_error (serv);
4600 +  if (mutt_strncmp ("500", buf, 3))
4601 +    serv->hasXPAT = 1;
4602 +
4603 +  mutt_socket_write (conn, "LISTGROUP\r\n");
4604 +  if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
4605 +    return nntp_connect_error (serv);
4606 +  if (mutt_strncmp ("500", buf, 3))
4607 +    serv->hasLISTGROUP = 1;
4608 +
4609 +  mutt_socket_write (conn, "XGTITLE +\r\n");
4610 +  if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
4611 +    return nntp_connect_error (serv);
4612 +  if (mutt_strncmp ("500", buf, 3))
4613 +    serv->hasXGTITLE = 1;
4614 +
4615 +  if (!mutt_strncmp ("282", buf, 3))
4616 +  {
4617 +    do
4618 +    {
4619 +      if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
4620 +       return nntp_connect_error (serv);
4621 +    } while (!(buf[0] == '.' && buf[1] == '\0'));
4622 +  }
4623 +
4624 +  return 0;
4625 +}
4626 +
4627 +static int nntp_open_connection (NNTP_SERVER *serv)
4628 +{
4629 +  if (serv->status == NNTP_OK)
4630 +    return 0;
4631 +  if (serv->status == NNTP_BYE)
4632 +    return -1;
4633 +  if (nntp_connect_and_auth (serv) < 0)
4634 +    return -1;
4635 +  if (nntp_attempt_features (serv) < 0)
4636 +    return -1;
4637 +  return 0;
4638 +}
4639 +
4640 +static int nntp_reconnect (NNTP_SERVER *serv)
4641 +{
4642 +  char buf[SHORT_STRING];
4643 +
4644 +  mutt_socket_close (serv->conn);
4645 +
4646 +  FOREVER
4647 +  {
4648 +    if (nntp_connect_and_auth (serv) == 0)
4649 +      return 0;
4650 +
4651 +    snprintf (buf, sizeof (buf), _("Connection to %s lost. Reconnect?"),
4652 +                               serv->conn->account.host);
4653 +    if (query_quadoption (OPT_NNTPRECONNECT, buf) != M_YES)
4654 +    {
4655 +      serv->status = NNTP_BYE;
4656 +      return -1;
4657 +    }
4658 +  }
4659 +}
4660 +
4661 +/* Send data from line[LONG_STRING] and receive answer to same line */
4662 +static int mutt_nntp_query (NNTP_DATA *data, char *line, size_t linelen)
4663 +{
4664 +  char buf[LONG_STRING];
4665 +  int done = TRUE;
4666 +
4667 +  if (data->nserv->status == NNTP_BYE)
4668 +    return -1;
4669 +
4670 +  do
4671 +  {
4672 +    if (*line)
4673 +    {
4674 +      mutt_socket_write (data->nserv->conn, line);
4675 +    }
4676 +    else if (data->group)
4677 +    {
4678 +      snprintf (buf, sizeof (buf), "GROUP %s\r\n", data->group);
4679 +      mutt_socket_write (data->nserv->conn, buf);
4680 +    }
4681 +
4682 +    done = TRUE;
4683 +    if (mutt_socket_readln (buf, sizeof (buf), data->nserv->conn) < 0)
4684 +    {
4685 +      if (nntp_reconnect (data->nserv) < 0)
4686 +       return -1;
4687 +
4688 +      if (data->group)
4689 +      {
4690 +       snprintf (buf, sizeof (buf), "GROUP %s\r\n", data->group);
4691 +       mutt_socket_write (data->nserv->conn, buf);
4692 +       if (mutt_socket_readln (buf, sizeof (buf), data->nserv->conn) < 0)
4693 +         return -1;
4694 +      }
4695 +      if (*line)
4696 +       done = FALSE;
4697 +    }
4698 +    else if ((!mutt_strncmp ("480", buf, 3)) && nntp_auth (data->nserv) < 0)
4699 +      return -1;
4700 +  } while (!done);
4701 +
4702 +  strfcpy (line, buf, linelen);
4703 +  return 0;
4704 +}
4705 +
4706 +/*
4707 + * This function calls  funct(*line, *data)  for each received line,
4708 + * funct(NULL, *data)  if  rewind(*data)  needs, exits when fail or done.
4709 + * Returned codes:
4710 + *  0 - successful,
4711 + *  1 - correct but not performed (may be, have to be continued),
4712 + * -1 - conection lost,
4713 + * -2 - invalid command or execution error,
4714 + * -3 - error in funct(*line, *data).
4715 + */
4716 +static int mutt_nntp_fetch (NNTP_DATA *nntp_data, char *query, char *msg,
4717 +               int (*funct) (char *, void *), void *data, int tagged)
4718 +{
4719 +  char buf[LONG_STRING];
4720 +  char *inbuf, *p;
4721 +  int done = FALSE;
4722 +  int chunk, line;
4723 +  size_t lenbuf = 0;
4724 +  int ret;
4725 +
4726 +  do
4727 +  {
4728 +    strfcpy (buf, query, sizeof (buf));
4729 +    if (mutt_nntp_query (nntp_data, buf, sizeof (buf)) < 0)
4730 +      return -1;
4731 +    if (buf[0] == '5')
4732 +      return -2;
4733 +    if (buf[0] != '2')
4734 +      return 1;
4735 +
4736 +    ret = 0;
4737 +    line = 0;
4738 +    inbuf = safe_malloc (sizeof (buf));
4739 +
4740 +    FOREVER
4741 +    {
4742 +      chunk = mutt_socket_readln_d (buf, sizeof (buf), nntp_data->nserv->conn,
4743 +                                   M_SOCK_LOG_HDR);
4744 +      if (chunk < 0)
4745 +       break;
4746 +
4747 +      p = buf;
4748 +      if (!lenbuf && buf[0] == '.')
4749 +      {
4750 +       if (buf[1] == '\0')
4751 +       {
4752 +         done = TRUE;
4753 +         break;
4754 +       }
4755 +       if (buf[1] == '.')
4756 +         p++;
4757 +      }
4758 +
4759 +      strfcpy (inbuf + lenbuf, p, sizeof (buf));
4760 +
4761 +      if (chunk >= sizeof (buf))
4762 +      {
4763 +       lenbuf += strlen (p);
4764 +      }
4765 +      else
4766 +      {
4767 +       line++;
4768 +       if (msg && ReadInc && (line % ReadInc == 0)) {
4769 +         if (tagged)
4770 +           mutt_message (_("%s (tagged: %d) %d"), msg, tagged, line);
4771 +         else
4772 +           mutt_message ("%s %d", msg, line);
4773 +       }
4774 +
4775 +       if (ret == 0 && funct (inbuf, data) < 0)
4776 +         ret = -3;
4777 +       lenbuf = 0;
4778 +      }
4779 +
4780 +      safe_realloc (&inbuf, lenbuf + sizeof (buf));
4781 +    }
4782 +    FREE (&inbuf);
4783 +    funct (NULL, data);
4784 +  }
4785 +  while (!done);
4786 +  return ret;
4787 +}
4788 +
4789 +static int nntp_read_tempfile (char *line, void *file)
4790 +{
4791 +  FILE *f = (FILE *)file;
4792 +
4793 +  if (!line)
4794 +    rewind (f);
4795 +  else
4796 +  {
4797 +    fputs (line, f);
4798 +    if (fputc ('\n', f) == EOF)
4799 +      return -1;
4800 +  }
4801 +  return 0;
4802 +}
4803 +
4804 +static void nntp_parse_xref (CONTEXT *ctx, char *group, char *xref, HEADER *h)
4805 +{
4806 +  register char *p, *b;
4807 +  register char *colon = NULL;
4808 +
4809 +  b = p = xref;
4810 +  while (*p)
4811 +  {
4812 +    /* skip to next word */
4813 +    b = p;
4814 +    while (*b && ((*b == ' ') || (*b == '\t'))) b++;
4815 +    p = b;
4816 +    colon = NULL;
4817 +    /* skip to end of word */
4818 +    while (*p && (*p != ' ') && (*p != '\t')) 
4819 +    {
4820 +      if (*p == ':')
4821 +       colon = p;
4822 +      p++;
4823 +    }
4824 +    if (*p)
4825 +    {
4826 +      *p = '\0';
4827 +      p++;
4828 +    }
4829 +    if (colon)
4830 +    {
4831 +      *colon = '\0';
4832 +      colon++;
4833 +      nntp_get_status (ctx, h, b, atoi(colon));
4834 +      if (h && h->article_num == 0 && mutt_strcmp (group, b) == 0)
4835 +       h->article_num = atoi(colon);
4836 +    }
4837 +  }
4838 +}
4839 +
4840 +/*
4841 + * returns:
4842 + *  0 on success
4843 + *  1 if article not found
4844 + * -1 if read or write error on tempfile or socket
4845 + */
4846 +static int nntp_read_header (CONTEXT *ctx, const char *msgid, int article_num)
4847 +{
4848 +  NNTP_DATA *nntp_data = ((NNTP_DATA *)ctx->data);
4849 +  FILE *f;
4850 +  char buf[LONG_STRING];
4851 +  char tempfile[_POSIX_PATH_MAX];
4852 +  int ret;
4853 +  HEADER *h = ctx->hdrs[ctx->msgcount];
4854 +
4855 +  mutt_mktemp (tempfile);
4856 +  if (!(f = safe_fopen (tempfile, "w+")))
4857 +    return -1;
4858 +
4859 +  if (!msgid)
4860 +    snprintf (buf, sizeof (buf), "HEAD %d\r\n", article_num);
4861 +  else
4862 +    snprintf (buf, sizeof (buf), "HEAD %s\r\n", msgid);
4863 +
4864 +  ret = mutt_nntp_fetch (nntp_data, buf, NULL, nntp_read_tempfile, f, 0);
4865 +  if (ret)
4866 +  {
4867 +#ifdef DEBUG
4868 +    if (ret != -1)
4869 +      dprint(1, (debugfile, "nntp_read_header: %s\n", buf));
4870 +#endif
4871 +    fclose (f);
4872 +    unlink (tempfile);
4873 +    return (ret == -1 ? -1 : 1);
4874 +  }
4875 +
4876 +  h->article_num = article_num;
4877 +  h->env = mutt_read_rfc822_header (f, h, 0, 0);
4878 +  fclose (f);
4879 +  unlink (tempfile);
4880 +
4881 +  if (h->env->xref != NULL)
4882 +    nntp_parse_xref (ctx, nntp_data->group, h->env->xref, h);
4883 +  else if (h->article_num == 0 && msgid)
4884 +  {
4885 +    snprintf (buf, sizeof (buf), "STAT %s\r\n", msgid);
4886 +    if (mutt_nntp_query (nntp_data, buf, sizeof (buf)) == 0)
4887 +      h->article_num = atoi (buf + 4);
4888 +  }
4889 +
4890 +  return 0;
4891 +}
4892 +
4893 +static int parse_description (char *line, void *n)
4894 +{
4895 +#define news ((NNTP_SERVER *) n)
4896 +  register char *d = line;
4897 +  NNTP_DATA *data;
4898 +
4899 +  if (!line)
4900 +    return 0;
4901 +  while (*d && *d != '\t' && *d != ' ') d++;
4902 +    *d = 0;
4903 +  d++;
4904 +  while (*d && (*d == '\t' || *d == ' ')) d++;
4905 +  dprint (2, (debugfile, "group: %s, desc: %s\n", line, d));
4906 +  if ((data = (NNTP_DATA *) hash_find (news->newsgroups, line)) != NULL &&
4907 +       mutt_strcmp (d, data->desc))
4908 +  {
4909 +    FREE (&data->desc);
4910 +    data->desc = safe_strdup (d);
4911 +  }
4912 +  return 0;
4913 +#undef news
4914 +}
4915 +
4916 +static void nntp_get_desc (NNTP_DATA *data, char *mask, char *msg)
4917 +{
4918 +  char buf[STRING];
4919 +
4920 +  if (!option (OPTLOADDESC) || !data || !data->nserv)
4921 +    return;
4922 +
4923 +  /* Get newsgroup description, if we can */
4924 +  if (data->nserv->hasXGTITLE)
4925 +    snprintf (buf, sizeof (buf), "XGTITLE %s\r\n", mask);
4926 +  else
4927 +    snprintf (buf, sizeof (buf), "LIST NEWSGROUPS %s\r\n", mask);
4928 +  if (mutt_nntp_fetch (data, buf, msg, parse_description, data->nserv, 0) != 0)
4929 +  {
4930 +#ifdef DEBUG
4931 +    nntp_error ("nntp_get_desc()", buf);
4932 +#endif
4933 +  }
4934 +}
4935 +
4936 +/*
4937 + * XOVER returns a tab separated list of:
4938 + * id|subject|from|date|Msgid|references|bytes|lines|xref
4939 + *
4940 + * This has to duplicate some of the functionality of 
4941 + * mutt_read_rfc822_header(), since it replaces the call to that (albeit with
4942 + * a limited number of headers which are "parsed" by placement in the list)
4943 + */
4944 +static int nntp_parse_xover (CONTEXT *ctx, char *buf, HEADER *hdr)
4945 +{
4946 +  NNTP_DATA *nntp_data = (NNTP_DATA *) ctx->data;
4947 +  char *p, *b;
4948 +  int x, done = 0;
4949 +
4950 +  hdr->env = mutt_new_envelope();
4951 +  hdr->env->newsgroups = safe_strdup (nntp_data->group);
4952 +  hdr->content = mutt_new_body();
4953 +  hdr->content->type = TYPETEXT;
4954 +  hdr->content->subtype = safe_strdup ("plain");
4955 +  hdr->content->encoding = ENC7BIT;
4956 +  hdr->content->disposition = DISPINLINE;
4957 +  hdr->content->length = -1;
4958 +  b = p = buf;
4959 +
4960 +  for (x = 0; !done && x < 9; x++)
4961 +  {
4962 +    /* if from file, need to skip newline character */
4963 +    while (*p && *p != '\n' && *p != '\t') p++;
4964 +    if (!*p) done++;
4965 +    *p = '\0';
4966 +    p++;
4967 +    switch (x)
4968 +    {
4969 +      case 0:
4970 +
4971 +       hdr->article_num = atoi (b);
4972 +       nntp_get_status (ctx, hdr, NULL, hdr->article_num);
4973 +       break;
4974 +      case 1:
4975 +       hdr->env->subject = safe_strdup (b);
4976 +       /* Now we need to do the things which would normally be done in 
4977 +        * mutt_read_rfc822_header() */
4978 +       if (hdr->env->subject)
4979 +       {
4980 +         regmatch_t pmatch[1];
4981 +
4982 +         rfc2047_decode (&hdr->env->subject);
4983 +
4984 +         if (regexec (ReplyRegexp.rx, hdr->env->subject, 1, pmatch, 0) == 0)
4985 +           hdr->env->real_subj = hdr->env->subject + pmatch[0].rm_eo;
4986 +         else
4987 +           hdr->env->real_subj = hdr->env->subject;
4988 +       }
4989 +       break;
4990 +      case 2:
4991 +       rfc822_free_address (&hdr->env->from);
4992 +       hdr->env->from = rfc822_parse_adrlist (hdr->env->from, b);
4993 +       rfc2047_decode_adrlist (hdr->env->from);
4994 +       break;
4995 +      case 3:
4996 +       hdr->date_sent = mutt_parse_date (b, hdr);
4997 +       hdr->received = hdr->date_sent;
4998 +       break;
4999 +      case 4:
5000 +       FREE (&hdr->env->message_id);
5001 +       hdr->env->message_id = safe_strdup (b);
5002 +       break;
5003 +      case 5:
5004 +       mutt_free_list (&hdr->env->references);
5005 +       hdr->env->references = mutt_parse_references (b, 0);
5006 +       break;
5007 +      case 6:
5008 +       hdr->content->length = atoi (b);
5009 +       break;
5010 +      case 7:
5011 +       hdr->lines = atoi (b);
5012 +       break;
5013 +      case 8:
5014 +       if (!hdr->read)
5015 +         FREE (&hdr->env->xref);
5016 +         b = b + 6;    /* skips the "Xref: " */
5017 +         hdr->env->xref = safe_strdup (b);
5018 +         nntp_parse_xref (ctx, nntp_data->group, b, hdr);
5019 +    }
5020 +    if (!*p)
5021 +      return -1;
5022 +    b = p;
5023 +  }
5024 +  return 0;
5025 +}
5026 +
5027 +typedef struct
5028 +{
5029 +  CONTEXT *ctx;
5030 +  unsigned int base;
5031 +  unsigned int first;
5032 +  unsigned int last;
5033 +  unsigned short *messages;
5034 +  char* msg;
5035 +} FETCH_CONTEXT;
5036 +
5037 +#define fc ((FETCH_CONTEXT *) c)
5038 +static int nntp_fetch_numbers (char *line, void *c)
5039 +{
5040 +  unsigned int num;
5041 +
5042 +  if (!line)
5043 +    return 0;
5044 +  num = atoi (line);
5045 +  if (num < fc->base || num > fc->last)
5046 +    return 0;
5047 +  fc->messages[num - fc->base] = 1;
5048 +  return 0;
5049 +}
5050 +
5051 +static int add_xover_line (char *line, void *c)
5052 +{
5053 +  unsigned int num, total;
5054 +  CONTEXT *ctx = fc->ctx;
5055 +  NNTP_DATA *data = (NNTP_DATA *)ctx->data;
5056 +
5057 +  if (!line)
5058 +    return 0;
5059 +
5060 +  if (ctx->msgcount >= ctx->hdrmax)
5061 +    mx_alloc_memory (ctx);
5062 +  ctx->hdrs[ctx->msgcount] = mutt_new_header ();
5063 +  ctx->hdrs[ctx->msgcount]->index = ctx->msgcount;
5064 +
5065 +  nntp_parse_xover (ctx, line, ctx->hdrs[ctx->msgcount]);
5066 +  num = ctx->hdrs[ctx->msgcount]->article_num;
5067 +
5068 +  if (num >= fc->first && num <= fc->last && fc->messages[num - fc->base])
5069 +  {
5070 +    ctx->msgcount++;
5071 +    if (num > data->lastLoaded)
5072 +      data->lastLoaded = num;
5073 +    num = num - fc->first + 1;
5074 +    total = fc->last - fc->first + 1;
5075 +    if (!ctx->quiet && fc->msg && ReadInc && (num % ReadInc == 0))
5076 +      mutt_message ("%s %d/%d", fc->msg, num, total);
5077 +  }
5078 +  else
5079 +    mutt_free_header (&ctx->hdrs[ctx->msgcount]); /* skip it */
5080 +
5081 +  return 0;
5082 +}
5083 +#undef fc
5084 +
5085 +static int nntp_fetch_headers (CONTEXT *ctx, unsigned int first,
5086 +       unsigned int last)
5087 +{
5088 +  char buf[HUGE_STRING];
5089 +  char *msg = _("Fetching message headers...");
5090 +  NNTP_DATA *nntp_data = ((NNTP_DATA *)ctx->data);
5091 +  int ret;
5092 +  int num;
5093 +  int oldmsgcount;
5094 +  unsigned int current;
5095 +  FILE *f;
5096 +  FETCH_CONTEXT fc;
5097 +
5098 +  /* if empty group or nothing to do */
5099 +  if (!last || first > last)
5100 +    return 0;
5101 +
5102 +  /* fetch list of articles */
5103 +  fc.ctx = ctx;
5104 +  fc.base = first;
5105 +  fc.last = last;
5106 +  fc.messages = safe_calloc (last - first + 1, sizeof (unsigned short));
5107 +  if (nntp_data->nserv->hasLISTGROUP)
5108 +  {
5109 +    mutt_message _("Fetching list of articles...");
5110 +    snprintf (buf, sizeof (buf), "LISTGROUP %s\r\n", nntp_data->group);
5111 +    if (mutt_nntp_fetch (nntp_data, buf, NULL, nntp_fetch_numbers, &fc, 0) != 0)
5112 +    {
5113 +      mutt_error (_("LISTGROUP command failed: %s"), buf);
5114 +#ifdef DEBUG
5115 +      nntp_error ("nntp_fetch_headers()", buf);
5116 +#endif
5117 +      FREE (&fc.messages);
5118 +      return -1;
5119 +    }
5120 +  }
5121 +  else
5122 +  {
5123 +    for (num = 0; num < last - first + 1; num++)
5124 +      fc.messages[num] = 1;
5125 +  }
5126 +
5127 +  /* CACHE: must be loaded xover cache here */
5128 +  num = nntp_data->lastCached - first + 1;
5129 +  if (option (OPTNEWSCACHE) && nntp_data->cache && num > 0)
5130 +  {
5131 +    nntp_cache_expand (buf, nntp_data->cache);
5132 +    mutt_message _("Fetching headers from cache...");
5133 +    if ((f = safe_fopen (buf, "r")))
5134 +    {
5135 +      int r = 0;
5136 +
5137 +      /* counting number of lines */
5138 +      while (fgets (buf, sizeof (buf), f) != NULL)
5139 +       r++;
5140 +      rewind (f);
5141 +      while (r > num && fgets (buf, sizeof (buf), f) != NULL)
5142 +       r--;
5143 +      oldmsgcount = ctx->msgcount;
5144 +      fc.first = first;
5145 +      fc.last = first + num - 1;
5146 +      fc.msg = NULL;
5147 +      while (fgets (buf, sizeof (buf), f) != NULL)
5148 +       add_xover_line (buf, &fc);
5149 +      fclose (f);
5150 +      nntp_data->lastLoaded = fc.last;
5151 +      first = fc.last + 1;
5152 +      if (ctx->msgcount > oldmsgcount)
5153 +       mx_update_context (ctx, ctx->msgcount - oldmsgcount);
5154 +    }
5155 +    else
5156 +      nntp_delete_cache (nntp_data);
5157 +  }
5158 +  num = last - first + 1;
5159 +  if (num <= 0)
5160 +  {
5161 +    FREE (&fc.messages);
5162 +    return 0;
5163 +  }
5164 +
5165 +  /*
5166 +   * Without XOVER, we have to fetch each article header and parse
5167 +   * it.  With XOVER, we ask for all of them
5168 +   */
5169 +  mutt_message (msg);
5170 +  if (nntp_data->nserv->hasXOVER)
5171 +  {
5172 +    oldmsgcount = ctx->msgcount;
5173 +    fc.first = first;
5174 +    fc.last = last;
5175 +    fc.msg = msg;
5176 +    snprintf (buf, sizeof (buf), "XOVER %d-%d\r\n", first, last);
5177 +    ret = mutt_nntp_fetch (nntp_data, buf, NULL, add_xover_line, &fc, 0);
5178 +    if (ctx->msgcount > oldmsgcount)
5179 +      mx_update_context (ctx, ctx->msgcount - oldmsgcount);
5180 +    if (ret != 0)
5181 +    {
5182 +      mutt_error (_("XOVER command failed: %s"), buf);
5183 +#ifdef DEBUG
5184 +      nntp_error ("nntp_fetch_headers()", buf);
5185 +#endif
5186 +      FREE (&fc.messages);
5187 +      return -1;
5188 +    }
5189 +    /* fetched OK */
5190 +  }
5191 +  else
5192 +  for (current = first; current <= last; current++)
5193 +  {
5194 +    HEADER *h;
5195 +
5196 +    ret = current - first + 1;
5197 +    mutt_message ("%s %d/%d", msg, ret, num);
5198 +
5199 +    if (!fc.messages[current - fc.base])
5200 +      continue;
5201 +
5202 +    if (ctx->msgcount >= ctx->hdrmax)
5203 +      mx_alloc_memory (ctx);
5204 +    h = ctx->hdrs[ctx->msgcount] = mutt_new_header ();
5205 +    h->index = ctx->msgcount;
5206 +
5207 +    ret = nntp_read_header (ctx, NULL, current);
5208 +    if (ret == 0) /* Got article. Fetch next header */
5209 +    {
5210 +      nntp_get_status (ctx, h, NULL, h->article_num);
5211 +      ctx->msgcount++;
5212 +      mx_update_context (ctx, 1);
5213 +    }
5214 +    else
5215 +      mutt_free_header (&h); /* skip it */
5216 +    if (ret == -1)
5217 +    {
5218 +      FREE (&fc.messages);
5219 +      return -1;
5220 +    }
5221 +
5222 +    if (current > nntp_data->lastLoaded)
5223 +      nntp_data->lastLoaded = current;
5224 +  }
5225 +  FREE (&fc.messages);
5226 +  nntp_data->lastLoaded = last;
5227 +  mutt_clear_error ();
5228 +  return 0;
5229 +}
5230 +
5231 +/* 
5232 + * currently, nntp "mailbox" is "newsgroup"
5233 + */
5234 +int nntp_open_mailbox (CONTEXT *ctx)
5235 +{
5236 +  NNTP_DATA *nntp_data;
5237 +  NNTP_SERVER *serv;
5238 +  char buf[HUGE_STRING];
5239 +  char server[LONG_STRING];
5240 +  int count = 0;
5241 +  unsigned int first;
5242 +  ACCOUNT acct;
5243 +
5244 +  if (nntp_parse_url (ctx->path, &acct, buf, sizeof (buf)) < 0 || !*buf)
5245 +  {
5246 +    mutt_error (_("%s is an invalid newsgroup specification!"), ctx->path);
5247 +    mutt_sleep (2);
5248 +    return -1;
5249 +  }
5250 +
5251 +  server[0] = '\0';
5252 +  nntp_expand_path (server, sizeof (server), &acct);
5253 +  if (!(serv = mutt_select_newsserver (server)) || serv->status != NNTP_OK)
5254 +    return -1;
5255 +
5256 +  CurrentNewsSrv = serv;
5257 +
5258 +  /* create NNTP-specific state struct if nof found in list */
5259 +  if ((nntp_data = (NNTP_DATA *) hash_find (serv->newsgroups, buf)) == NULL)
5260 +  {
5261 +    nntp_data = safe_calloc (1, sizeof (NNTP_DATA) + strlen (buf) + 1);
5262 +    nntp_data->group = (char *) nntp_data + sizeof (NNTP_DATA);
5263 +    strcpy (nntp_data->group, buf);
5264 +    hash_insert (serv->newsgroups, nntp_data->group, nntp_data, 0);
5265 +    nntp_add_to_list (serv, nntp_data);
5266 +  }
5267 +  ctx->data = nntp_data;
5268 +  nntp_data->nserv = serv;
5269 +
5270 +  mutt_message (_("Selecting %s..."), nntp_data->group);
5271 +
5272 +  if (!nntp_data->desc)
5273 +  {
5274 +    nntp_get_desc (nntp_data, nntp_data->group, NULL);
5275 +    if (nntp_data->desc)
5276 +      nntp_save_cache_index (serv);
5277 +  }
5278 +
5279 +  buf[0] = 0;
5280 +  if (mutt_nntp_query (nntp_data, buf, sizeof(buf)) < 0)
5281 +  {
5282 +#ifdef DEBUG
5283 +    nntp_error ("nntp_open_mailbox()", buf);
5284 +#endif
5285 +    return -1;
5286 +  }
5287 +
5288 +  if (mutt_strncmp ("211", buf, 3))
5289 +  {
5290 +    LIST *l = serv->list;
5291 +
5292 +    /* GROUP command failed */
5293 +    if (!mutt_strncmp ("411", buf, 3))
5294 +    {
5295 +      mutt_error (_("Newsgroup %s not found on server %s"),
5296 +                   nntp_data->group, serv->conn->account.host);
5297 +
5298 +      /* CACHE: delete cache and line from .index */
5299 +      nntp_delete_cache (nntp_data);
5300 +      hash_delete (serv->newsgroups, nntp_data->group, NULL, nntp_delete_data);
5301 +      while (l && l->data != (void *) nntp_data) l = l->next;
5302 +      if (l)
5303 +       l->data = NULL;
5304 +
5305 +      sleep (2);
5306 +    }
5307 +
5308 +    return -1;
5309 +  }
5310 +
5311 +  sscanf (buf + 4, "%d %u %u %s", &count, &nntp_data->firstMessage, 
5312 +         &nntp_data->lastMessage, buf);
5313 +
5314 +  nntp_data->deleted = 0;
5315 +
5316 +  time (&serv->check_time);
5317 +
5318 +  /*
5319 +   * Check for max adding context. If it is greater than $nntp_context,
5320 +   * strip off extra articles
5321 +   */
5322 +  first = nntp_data->firstMessage;
5323 +  if (NntpContext && nntp_data->lastMessage - first + 1 > NntpContext)
5324 +    first = nntp_data->lastMessage - NntpContext + 1;
5325 +  if (first)
5326 +    nntp_data->lastLoaded = first - 1;
5327 +  return nntp_fetch_headers (ctx, first, nntp_data->lastMessage);
5328 +}
5329 +
5330 +int nntp_fetch_message (MESSAGE *msg, CONTEXT *ctx, int msgno)
5331 +{
5332 +  char buf[LONG_STRING];
5333 +  char path[_POSIX_PATH_MAX];
5334 +  NNTP_CACHE *cache;
5335 +  char *m = _("Fetching message...");
5336 +  int ret;
5337 +
5338 +  /* see if we already have the message in our cache */
5339 +  cache = &((NNTP_DATA *) ctx->data)->acache[ctx->hdrs[msgno]->index % NNTP_CACHE_LEN];
5340 +
5341 +  /* if everything is fine, assign msg->fp and return */
5342 +  if (cache->path && cache->index == ctx->hdrs[msgno]->index &&
5343 +      (msg->fp = fopen (cache->path, "r")))
5344 +    return 0;
5345 +
5346 +  /* clear the previous entry */
5347 +  unlink (cache->path);
5348 +  free (cache->path);
5349 +
5350 +  mutt_message (m);
5351 +
5352 +  cache->index = ctx->hdrs[msgno]->index;
5353 +  mutt_mktemp (path);
5354 +  cache->path = safe_strdup (path);
5355 +  if (!(msg->fp = safe_fopen (path, "w+")))
5356 +  {
5357 +    FREE (&cache->path);
5358 +    return -1;
5359 +  }
5360 +
5361 +  if (ctx->hdrs[msgno]->article_num == 0)
5362 +    snprintf (buf, sizeof (buf), "ARTICLE %s\r\n",
5363 +         ctx->hdrs[msgno]->env->message_id);
5364 +  else
5365 +    snprintf (buf, sizeof (buf), "ARTICLE %d\r\n",
5366 +         ctx->hdrs[msgno]->article_num);
5367 +
5368 +  ret = mutt_nntp_fetch ((NNTP_DATA *)ctx->data, buf, m, nntp_read_tempfile,
5369 +       msg->fp, ctx->tagged);
5370 +  if (ret == 1)
5371 +  {
5372 +    mutt_error (_("Article %d not found on server"), 
5373 +         ctx->hdrs[msgno]->article_num);
5374 +    dprint (1, (debugfile, "nntp_fetch_message: %s\n", buf));
5375 +  }
5376 +
5377 +  if (ret)
5378 +  {
5379 +    fclose (msg->fp);
5380 +    unlink (path);
5381 +    FREE (&cache->path);
5382 +    return -1;
5383 +  }
5384 +
5385 +  mutt_free_envelope (&ctx->hdrs[msgno]->env);
5386 +  ctx->hdrs[msgno]->env = mutt_read_rfc822_header (msg->fp, ctx->hdrs[msgno], 0, 0);
5387 +  /* fix content length */
5388 +  fseek(msg->fp, 0, SEEK_END);
5389 +  ctx->hdrs[msgno]->content->length = ftell (msg->fp) - 
5390 +                                        ctx->hdrs[msgno]->content->offset;
5391 +
5392 +  /* this is called in mutt before the open which fetches the message, 
5393 +   * which is probably wrong, but we just call it again here to handle
5394 +   * the problem instead of fixing it.
5395 +   */
5396 +  mutt_parse_mime_message (ctx, ctx->hdrs[msgno]);
5397 +
5398 +  /* These would normally be updated in mx_update_context(), but the 
5399 +   * full headers aren't parsed with XOVER, so the information wasn't
5400 +   * available then.
5401 +   */
5402 +#if defined(HAVE_PGP) || defined(HAVE_SMIME)
5403 +  ctx->hdrs[msgno]->security = crypt_query (ctx->hdrs[msgno]->content);
5404 +#endif /* HAVE_PGP || HAVE_SMIME */
5405 +
5406 +  mutt_clear_error();
5407 +  rewind (msg->fp);
5408 +
5409 +  return 0;
5410 +}
5411 +
5412 +/* Post article */
5413 +int nntp_post (const char *msg) {
5414 +  char buf[LONG_STRING];
5415 +  size_t len;
5416 +  FILE *f;
5417 +  NNTP_DATA *nntp_data;
5418 +
5419 +  if (Context && Context->magic == M_NNTP)
5420 +    nntp_data = (NNTP_DATA *)Context->data;
5421 +  else
5422 +  {
5423 +    if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)) ||
5424 +       !CurrentNewsSrv->list || !CurrentNewsSrv->list->data)
5425 +    {
5426 +      mutt_error (_("Can't post article. No connection to news server."));
5427 +      return -1;
5428 +    }
5429 +    nntp_data = (NNTP_DATA *)CurrentNewsSrv->list->data;
5430 +  }
5431 +
5432 +  if (!(f = safe_fopen (msg, "r")))
5433 +  {
5434 +    mutt_error (_("Can't post article. Unable to open %s"), msg);
5435 +    return -1;
5436 +  }
5437 +
5438 +  strfcpy (buf, "POST\r\n", sizeof (buf));
5439 +  if (mutt_nntp_query (nntp_data, buf, sizeof (buf)) < 0)
5440 +  {
5441 +    mutt_error (_("Can't post article. Connection to %s lost."),
5442 +               nntp_data->nserv->conn->account.host);
5443 +    return -1;
5444 +  }
5445 +  if (buf[0] != '3')
5446 +  {
5447 +    mutt_error (_("Can't post article: %s"), buf);
5448 +    return -1;
5449 +  }
5450 +
5451 +  buf[0] = '.';
5452 +  buf[1] = '\0';
5453 +  while (fgets (buf + 1, sizeof (buf) - 2, f) != NULL)
5454 +  {
5455 +    len = strlen (buf);
5456 +    if (buf[len - 1] == '\n')
5457 +    {
5458 +      buf[len - 1] = '\r';
5459 +      buf[len] = '\n';
5460 +      len++;
5461 +      buf[len] = '\0';
5462 +    }
5463 +    if (buf[1] == '.')
5464 +      mutt_socket_write_d (nntp_data->nserv->conn, buf, -1, M_SOCK_LOG_HDR);
5465 +    else
5466 +      mutt_socket_write_d (nntp_data->nserv->conn, buf + 1, -1, M_SOCK_LOG_HDR);
5467 +  }
5468 +  fclose (f);
5469 +
5470 +  if (buf[strlen (buf) - 1] != '\n')
5471 +    mutt_socket_write_d (nntp_data->nserv->conn, "\r\n", -1, M_SOCK_LOG_HDR);
5472 +  mutt_socket_write_d (nntp_data->nserv->conn, ".\r\n", -1, M_SOCK_LOG_HDR);
5473 +  if (mutt_socket_readln (buf, sizeof (buf), nntp_data->nserv->conn) < 0)
5474 +  {
5475 +    mutt_error (_("Can't post article. Connection to %s lost."),
5476 +               nntp_data->nserv->conn->account.host);
5477 +    return -1;
5478 +  }
5479 +  if (buf[0] != '2')
5480 +  {
5481 +    mutt_error (_("Can't post article: %s"), buf);
5482 +    return -1;
5483 +  }
5484 +
5485 +  return 0;
5486 +}
5487 +
5488 +/* nntp_logout_all: close all open connections. */
5489 +void nntp_logout_all (void)
5490 +{
5491 +  char buf[LONG_STRING];
5492 +  CONNECTION* conn;
5493 +
5494 +  conn = mutt_socket_head ();
5495 +
5496 +  while (conn)
5497 +  {
5498 +    CONNECTION *next = conn->next;
5499 +
5500 +    if (conn->account.type == M_ACCT_TYPE_NNTP)
5501 +    {
5502 +      mutt_message (_("Closing connection to %s..."), conn->account.host);
5503 +      mutt_socket_write (conn, "QUIT\r\n");
5504 +      mutt_socket_readln (buf, sizeof (buf), conn);
5505 +      mutt_clear_error ();
5506 +      mutt_socket_close (conn);
5507 +      mutt_socket_free (conn);
5508 +    }
5509 +
5510 +    conn = next;
5511 +  }
5512 +}
5513 +
5514 +static void nntp_free_acache (NNTP_DATA *data)
5515 +{
5516 +  int i;
5517 +
5518 +  for (i = 0; i < NNTP_CACHE_LEN; i++)
5519 +  {
5520 +    if (data->acache[i].path)
5521 +    {
5522 +      unlink (data->acache[i].path);
5523 +      FREE (&data->acache[i].path);
5524 +    }
5525 +  }
5526 +}
5527 +
5528 +void nntp_delete_data (void *p)
5529 +{
5530 +  NNTP_DATA *data = (NNTP_DATA *)p;
5531 +
5532 +  if (!p)
5533 +    return;
5534 +  FREE (&data->entries);
5535 +  FREE (&data->desc);
5536 +  FREE (&data->cache);
5537 +  nntp_free_acache (data);
5538 +  FREE (p);
5539 +}
5540 +
5541 +int nntp_sync_mailbox (CONTEXT *ctx)
5542 +{
5543 +  NNTP_DATA *data = ctx->data;
5544 +
5545 +  /* CACHE: update cache and .index files */
5546 +  if ((option (OPTSAVEUNSUB) || data->subscribed))
5547 +    nntp_save_cache_group (ctx);
5548 +  nntp_free_acache (data);
5549 +
5550 +  data->nserv->check_time = 0; /* next nntp_check_mailbox() will really check */
5551 +  return 0;
5552 +}
5553 +
5554 +void nntp_fastclose_mailbox (CONTEXT *ctx)
5555 +{
5556 +  NNTP_DATA *data = (NNTP_DATA *) ctx->data, *tmp;
5557 +
5558 +  if (!data)
5559 +    return;
5560 +  nntp_free_acache (data);
5561 +  if (!data->nserv || !data->nserv->newsgroups || !data->group)
5562 +    return;
5563 +  nntp_save_cache_index (data->nserv);
5564 +  if ((tmp = hash_find (data->nserv->newsgroups, data->group)) == NULL
5565 +       || tmp != data)
5566 +    nntp_delete_data (data);
5567 +}
5568 +
5569 +/* commit changes and terminate connection */
5570 +int nntp_close_mailbox (CONTEXT *ctx)
5571 +{
5572 +  if (!ctx)
5573 +    return -1;
5574 +  mutt_message _("Quitting newsgroup...");
5575 +  if (ctx->data)
5576 +  {
5577 +    NNTP_DATA *data = (NNTP_DATA *) ctx->data;
5578 +    int ret;
5579 +
5580 +    if (data->nserv && data->nserv->conn && ctx->unread)
5581 +    {
5582 +      ret = query_quadoption (OPT_CATCHUP, _("Mark all articles read?"));
5583 +      if (ret == M_YES)
5584 +       mutt_newsgroup_catchup (data->nserv, data->group);
5585 +      else if (ret < 0)
5586 +       return -1;
5587 +    }
5588 +  }
5589 +  nntp_sync_mailbox (ctx);
5590 +  if (ctx->data && ((NNTP_DATA *)ctx->data)->nserv)
5591 +  {
5592 +    NNTP_SERVER *news;
5593 +
5594 +    news = ((NNTP_DATA *)ctx->data)->nserv;
5595 +    newsrc_gen_entries (ctx);
5596 +    ((NNTP_DATA *)ctx->data)->unread = ctx->unread;
5597 +    mutt_newsrc_update (news);
5598 +  }
5599 +  mutt_clear_error();
5600 +  return 0;
5601 +}
5602 +
5603 +/* use the GROUP command to poll for new mail */
5604 +static int _nntp_check_mailbox (CONTEXT *ctx, NNTP_DATA *nntp_data)
5605 +{
5606 +  char buf[LONG_STRING];
5607 +  int count = 0;
5608 +
5609 +  if (nntp_data->nserv->check_time + NewsPollTimeout > time (NULL))
5610 +    return 0;
5611 +
5612 +  buf[0] = 0;
5613 +  if (mutt_nntp_query (nntp_data, buf, sizeof (buf)) < 0)
5614 +  {
5615 +#ifdef DEBUG
5616 +    nntp_error ("nntp_check_mailbox()", buf);
5617 +#endif
5618 +    return -1;
5619 +  }
5620 +  if (mutt_strncmp ("211", buf, 3))
5621 +  {
5622 +    buf[0] = 0;
5623 +    if (mutt_nntp_query (nntp_data, buf, sizeof (buf)) < 0)
5624 +    {
5625 +#ifdef DEBUG
5626 +      nntp_error ("nntp_check_mailbox()", buf);
5627 +#endif
5628 +      return -1;
5629 +    }
5630 +  }
5631 +  if (!mutt_strncmp ("211", buf, 3))
5632 +  {
5633 +    int first;
5634 +    int last;
5635 +
5636 +    sscanf (buf + 4, "%d %d %d", &count, &first, &last);
5637 +    nntp_data->firstMessage = first;
5638 +    nntp_data->lastMessage = last;
5639 +    if (ctx && last > nntp_data->lastLoaded)
5640 +    {
5641 +      nntp_fetch_headers (ctx, nntp_data->lastLoaded + 1, last);
5642 +      time (&nntp_data->nserv->check_time);
5643 +      return 1;
5644 +    }
5645 +    if (!last || (!nntp_data->rc && !nntp_data->lastCached))
5646 +      nntp_data->unread = count;
5647 +    else
5648 +      mutt_newsgroup_stat (nntp_data);
5649 +    /* active was renumbered? */
5650 +    if (last < nntp_data->lastLoaded)
5651 +    {
5652 +      if (!nntp_data->max)
5653 +      {
5654 +       nntp_data->entries = safe_calloc (5, sizeof (NEWSRC_ENTRY));
5655 +       nntp_data->max = 5;
5656 +      }
5657 +      nntp_data->lastCached = 0;
5658 +      nntp_data->num = 1;
5659 +      nntp_data->entries[0].first = 1;
5660 +      nntp_data->entries[0].last = 0;
5661 +    }
5662 +  }
5663 +
5664 +  time (&nntp_data->nserv->check_time);
5665 +  return 0;
5666 +}
5667 +
5668 +int nntp_check_mailbox (CONTEXT *ctx)
5669 +{
5670 +  return _nntp_check_mailbox (ctx, (NNTP_DATA *)ctx->data);
5671 +}
5672 +
5673 +static int add_group (char *buf, void *serv)
5674 +{
5675 +#define s ((NNTP_SERVER *) serv)
5676 +  char group[LONG_STRING], mod, desc[HUGE_STRING];
5677 +  int first, last;
5678 +  NNTP_DATA *nntp_data;
5679 +  static int n = 0;
5680 +
5681 +  _checked = n;        /* _checked have N, where N = number of groups */
5682 +  if (!buf)    /* at EOF must be zerouth */
5683 +    n = 0;
5684 +
5685 +  if (!s || !buf)
5686 +    return 0;
5687 +
5688 +  *desc = 0;
5689 +  sscanf (buf, "%s %d %d %c %[^\n]", group, &last, &first, &mod, desc);
5690 +  if (!group)
5691 +    return 0;
5692 +  if ((nntp_data = (NNTP_DATA *) hash_find (s->newsgroups, group)) == NULL)
5693 +  {
5694 +    n++;
5695 +    nntp_data = safe_calloc (1, sizeof (NNTP_DATA) + strlen (group) + 1);
5696 +    nntp_data->group = (char *) nntp_data + sizeof (NNTP_DATA);
5697 +    strcpy (nntp_data->group, group);
5698 +    nntp_data->nserv = s;
5699 +    if (s->newsgroups->nelem < s->newsgroups->curnelem * 2)
5700 +      s->newsgroups = hash_resize (s->newsgroups, s->newsgroups->nelem * 2);
5701 +    hash_insert (s->newsgroups, nntp_data->group, nntp_data, 0);
5702 +    nntp_add_to_list (s, nntp_data);
5703 +  }
5704 +  nntp_data->deleted = 0;
5705 +  nntp_data->firstMessage = first;
5706 +  nntp_data->lastMessage = last;
5707 +  if (mod == 'y')
5708 +    nntp_data->allowed = 1;
5709 +  else
5710 +    nntp_data->allowed = 0;
5711 +  if (nntp_data->desc)
5712 +    FREE (&nntp_data->desc);
5713 +  if (*desc)
5714 +    nntp_data->desc = safe_strdup (desc);
5715 +  if (nntp_data->rc || nntp_data->lastCached)
5716 +    mutt_newsgroup_stat (nntp_data);
5717 +  else if (nntp_data->lastMessage &&
5718 +       nntp_data->firstMessage <= nntp_data->lastMessage)
5719 +    nntp_data->unread = nntp_data->lastMessage - nntp_data->firstMessage + 1;
5720 +  else
5721 +    nntp_data->unread = 0;
5722 +
5723 +  return 0;
5724 +#undef s
5725 +}
5726 +
5727 +int nntp_check_newgroups (NNTP_SERVER *serv, int force)
5728 +{
5729 +  char buf[LONG_STRING];
5730 +  NNTP_DATA nntp_data;
5731 +  LIST *l;
5732 +  LIST emp;
5733 +  time_t now;
5734 +  struct tm *t;
5735 +
5736 +  if (!serv || !serv->newgroups_time)
5737 +    return -1;
5738 +
5739 +  if (nntp_open_connection (serv) < 0)
5740 +    return -1;
5741 +
5742 +  /* check subscribed groups for new news */
5743 +  if (option (OPTSHOWNEWNEWS))
5744 +  {
5745 +    mutt_message _("Checking for new messages...");
5746 +    for (l = serv->list; l; l = l->next)
5747 +    {
5748 +      serv->check_time = 0;    /* really check! */
5749 +      if (l->data && ((NNTP_DATA *) l->data)->subscribed)
5750 +       _nntp_check_mailbox (NULL, (NNTP_DATA *) l->data);
5751 +    }
5752 +  }
5753 +  else if (!force)
5754 +    return 0;
5755 +
5756 +  mutt_message _("Checking for new newsgroups...");
5757 +  now = serv->newgroups_time;
5758 +  time (&serv->newgroups_time);
5759 +  t = gmtime (&now);
5760 +  snprintf (buf, sizeof (buf), "NEWGROUPS %02d%02d%02d %02d%02d%02d GMT\r\n",
5761 +       (t->tm_year % 100), t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min,
5762 +       t->tm_sec);
5763 +  nntp_data.nserv = serv;
5764 +  if (Context && Context->magic == M_NNTP)
5765 +    nntp_data.group = ((NNTP_DATA *)Context->data)->group;
5766 +  else
5767 +    nntp_data.group = NULL;
5768 +  l = serv->tail;
5769 +  if (mutt_nntp_fetch (&nntp_data, buf, _("Adding new newsgroups..."),
5770 +       add_group, serv, 0) != 0)
5771 +  {
5772 +#ifdef DEBUG
5773 +    nntp_error ("nntp_check_newgroups()", buf);
5774 +#endif
5775 +    return -1;
5776 +  }
5777 +
5778 +  mutt_message _("Loading descriptions...");
5779 +  if (l)
5780 +    emp.next = l->next;
5781 +  else
5782 +    emp.next = serv->list;
5783 +  l = &emp;
5784 +  while (l->next)
5785 +  {
5786 +    l = l->next;
5787 +    ((NNTP_DATA *) l->data)->new = 1;
5788 +    nntp_get_desc ((NNTP_DATA *) l->data, ((NNTP_DATA *) l->data)->group, NULL);
5789 +  }
5790 +  if (emp.next)
5791 +    nntp_save_cache_index (serv);
5792 +  mutt_clear_error ();
5793 +  return _checked;
5794 +}
5795 +
5796 +/* Load list of all newsgroups from cache ALL */
5797 +int nntp_get_cache_all (NNTP_SERVER *serv)
5798 +{
5799 +  char buf[HUGE_STRING];
5800 +  FILE *f;
5801 +
5802 +  nntp_cache_expand (buf, serv->cache);
5803 +  if ((f = safe_fopen (buf, "r")))
5804 +  {
5805 +    int i = 0;
5806 +
5807 +    while (fgets (buf, sizeof(buf), f) != NULL)
5808 +    {
5809 +      if (ReadInc && (i % ReadInc == 0))
5810 +       mutt_message (_("Loading list from cache... %d"), i);
5811 +      add_group (buf, serv);
5812 +      i++;
5813 +    }
5814 +    add_group (NULL, NULL);
5815 +    fclose (f);
5816 +    mutt_clear_error ();
5817 +    return 0;
5818 +  }
5819 +  else
5820 +  {
5821 +    FREE (&serv->cache);
5822 +    return -1;
5823 +  }
5824 +}
5825 +
5826 +/* Load list of all newsgroups from active */
5827 +int nntp_get_active (NNTP_SERVER *serv)
5828 +{
5829 +  char msg[SHORT_STRING];
5830 +  NNTP_DATA nntp_data;
5831 +  LIST *tmp;
5832 +
5833 +  if (nntp_open_connection (serv) < 0)
5834 +    return -1;
5835 +
5836 +  snprintf (msg, sizeof(msg), _("Loading list of all newsgroups on server %s..."),
5837 +               serv->conn->account.host);
5838 +  mutt_message (msg);
5839 +  time (&serv->newgroups_time);
5840 +  nntp_data.nserv = serv;
5841 +  nntp_data.group = NULL;
5842 +
5843 +  if (mutt_nntp_fetch (&nntp_data, "LIST\r\n", msg, add_group, serv, 0) < 0)
5844 +  {
5845 +#ifdef DEBUG
5846 +    nntp_error ("nntp_get_active()", "LIST\r\n");
5847 +#endif
5848 +    return -1;
5849 +  }
5850 +
5851 +  strfcpy (msg, _("Loading descriptions..."), sizeof (msg));
5852 +  mutt_message (msg);
5853 +  nntp_get_desc (&nntp_data, "*", msg);
5854 +
5855 +  for (tmp = serv->list; tmp; tmp = tmp->next)
5856 +  {
5857 +    NNTP_DATA *data = (NNTP_DATA *)tmp->data;
5858 +
5859 +    if (data && data->deleted && !data->rc)
5860 +    {
5861 +      nntp_delete_cache (data);
5862 +      hash_delete (serv->newsgroups, data->group, NULL, nntp_delete_data);
5863 +      tmp->data = NULL;
5864 +    }
5865 +  }
5866 +  nntp_save_cache_index (serv);
5867 +
5868 +  mutt_clear_error ();
5869 +  return _checked;
5870 +}
5871 +
5872 +/*
5873 + * returns -1 if error ocurred while retrieving header,
5874 + * number of articles which ones exist in context on success.
5875 + */
5876 +int nntp_check_msgid (CONTEXT *ctx, const char *msgid)
5877 +{
5878 +  int ret;
5879 +
5880 +  /* if msgid is already in context, don't reload them */
5881 +  if (hash_find (ctx->id_hash, msgid))
5882 +    return 1;
5883 +  if (ctx->msgcount == ctx->hdrmax)
5884 +    mx_alloc_memory (ctx);
5885 +  ctx->hdrs[ctx->msgcount] = mutt_new_header ();
5886 +  ctx->hdrs[ctx->msgcount]->index = ctx->msgcount;
5887 +  
5888 +  mutt_message (_("Fetching %s from server..."), msgid);
5889 +  ret = nntp_read_header (ctx, msgid, 0);
5890 +  /* since nntp_read_header() may set read flag, we must reset it */
5891 +  ctx->hdrs[ctx->msgcount]->read = 0;
5892 +  if (ret != 0)
5893 +    mutt_free_header (&ctx->hdrs[ctx->msgcount]);
5894 +  else
5895 +  {
5896 +    ctx->msgcount++;
5897 +    mx_update_context (ctx, 1);
5898 +    ctx->changed = 1;
5899 +  }
5900 +  return ret;
5901 +}
5902 +
5903 +typedef struct
5904 +{
5905 +  CONTEXT *ctx;
5906 +  unsigned int num;
5907 +  unsigned int max;
5908 +  unsigned int *child;
5909 +} CHILD_CONTEXT;
5910 +
5911 +static int check_children (char *s, void *c)
5912 +{
5913 +#define cc ((CHILD_CONTEXT *) c)
5914 +  unsigned int i, n;
5915 +
5916 +  if (!s || (n = atoi (s)) == 0)
5917 +    return 0;
5918 +  for (i = 0; i < cc->ctx->msgcount; i++)
5919 +    if (cc->ctx->hdrs[i]->article_num == n)
5920 +      return 0;
5921 +  if (cc->num >= cc->max)
5922 +    safe_realloc (&cc->child, sizeof (unsigned int) * (cc->max += 25));
5923 +  cc->child[cc->num++] = n;
5924 +
5925 +  return 0;
5926 +#undef cc
5927 +}
5928 +
5929 +int nntp_check_children (CONTEXT *ctx, const char *msgid)
5930 +{
5931 +  NNTP_DATA *nntp_data = (NNTP_DATA *)ctx->data;
5932 +  char buf[STRING];
5933 +  int i, ret = 0, tmp = 0;
5934 +  CHILD_CONTEXT cc;
5935 +
5936 +  if (!nntp_data || !nntp_data->nserv || !nntp_data->nserv->conn ||
5937 +       !nntp_data->nserv->conn->account.host)
5938 +    return -1;
5939 +  if (nntp_data->firstMessage > nntp_data->lastLoaded)
5940 +    return 0;
5941 +  if (!nntp_data->nserv->hasXPAT)
5942 +  {
5943 +    mutt_error (_("Server %s does not support this operation!"),
5944 +         nntp_data->nserv->conn->account.host);
5945 +    return -1;
5946 +  }
5947 +
5948 +  snprintf (buf, sizeof (buf), "XPAT References %d-%d *%s*\r\n", 
5949 +       nntp_data->firstMessage, nntp_data->lastLoaded, msgid);
5950 +
5951 +  cc.ctx = ctx;
5952 +  cc.num = 0;
5953 +  cc.max = 25;
5954 +  cc.child = safe_malloc (sizeof (unsigned int) * 25);
5955 +  if (mutt_nntp_fetch (nntp_data, buf, NULL, check_children, &cc, 0))
5956 +  {
5957 +    FREE (&cc.child);
5958 +    return -1;
5959 +  }
5960 +  /* dont try to read the xover cache. check_children() already
5961 +   * made sure that we dont have the article, so we need to visit
5962 +   * the server. Reading the cache at this point is also bad
5963 +   * because it would duplicate messages */
5964 +  if (option (OPTNEWSCACHE))
5965 +  {
5966 +    tmp++;
5967 +    unset_option (OPTNEWSCACHE);
5968 +  }
5969 +  for (i = 0; i < cc.num; i++)
5970 +  {
5971 +    if ((ret = nntp_fetch_headers (ctx, cc.child[i], cc.child[i])))
5972 +      break;
5973 +    if (ctx->msgcount &&
5974 +         ctx->hdrs[ctx->msgcount - 1]->article_num == cc.child[i])
5975 +      ctx->hdrs[ctx->msgcount - 1]->read = 0;
5976 +  }
5977 +  if (tmp)
5978 +    set_option (OPTNEWSCACHE);
5979 +  FREE (&cc.child);
5980 +  return ret;
5981 +}
5982 diff -udprP mutt-1.5.13.orig/nntp.h mutt-1.5.13/nntp.h
5983 --- mutt-1.5.13.orig/nntp.h     1970-01-01 03:00:00.000000000 +0300
5984 +++ mutt-1.5.13/nntp.h  2006-08-15 13:04:56.000000000 +0300
5985 @@ -0,0 +1,136 @@
5986 +/*
5987 + * Copyright (C) 1998 Brandon Long <blong@fiction.net>
5988 + * Copyright (C) 1999 Andrej Gritsenko <andrej@lucky.net>
5989 + * Copyright (C) 2000-2004 Vsevolod Volkov <vvv@mutt.org.ua>
5990 + * 
5991 + *     This program is free software; you can redistribute it and/or modify
5992 + *     it under the terms of the GNU General Public License as published by
5993 + *     the Free Software Foundation; either version 2 of the License, or
5994 + *     (at your option) any later version.
5995 + * 
5996 + *     This program is distributed in the hope that it will be useful,
5997 + *     but WITHOUT ANY WARRANTY; without even the implied warranty of
5998 + *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
5999 + *     GNU General Public License for more details.
6000 + * 
6001 + *     You should have received a copy of the GNU General Public License
6002 + *     along with this program; if not, write to the Free Software
6003 + *     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
6004 + */ 
6005 +
6006 +#ifndef _NNTP_H_
6007 +#define _NNTP_H_ 1
6008 +
6009 +#include "mutt_socket.h"
6010 +#include "mailbox.h"
6011 +
6012 +#include <time.h>
6013 +
6014 +#define NNTP_PORT 119
6015 +#define NNTP_SSL_PORT 563
6016 +
6017 +/* number of entries in the hash table */
6018 +#define NNTP_CACHE_LEN 10
6019 +
6020 +enum
6021 +{
6022 +  NNTP_NONE = 0,
6023 +  NNTP_OK,
6024 +  NNTP_BYE
6025 +};
6026 +
6027 +typedef struct
6028 +{
6029 +  int first;
6030 +  int last;
6031 +} NEWSRC_ENTRY;
6032 +
6033 +typedef struct
6034 +{
6035 +  unsigned int hasXPAT : 1;
6036 +  unsigned int hasXGTITLE : 1;
6037 +  unsigned int hasXOVER : 1;
6038 +  unsigned int hasLISTGROUP : 1;
6039 +  unsigned int status : 3;
6040 +  char *newsrc;
6041 +  char *cache;
6042 +  int stat;
6043 +  off_t size;
6044 +  time_t mtime;
6045 +  time_t newgroups_time;
6046 +  time_t check_time;
6047 +  HASH *newsgroups;
6048 +  LIST *list;  /* list of newsgroups */
6049 +  LIST *tail;  /* last entry of list */
6050 +  CONNECTION *conn;
6051 +} NNTP_SERVER;
6052 +
6053 +typedef struct
6054 +{
6055 +  unsigned int index;
6056 +  char *path;
6057 +} NNTP_CACHE;
6058 +
6059 +typedef struct
6060 +{
6061 +  NEWSRC_ENTRY *entries;
6062 +  unsigned int num;    /* number of used entries */
6063 +  unsigned int max;    /* number of allocated entries */
6064 +  unsigned int unread;
6065 +  unsigned int firstMessage;
6066 +  unsigned int lastMessage;
6067 +  unsigned int lastLoaded;
6068 +  unsigned int lastCached;
6069 +  unsigned int subscribed : 1;
6070 +  unsigned int rc : 1;
6071 +  unsigned int new : 1;
6072 +  unsigned int allowed : 1;
6073 +  unsigned int deleted : 1;
6074 +  char *group;
6075 +  char *desc;
6076 +  char *cache;
6077 +  NNTP_SERVER *nserv;
6078 +  NNTP_CACHE acache[NNTP_CACHE_LEN];
6079 +} NNTP_DATA;
6080 +
6081 +/* internal functions */
6082 +int nntp_get_active (NNTP_SERVER *);
6083 +int nntp_get_cache_all (NNTP_SERVER *);
6084 +int nntp_save_cache_index (NNTP_SERVER *);
6085 +int nntp_check_newgroups (NNTP_SERVER *, int);
6086 +int nntp_save_cache_group (CONTEXT *);
6087 +int nntp_parse_url (const char *, ACCOUNT *, char *, size_t);
6088 +void newsrc_gen_entries (CONTEXT *);
6089 +void nntp_get_status (CONTEXT *, HEADER *, char *, int);
6090 +void mutt_newsgroup_stat (NNTP_DATA *);
6091 +void nntp_delete_cache (NNTP_DATA *);
6092 +void nntp_add_to_list (NNTP_SERVER *, NNTP_DATA *);
6093 +void nntp_cache_expand (char *, const char *);
6094 +void nntp_delete_data (void *);
6095 +
6096 +/* exposed interface */
6097 +NNTP_SERVER *mutt_select_newsserver (char *);
6098 +NNTP_DATA *mutt_newsgroup_subscribe (NNTP_SERVER *, char *);
6099 +NNTP_DATA *mutt_newsgroup_unsubscribe (NNTP_SERVER *, char *);
6100 +NNTP_DATA *mutt_newsgroup_catchup (NNTP_SERVER *, char *);
6101 +NNTP_DATA *mutt_newsgroup_uncatchup (NNTP_SERVER *, char *);
6102 +void nntp_clear_cacheindex (NNTP_SERVER *);
6103 +int mutt_newsrc_update (NNTP_SERVER *);
6104 +int nntp_open_mailbox (CONTEXT *);
6105 +int nntp_sync_mailbox (CONTEXT *);
6106 +int nntp_check_mailbox (CONTEXT *);
6107 +int nntp_close_mailbox (CONTEXT *);
6108 +void nntp_fastclose_mailbox (CONTEXT *);
6109 +int nntp_fetch_message (MESSAGE *, CONTEXT *, int);
6110 +int nntp_post (const char *);
6111 +int nntp_check_msgid (CONTEXT *, const char *);
6112 +int nntp_check_children (CONTEXT *, const char *);
6113 +void nntp_buffy (char *);
6114 +void nntp_expand_path (char *, size_t, ACCOUNT *);
6115 +void nntp_logout_all ();
6116 +const char *nntp_format_str (char *, size_t, char, const char *, const char *,
6117 +               const char *, const char *, unsigned long, format_flag);
6118 +
6119 +NNTP_SERVER *CurrentNewsSrv INITVAL (NULL);
6120 +
6121 +#endif /* _NNTP_H_ */
6122 diff -udprP mutt-1.5.13.orig/pager.c mutt-1.5.13/pager.c
6123 --- mutt-1.5.13.orig/pager.c    2006-05-18 21:44:29.000000000 +0300
6124 +++ mutt-1.5.13/pager.c 2006-08-15 13:04:56.000000000 +0300
6125 @@ -1059,6 +1059,11 @@ fill_buffer (FILE *f, LOFF_T *last_pos, 
6126    return b_read;
6127  }
6128  
6129 +#ifdef USE_NNTP
6130 +#include "mx.h"
6131 +#include "nntp.h"
6132 +#endif
6133 +
6134  
6135  static int format_line (struct line_t **lineInfo, int n, unsigned char *buf,
6136                         int flags, ansi_attr *pa, int cnt,
6137 @@ -1497,6 +1502,16 @@ static struct mapping_t PagerHelpExtra[]
6138    { NULL,      0 }
6139  };
6140  
6141 +#ifdef USE_NNTP
6142 +static struct mapping_t PagerNewsHelpExtra[] = {
6143 +  { N_("Post"),     OP_POST },
6144 +  { N_("Followup"), OP_FOLLOWUP },
6145 +  { N_("Del"),      OP_DELETE },
6146 +  { N_("Next"),     OP_MAIN_NEXT_UNDELETED },
6147 +  { NULL,           0 }
6148 +};
6149 +#endif
6150 +
6151  
6152  
6153  /* This pager is actually not so simple as it once was.  It now operates in
6154 @@ -1538,6 +1553,10 @@ mutt_pager (const char *banner, const ch
6155    int old_PagerIndexLines;             /* some people want to resize it
6156                                          * while inside the pager... */
6157  
6158 +#ifdef USE_NNTP
6159 +  char *followup_to;
6160 +#endif
6161 +
6162    if (!(flags & M_SHOWCOLOR))
6163      flags |= M_SHOWFLAT;
6164  
6165 @@ -1577,7 +1596,11 @@ mutt_pager (const char *banner, const ch
6166    if (IsHeader (extra))
6167    {
6168      strfcpy (tmphelp, helpstr, sizeof (tmphelp));
6169 -    mutt_compile_help (buffer, sizeof (buffer), MENU_PAGER, PagerHelpExtra);
6170 +    mutt_compile_help (buffer, sizeof (buffer), MENU_PAGER,
6171 +#ifdef USE_NNTP
6172 +       (Context && (Context->magic == M_NNTP)) ? PagerNewsHelpExtra :
6173 +#endif
6174 +       PagerHelpExtra);
6175      snprintf (helpstr, sizeof (helpstr), "%s %s", tmphelp, buffer);
6176    }
6177    if (!InHelp)
6178 @@ -2418,6 +2441,15 @@ CHECK_IMAP_ACL(IMAP_ACL_DELETE);
6179  CHECK_IMAP_ACL(IMAP_ACL_WRITE);
6180  #endif
6181  
6182 +#ifdef USE_NNTP
6183 +       if (Context->magic == M_NNTP)
6184 +       {
6185 +         mutt_flushinp ();
6186 +         mutt_error _("Can't change 'important' flag on NNTP server.");
6187 +         break;
6188 +       }
6189 +#endif
6190 +
6191         mutt_set_flag (Context, extra->hdr, M_FLAG, !extra->hdr->flagged);
6192         redraw = REDRAW_STATUS | REDRAW_INDEX;
6193         if (option (OPTRESOLVE))
6194 @@ -2451,6 +2483,60 @@ CHECK_IMAP_ACL(IMAP_ACL_WRITE);
6195         redraw = REDRAW_FULL;
6196         break;
6197  
6198 +#ifdef USE_NNTP
6199 +      case OP_POST:
6200 +       CHECK_MODE(IsHeader (extra) && !IsAttach (extra));
6201 +       CHECK_ATTACH;
6202 +       if (extra->ctx && extra->ctx->magic == M_NNTP &&
6203 +           !((NNTP_DATA *)extra->ctx->data)->allowed &&
6204 +           query_quadoption (OPT_TOMODERATED,_("Posting to this group not allowed, may be moderated. Continue?")) != M_YES)
6205 +         break;
6206 +       ci_send_message (SENDNEWS, NULL, NULL, extra->ctx, NULL);
6207 +       redraw = REDRAW_FULL;
6208 +       break;
6209 +
6210 +      case OP_FORWARD_TO_GROUP:
6211 +       CHECK_MODE(IsHeader (extra) || IsMsgAttach (extra));
6212 +       CHECK_ATTACH;
6213 +       if (extra->ctx && extra->ctx->magic == M_NNTP &&
6214 +           !((NNTP_DATA *)extra->ctx->data)->allowed &&
6215 +           query_quadoption (OPT_TOMODERATED,_("Posting to this group not allowed, may be moderated. Continue?")) != M_YES)
6216 +         break;
6217 +       if (IsMsgAttach (extra))
6218 +         mutt_attach_forward (extra->fp, extra->hdr, extra->idx,
6219 +                              extra->idxlen, extra->bdy, SENDNEWS);
6220 +       else
6221 +         ci_send_message (SENDNEWS|SENDFORWARD, NULL, NULL, extra->ctx, extra->hdr);
6222 +       redraw = REDRAW_FULL;
6223 +       break;
6224 +
6225 +      case OP_FOLLOWUP:
6226 +       CHECK_MODE(IsHeader (extra) || IsMsgAttach (extra));
6227 +       CHECK_ATTACH;
6228 +
6229 +        if (IsMsgAttach (extra))
6230 +         followup_to = extra->bdy->hdr->env->followup_to;
6231 +        else
6232 +         followup_to = extra->hdr->env->followup_to;
6233 +
6234 +       if (!followup_to || mutt_strcasecmp (followup_to, "poster") ||
6235 +           query_quadoption (OPT_FOLLOWUPTOPOSTER,_("Reply by mail as poster prefers?")) != M_YES)
6236 +       {
6237 +         if (extra->ctx && extra->ctx->magic == M_NNTP &&
6238 +             !((NNTP_DATA *)extra->ctx->data)->allowed &&
6239 +             query_quadoption (OPT_TOMODERATED,_("Posting to this group not allowed, may be moderated. Continue?")) != M_YES)
6240 +           break;
6241 +         if (IsMsgAttach (extra))
6242 +           mutt_attach_reply (extra->fp, extra->hdr, extra->idx,
6243 +                              extra->idxlen, extra->bdy, SENDNEWS|SENDREPLY);
6244 +         else
6245 +           ci_send_message (SENDNEWS|SENDREPLY, NULL, NULL,
6246 +                            extra->ctx, extra->hdr);
6247 +         redraw = REDRAW_FULL;
6248 +         break;
6249 +       }
6250 +#endif
6251 +
6252        case OP_REPLY:
6253         CHECK_MODE(IsHeader (extra) || IsMsgAttach (extra));
6254          CHECK_ATTACH;      
6255 @@ -2497,7 +2583,7 @@ CHECK_IMAP_ACL(IMAP_ACL_WRITE);
6256          CHECK_ATTACH;
6257          if (IsMsgAttach (extra))
6258           mutt_attach_forward (extra->fp, extra->hdr, extra->idx,
6259 -                              extra->idxlen, extra->bdy);
6260 +                              extra->idxlen, extra->bdy, 0);
6261          else
6262           ci_send_message (SENDFORWARD, NULL, NULL, extra->ctx, extra->hdr);
6263         redraw = REDRAW_FULL;
6264 diff -udprP mutt-1.5.13.orig/parse.c mutt-1.5.13/parse.c
6265 --- mutt-1.5.13.orig/parse.c    2006-04-28 22:48:32.000000000 +0300
6266 +++ mutt-1.5.13/parse.c 2006-08-15 13:04:56.000000000 +0300
6267 @@ -89,7 +89,7 @@ char *mutt_read_rfc822_line (FILE *f, ch
6268    /* not reached */
6269  }
6270  
6271 -static LIST *mutt_parse_references (char *s, int in_reply_to)
6272 +LIST *mutt_parse_references (char *s, int in_reply_to)
6273  {
6274    LIST *t, *lst = NULL;
6275    int m, n = 0;
6276 @@ -1052,6 +1052,17 @@ int mutt_parse_rfc822_line (ENVELOPE *e,
6277        e->from = rfc822_parse_adrlist (e->from, p);
6278        matched = 1;
6279      }
6280 +#ifdef USE_NNTP
6281 +    else if (!mutt_strcasecmp (line+1, "ollowup-to"))
6282 +    {
6283 +      if (!e->followup_to)
6284 +      {
6285 +       mutt_remove_trailing_ws (p);
6286 +       e->followup_to = safe_strdup (mutt_skip_whitespace (p));
6287 +      }
6288 +      matched = 1;
6289 +    }
6290 +#endif
6291      break;
6292      
6293      case 'i':
6294 @@ -1136,6 +1147,27 @@ int mutt_parse_rfc822_line (ENVELOPE *e,
6295      }
6296      break;
6297      
6298 +#ifdef USE_NNTP
6299 +    case 'n':
6300 +    if (!mutt_strcasecmp (line + 1, "ewsgroups"))
6301 +    {
6302 +      FREE (&e->newsgroups);
6303 +      mutt_remove_trailing_ws (p);
6304 +      e->newsgroups = safe_strdup (mutt_skip_whitespace (p));
6305 +      matched = 1;
6306 +    }
6307 +    break;
6308 +#endif
6309 +
6310 +    case 'o':
6311 +    /* field `Organization:' saves only for pager! */
6312 +    if (!mutt_strcasecmp (line + 1, "rganization"))
6313 +    {
6314 +      if (!e->organization && mutt_strcasecmp (p, "unknown"))
6315 +       e->organization = safe_strdup (p);
6316 +    }
6317 +    break;
6318 +
6319      case 'r':
6320      if (!ascii_strcasecmp (line + 1, "eferences"))
6321      {
6322 @@ -1244,6 +1276,20 @@ int mutt_parse_rfc822_line (ENVELOPE *e,
6323        e->x_label = safe_strdup(p);
6324        matched = 1;
6325      }
6326 +#ifdef USE_NNTP
6327 +    else if (!mutt_strcasecmp (line + 1, "-comment-to"))
6328 +    {
6329 +      if (!e->x_comment_to)
6330 +       e->x_comment_to = safe_strdup (p);
6331 +      matched = 1;
6332 +    }
6333 +    else if (!mutt_strcasecmp (line + 1, "ref"))
6334 +    {
6335 +      if (!e->xref)
6336 +       e->xref = safe_strdup (p);
6337 +      matched = 1;
6338 +    }
6339 +#endif
6340      
6341      default:
6342      break;
6343 diff -udprP mutt-1.5.13.orig/pattern.c mutt-1.5.13/pattern.c
6344 --- mutt-1.5.13.orig/pattern.c  2006-08-11 12:32:58.000000000 +0300
6345 +++ mutt-1.5.13/pattern.c       2006-08-15 13:04:56.000000000 +0300
6346 @@ -90,6 +90,9 @@ Flags[] =
6347    { 'U', M_UNREAD,             0,              NULL },
6348    { 'v', M_COLLAPSED,          0,              NULL },
6349    { 'V', M_CRYPT_VERIFIED,     0,              NULL },
6350 +#ifdef USE_NNTP
6351 +  { 'w', M_NEWSGROUPS,         0,              eat_regexp },
6352 +#endif
6353    { 'x', M_REFERENCE,          0,              eat_regexp },
6354    { 'X', M_MIMEATTACH,         0,              eat_range },
6355    { 'y', M_XLABEL,             0,              eat_regexp },
6356 @@ -1197,6 +1200,10 @@ mutt_pattern_exec (struct pattern_t *pat
6357        }
6358      case M_UNREFERENCED:
6359        return (pat->not ^ (h->thread && !h->thread->child));
6360 +#ifdef USE_NNTP
6361 +    case M_NEWSGROUPS:
6362 +      return (pat->not ^ (h->env->newsgroups && patmatch (pat, h->env->newsgroups) == 0));
6363 +#endif
6364    }
6365    mutt_error (_("error: unknown op %d (report this error)."), pat->op);
6366    return (-1);
6367 @@ -1264,6 +1271,7 @@ int mutt_pattern_func (int op, char *pro
6368    int i;
6369  
6370    strfcpy (buf, NONULL (Context->pattern), sizeof (buf));
6371 +  if (prompt || op != M_LIMIT)
6372    if (mutt_get_field (prompt, buf, sizeof (buf), M_PATTERN | M_CLEAR) != 0 || !buf[0])
6373      return (-1);
6374  
6375 diff -udprP mutt-1.5.13.orig/po/POTFILES.in mutt-1.5.13/po/POTFILES.in
6376 --- mutt-1.5.13.orig/po/POTFILES.in     2005-08-03 12:17:47.000000000 +0300
6377 +++ mutt-1.5.13/po/POTFILES.in  2006-08-15 13:04:56.000000000 +0300
6378 @@ -45,6 +45,8 @@ mutt_ssl_gnutls.c
6379  mutt_tunnel.c
6380  muttlib.c
6381  mx.c
6382 +newsrc.c
6383 +nntp.c
6384  pager.c
6385  parse.c
6386  pattern.c
6387 diff -udprP mutt-1.5.13.orig/postpone.c mutt-1.5.13/postpone.c
6388 --- mutt-1.5.13.orig/postpone.c 2006-04-20 19:46:35.000000000 +0300
6389 +++ mutt-1.5.13/postpone.c      2006-08-15 13:04:56.000000000 +0300
6390 @@ -126,15 +126,26 @@ int mutt_num_postponed (int force)
6391  
6392    if (LastModify < st.st_mtime)
6393    {
6394 +#ifdef USE_NNTP
6395 +    int optnews = option (OPTNEWS);
6396 +#endif
6397      LastModify = st.st_mtime;
6398  
6399      if (access (Postponed, R_OK | F_OK) != 0)
6400        return (PostCount = 0);
6401 +#ifdef USE_NNTP
6402 +    if (optnews)
6403 +       unset_option (OPTNEWS);
6404 +#endif
6405      if (mx_open_mailbox (Postponed, M_NOSORT | M_QUIET, &ctx) == NULL)
6406        PostCount = 0;
6407      else
6408        PostCount = ctx.msgcount;
6409      mx_fastclose_mailbox (&ctx);
6410 +#ifdef USE_NNTP
6411 +    if (optnews)
6412 +       set_option (OPTNEWS);
6413 +#endif
6414    }
6415  
6416    return (PostCount);
6417 diff -udprP mutt-1.5.13.orig/protos.h mutt-1.5.13/protos.h
6418 --- mutt-1.5.13.orig/protos.h   2006-07-12 02:32:28.000000000 +0300
6419 +++ mutt-1.5.13/protos.h        2006-08-15 13:04:56.000000000 +0300
6420 @@ -110,6 +110,7 @@ HASH *mutt_make_id_hash (CONTEXT *);
6421  HASH *mutt_make_subj_hash (CONTEXT *);
6422  
6423  LIST *mutt_make_references(ENVELOPE *e);
6424 +LIST *mutt_parse_references (char *, int);
6425  
6426  char *mutt_read_rfc822_line (FILE *, char *, size_t *);
6427  ENVELOPE *mutt_read_rfc822_header (FILE *, HEADER *, short, short);
6428 @@ -251,6 +252,7 @@ void mutt_unblock_signals_system (int);
6429  void mutt_update_encoding (BODY *a);
6430  void mutt_version (void);
6431  void mutt_view_attachments (HEADER *);
6432 +void mutt_write_references (LIST *, FILE *);
6433  void mutt_write_address_list (ADDRESS *adr, FILE *fp, int linelen, int display);
6434  void mutt_set_virtual (CONTEXT *);
6435  
6436 diff -udprP mutt-1.5.13.orig/recvattach.c mutt-1.5.13/recvattach.c
6437 --- mutt-1.5.13.orig/recvattach.c       2006-04-18 18:25:33.000000000 +0300
6438 +++ mutt-1.5.13/recvattach.c    2006-08-15 13:04:56.000000000 +0300
6439 @@ -1087,6 +1087,15 @@ void mutt_view_attachments (HEADER *hdr)
6440         }
6441  #endif
6442  
6443 +#ifdef USE_NNTP
6444 +       if (Context->magic == M_NNTP)
6445 +       {
6446 +         mutt_flushinp ();
6447 +         mutt_error _("Can't delete attachment from newsserver.");
6448 +         break;
6449 +       }
6450 +#endif
6451 +
6452          if (WithCrypto && hdr->security & ~PGP_TRADITIONAL_CHECKED)
6453          {
6454           mutt_message _(
6455 @@ -1178,10 +1187,33 @@ void mutt_view_attachments (HEADER *hdr)
6456        case OP_FORWARD_MESSAGE:
6457          CHECK_ATTACH;
6458          mutt_attach_forward (fp, hdr, idx, idxlen,
6459 -                            menu->tagprefix ? NULL : idx[menu->current]->content);
6460 +                            menu->tagprefix ? NULL : idx[menu->current]->content, 0);
6461          menu->redraw = REDRAW_FULL;
6462          break;
6463        
6464 +#ifdef USE_NNTP
6465 +      case OP_FORWARD_TO_GROUP:
6466 +       CHECK_ATTACH;
6467 +       mutt_attach_forward (fp, hdr, idx, idxlen,
6468 +               menu->tagprefix ? NULL : idx[menu->current]->content, SENDNEWS);
6469 +       menu->redraw = REDRAW_FULL;
6470 +       break;
6471 +
6472 +      case OP_FOLLOWUP:
6473 +       CHECK_ATTACH;
6474 +
6475 +       if (!idx[menu->current]->content->hdr->env->followup_to ||
6476 +           mutt_strcasecmp (idx[menu->current]->content->hdr->env->followup_to, "poster") ||
6477 +           query_quadoption (OPT_FOLLOWUPTOPOSTER,_("Reply by mail as poster prefers?")) != M_YES)
6478 +       {
6479 +         mutt_attach_reply (fp, hdr, idx, idxlen,
6480 +               menu->tagprefix ? NULL : idx[menu->current]->content,
6481 +               SENDNEWS|SENDREPLY);
6482 +         menu->redraw = REDRAW_FULL;
6483 +         break;
6484 +       }
6485 +#endif
6486 +
6487        case OP_REPLY:
6488        case OP_GROUP_REPLY:
6489        case OP_LIST_REPLY:
6490 diff -udprP mutt-1.5.13.orig/recvcmd.c mutt-1.5.13/recvcmd.c
6491 --- mutt-1.5.13.orig/recvcmd.c  2005-09-18 11:22:22.000000000 +0300
6492 +++ mutt-1.5.13/recvcmd.c       2006-08-15 13:04:56.000000000 +0300
6493 @@ -377,7 +377,7 @@ static BODY ** copy_problematic_attachme
6494  static void attach_forward_bodies (FILE * fp, HEADER * hdr,
6495                                    ATTACHPTR ** idx, short idxlen,
6496                                    BODY * cur,
6497 -                                  short nattach)
6498 +                                  short nattach, int flags)
6499  {
6500    short i;
6501    short mime_fwd_all = 0;
6502 @@ -523,7 +523,7 @@ _("Can't decode all tagged attachments. 
6503    tmpfp = NULL;
6504  
6505    /* now that we have the template, send it. */
6506 -  ci_send_message (0, tmphdr, tmpbody, NULL, parent);
6507 +  ci_send_message (flags, tmphdr, tmpbody, NULL, parent);
6508    return;
6509    
6510    bail:
6511 @@ -550,7 +550,7 @@ _("Can't decode all tagged attachments. 
6512   */
6513  
6514  static void attach_forward_msgs (FILE * fp, HEADER * hdr, 
6515 -              ATTACHPTR ** idx, short idxlen, BODY * cur)
6516 +              ATTACHPTR ** idx, short idxlen, BODY * cur, int flags)
6517  {
6518    HEADER *curhdr = NULL;
6519    HEADER *tmphdr;
6520 @@ -655,23 +655,23 @@ static void attach_forward_msgs (FILE * 
6521    else
6522      mutt_free_header (&tmphdr);
6523  
6524 -  ci_send_message (0, tmphdr, *tmpbody ? tmpbody : NULL, 
6525 +  ci_send_message (flags, tmphdr, *tmpbody ? tmpbody : NULL, 
6526                    NULL, curhdr);
6527  
6528  }
6529  
6530  void mutt_attach_forward (FILE * fp, HEADER * hdr, 
6531 -                         ATTACHPTR ** idx, short idxlen, BODY * cur)
6532 +                         ATTACHPTR ** idx, short idxlen, BODY * cur, int flags)
6533  {
6534    short nattach;
6535    
6536  
6537    if (check_all_msg (idx, idxlen, cur, 0) == 0)
6538 -    attach_forward_msgs (fp, hdr, idx, idxlen, cur);
6539 +    attach_forward_msgs (fp, hdr, idx, idxlen, cur, flags);
6540    else
6541    {
6542      nattach = count_tagged (idx, idxlen);
6543 -    attach_forward_bodies (fp, hdr, idx, idxlen, cur, nattach);
6544 +    attach_forward_bodies (fp, hdr, idx, idxlen, cur, nattach, flags);
6545    }
6546  }
6547  
6548 @@ -729,28 +729,40 @@ attach_reply_envelope_defaults (ENVELOPE
6549      return -1;
6550    }
6551  
6552 -  if (parent)
6553 +#ifdef USE_NNTP
6554 +  if ((flags & SENDNEWS))
6555    {
6556 -    if (mutt_fetch_recips (env, curenv, flags) == -1)
6557 -      return -1;
6558 +    /* in case followup set Newsgroups: with Followup-To: if it present */
6559 +    if (!env->newsgroups && curenv &&
6560 +       mutt_strcasecmp (curenv->followup_to, "poster"))
6561 +      env->newsgroups = safe_strdup (curenv->followup_to);
6562    }
6563    else
6564 +#endif
6565    {
6566 -    for (i = 0; i < idxlen; i++)
6567 +    if (parent)
6568      {
6569 -      if (idx[i]->content->tagged
6570 -         && mutt_fetch_recips (env, idx[i]->content->hdr->env, flags) == -1)
6571 +      if (mutt_fetch_recips (env, curenv, flags) == -1)
6572         return -1;
6573      }
6574 +    else
6575 +    {
6576 +      for (i = 0; i < idxlen; i++)
6577 +      {
6578 +       if (idx[i]->content->tagged
6579 +           && mutt_fetch_recips (env, idx[i]->content->hdr->env, flags) == -1)
6580 +         return -1;
6581 +      }
6582 +    }
6583 +
6584 +    if ((flags & SENDLISTREPLY) && !env->to)
6585 +    {
6586 +      mutt_error _("No mailing lists found!");
6587 +      return (-1);
6588 +    }
6589 +
6590 +    mutt_fix_reply_recipients (env);
6591    }
6592 -  
6593 -  if ((flags & SENDLISTREPLY) && !env->to)
6594 -  {
6595 -    mutt_error _("No mailing lists found!");
6596 -    return (-1);
6597 -  }
6598 -  
6599 -  mutt_fix_reply_recipients (env);
6600    mutt_make_misc_reply_headers (env, Context, curhdr, curenv);
6601  
6602    if (parent)
6603 @@ -811,6 +823,13 @@ void mutt_attach_reply (FILE * fp, HEADE
6604    char prefix[SHORT_STRING];
6605    int rc;
6606    
6607 +#ifdef USE_NNTP
6608 +  if (flags & SENDNEWS)
6609 +    set_option (OPTNEWSSEND);
6610 +  else
6611 +    unset_option (OPTNEWSSEND);
6612 +#endif
6613 +
6614    if (check_all_msg (idx, idxlen, cur, 0) == -1)
6615    {
6616      nattach = count_tagged (idx, idxlen);
6617 diff -udprP mutt-1.5.13.orig/rfc1524.c mutt-1.5.13/rfc1524.c
6618 --- mutt-1.5.13.orig/rfc1524.c  2006-05-18 21:44:29.000000000 +0300
6619 +++ mutt-1.5.13/rfc1524.c       2006-08-15 13:04:56.000000000 +0300
6620 @@ -569,13 +569,13 @@ int rfc1524_expand_filename (char *namet
6621   * safe_fopen().
6622   */
6623  
6624 -int mutt_rename_file (char *oldfile, char *newfile)
6625 +int _mutt_rename_file (char *oldfile, char *newfile, int overwrite)
6626  {
6627    FILE *ofp, *nfp;
6628  
6629    if (access (oldfile, F_OK) != 0)
6630      return 1;
6631 -  if (access (newfile, F_OK) == 0)
6632 +  if (!overwrite && access (newfile, F_OK) == 0)
6633      return 2;
6634    if ((ofp = fopen (oldfile,"r")) == NULL)
6635      return 3;
6636 @@ -590,3 +590,8 @@ int mutt_rename_file (char *oldfile, cha
6637    mutt_unlink (oldfile);
6638    return 0;
6639  }
6640 +
6641 +int mutt_rename_file (char *oldfile, char *newfile)
6642 +{
6643 +  return _mutt_rename_file (oldfile, newfile, 0);
6644 +}
6645 diff -udprP mutt-1.5.13.orig/rfc1524.h mutt-1.5.13/rfc1524.h
6646 --- mutt-1.5.13.orig/rfc1524.h  2005-09-18 11:22:22.000000000 +0300
6647 +++ mutt-1.5.13/rfc1524.h       2006-08-15 13:04:56.000000000 +0300
6648 @@ -40,5 +40,6 @@ int rfc1524_expand_command (BODY *, char
6649  int rfc1524_expand_filename (char *, char *, char *, size_t);
6650  int rfc1524_mailcap_lookup (BODY *, char *, rfc1524_entry *, int);
6651  int mutt_rename_file (char *, char *);
6652 +int _mutt_rename_file (char *, char *, int);
6653  
6654  #endif /* _RFC1524_H */
6655 diff -udprP mutt-1.5.13.orig/send.c mutt-1.5.13/send.c
6656 --- mutt-1.5.13.orig/send.c     2006-03-03 12:12:34.000000000 +0200
6657 +++ mutt-1.5.13/send.c  2006-08-15 13:04:56.000000000 +0300
6658 @@ -44,6 +44,10 @@
6659  #include <sys/types.h>
6660  #include <utime.h>
6661  
6662 +#ifdef USE_NNTP
6663 +#include "nntp.h"
6664 +#endif
6665 +
6666  #ifdef MIXMASTER
6667  #include "remailer.h"
6668  #endif
6669 @@ -213,17 +217,51 @@ static int edit_address (ADDRESS **a, /*
6670    return 0;
6671  }
6672  
6673 -static int edit_envelope (ENVELOPE *en)
6674 +static int edit_envelope (ENVELOPE *en, int flags)
6675  {
6676    char buf[HUGE_STRING];
6677    LIST *uh = UserHeader;
6678  
6679 -  if (edit_address (&en->to, "To: ") == -1 || en->to == NULL)
6680 -    return (-1);
6681 -  if (option (OPTASKCC) && edit_address (&en->cc, "Cc: ") == -1)
6682 -    return (-1);
6683 -  if (option (OPTASKBCC) && edit_address (&en->bcc, "Bcc: ") == -1)
6684 -    return (-1);
6685 +#ifdef USE_NNTP
6686 +  if (option (OPTNEWSSEND))
6687 +  {
6688 +    if (en->newsgroups)
6689 +      strfcpy (buf, en->newsgroups, sizeof (buf));
6690 +    else
6691 +      buf[0] = 0;
6692 +    if (mutt_get_field ("Newsgroups: ", buf, sizeof (buf), 0) != 0)
6693 +      return (-1);
6694 +    FREE (&en->newsgroups);
6695 +    en->newsgroups = safe_strdup (buf);
6696 +
6697 +    if (en->followup_to)
6698 +      strfcpy (buf, en->followup_to, sizeof (buf));
6699 +    else
6700 +      buf[0] = 0;
6701 +    if (option (OPTASKFOLLOWUP) && mutt_get_field ("Followup-To: ", buf, sizeof (buf), 0) != 0)
6702 +      return (-1);
6703 +    FREE (&en->followup_to);
6704 +    en->followup_to = safe_strdup (buf);
6705 +
6706 +    if (en->x_comment_to)
6707 +      strfcpy (buf, en->x_comment_to, sizeof (buf));
6708 +    else
6709 +      buf[0] = 0;
6710 +    if (option (OPTXCOMMENTTO) && option (OPTASKXCOMMENTTO) && mutt_get_field ("X-Comment-To: ", buf, sizeof (buf), 0) != 0)
6711 +      return (-1);
6712 +    FREE (&en->x_comment_to);
6713 +    en->x_comment_to = safe_strdup (buf);
6714 +  }
6715 +  else
6716 +#endif
6717 +  {
6718 +    if (edit_address (&en->to, "To: ") == -1 || en->to == NULL)
6719 +      return (-1);
6720 +    if (option (OPTASKCC) && edit_address (&en->cc, "Cc: ") == -1)
6721 +      return (-1);
6722 +    if (option (OPTASKBCC) && edit_address (&en->bcc, "Bcc: ") == -1)
6723 +      return (-1);
6724 +  }
6725  
6726    if (en->subject)
6727    {
6728 @@ -259,6 +297,14 @@ static int edit_envelope (ENVELOPE *en)
6729    return 0;
6730  }
6731  
6732 +#ifdef USE_NNTP
6733 +char *nntp_get_header (const char *s)
6734 +{
6735 +  SKIPWS (s);
6736 +  return safe_strdup (s);
6737 +}
6738 +#endif
6739 +
6740  static void process_user_recips (ENVELOPE *env)
6741  {
6742    LIST *uh = UserHeader;
6743 @@ -271,6 +317,14 @@ static void process_user_recips (ENVELOP
6744        env->cc = rfc822_parse_adrlist (env->cc, uh->data + 3);
6745      else if (ascii_strncasecmp ("bcc:", uh->data, 4) == 0)
6746        env->bcc = rfc822_parse_adrlist (env->bcc, uh->data + 4);
6747 +#ifdef USE_NNTP
6748 +    else if (ascii_strncasecmp ("newsgroups:", uh->data, 11) == 0)
6749 +      env->newsgroups = nntp_get_header (uh->data + 11);
6750 +    else if (ascii_strncasecmp ("followup-to:", uh->data, 12) == 0)
6751 +      env->followup_to = nntp_get_header (uh->data + 12);
6752 +    else if (ascii_strncasecmp ("x-comment-to:", uh->data, 13) == 0)
6753 +      env->x_comment_to = nntp_get_header (uh->data + 13);
6754 +#endif
6755    }
6756  }
6757  
6758 @@ -301,6 +355,12 @@ static void process_user_header (ENVELOP
6759      else if (ascii_strncasecmp ("to:", uh->data, 3) != 0 &&
6760              ascii_strncasecmp ("cc:", uh->data, 3) != 0 &&
6761              ascii_strncasecmp ("bcc:", uh->data, 4) != 0 &&
6762 +#ifdef USE_NNTP
6763 +            ascii_strncasecmp ("newsgroups:", uh->data, 11) != 0 &&
6764 +            ascii_strncasecmp ("followup-to:", uh->data, 12) != 0 &&
6765 +            ascii_strncasecmp ("x-comment-to:", uh->data, 13) != 0 &&
6766 +#endif
6767 +            ascii_strncasecmp ("supersedes:", uh->data, 11) != 0 &&
6768              ascii_strncasecmp ("subject:", uh->data, 8) != 0)
6769      {
6770        if (last)
6771 @@ -646,6 +706,10 @@ void mutt_add_to_reference_headers (ENVE
6772    if (pp) *pp = p;
6773    if (qq) *qq = q;
6774    
6775 +#ifdef USE_NNTP
6776 +  if (option (OPTNEWSSEND) && option (OPTXCOMMENTTO) && curenv->from)
6777 +    env->x_comment_to = safe_strdup (mutt_get_name (curenv->from));
6778 +#endif
6779  }
6780  
6781  static void 
6782 @@ -702,6 +766,16 @@ envelope_defaults (ENVELOPE *env, CONTEX
6783  
6784    if (flags & SENDREPLY)
6785    {
6786 +#ifdef USE_NNTP
6787 +    if ((flags & SENDNEWS))
6788 +    {
6789 +      /* in case followup set Newsgroups: with Followup-To: if it present */
6790 +      if (!env->newsgroups && curenv &&
6791 +         mutt_strcasecmp (curenv->followup_to, "poster"))
6792 +       env->newsgroups = safe_strdup (curenv->followup_to);
6793 +    }
6794 +    else
6795 +#endif
6796      if (tag)
6797      {
6798        HEADER *h;
6799 @@ -848,7 +922,18 @@ void mutt_set_followup_to (ENVELOPE *e)
6800     * it hasn't already been set
6801     */
6802  
6803 -  if (option (OPTFOLLOWUPTO) && !e->mail_followup_to)
6804 +  if (!option (OPTFOLLOWUPTO))
6805 +    return;
6806 +#ifdef USE_NNTP
6807 +  if (option (OPTNEWSSEND))
6808 +  {
6809 +    if (!e->followup_to && e->newsgroups && (strrchr (e->newsgroups, ',')))
6810 +      e->followup_to = safe_strdup (e->newsgroups);
6811 +    return;
6812 +  }
6813 +#endif
6814 +
6815 +  if (!e->mail_followup_to)
6816    {
6817      if (mutt_is_list_cc (0, e->to, e->cc))
6818      {
6819 @@ -1081,6 +1166,13 @@ ci_send_message (int flags,              /* send mod
6820  
6821    int rv = -1;
6822    
6823 +#ifdef USE_NNTP
6824 +  if (flags & SENDNEWS)
6825 +    set_option (OPTNEWSSEND);
6826 +  else
6827 +    unset_option (OPTNEWSSEND);
6828 +#endif
6829 +
6830    if (!flags && !msg && quadoption (OPT_RECALL) != M_NO &&
6831        mutt_num_postponed (1))
6832    {
6833 @@ -1111,6 +1203,22 @@ ci_send_message (int flags,              /* send mod
6834      {
6835        if ((flags = mutt_get_postponed (ctx, msg, &cur, fcc, sizeof (fcc))) < 0)
6836         goto cleanup;
6837 +#ifdef USE_NNTP
6838 +      /*
6839 +       * If postponed message is a news article, it have
6840 +       * a "Newsgroups:" header line, then set appropriate flag.
6841 +       */
6842 +      if (msg->env->newsgroups)
6843 +      {
6844 +       flags |= SENDNEWS;
6845 +       set_option (OPTNEWSSEND);
6846 +      }
6847 +      else
6848 +      {
6849 +       flags &= ~SENDNEWS;
6850 +       unset_option (OPTNEWSSEND);
6851 +      }
6852 +#endif
6853      }
6854  
6855      if (flags & (SENDPOSTPONED|SENDRESEND))
6856 @@ -1215,11 +1323,16 @@ ci_send_message (int flags,             /* send mod
6857      /* Expand aliases and remove duplicates/crossrefs */
6858      mutt_fix_reply_recipients (msg->env);
6859  
6860 +#ifdef USE_NNTP
6861 +    if ((flags & SENDNEWS) && ctx && ctx->magic == M_NNTP && !msg->env->newsgroups)
6862 +      msg->env->newsgroups = safe_strdup (((NNTP_DATA *)ctx->data)->group);
6863 +#endif
6864 +
6865      if (! (flags & SENDMAILX) &&
6866         ! (option (OPTAUTOEDIT) && option (OPTEDITHDRS)) &&
6867         ! ((flags & SENDREPLY) && option (OPTFASTREPLY)))
6868      {
6869 -      if (edit_envelope (msg->env) == -1)
6870 +      if (edit_envelope (msg->env, flags) == -1)
6871         goto cleanup;
6872      }
6873  
6874 @@ -1470,6 +1583,11 @@ main_loop:
6875      if (i == -1)
6876      {
6877        /* abort */
6878 +#ifdef USE_NNTP
6879 +      if (flags & SENDNEWS)
6880 +       mutt_message _("Article not posted.");
6881 +      else
6882 +#endif
6883        mutt_message _("Mail not sent.");
6884        goto cleanup;
6885      }
6886 @@ -1502,6 +1620,9 @@ main_loop:
6887      }
6888    }
6889  
6890 +#ifdef USE_NNTP
6891 +  if (!(flags & SENDNEWS))
6892 +#endif
6893    if (!msg->env->to && !msg->env->cc && !msg->env->bcc)
6894    {
6895      if (! (flags & SENDBATCH))
6896 @@ -1534,6 +1655,19 @@ main_loop:
6897        mutt_error _("No subject specified.");
6898      goto main_loop;
6899    }
6900 +#ifdef USE_NNTP
6901 +  if ((flags & SENDNEWS) && !msg->env->subject)
6902 +  {
6903 +    mutt_error _("No subject specified.");
6904 +    goto main_loop;
6905 +  }
6906 +
6907 +  if ((flags & SENDNEWS) && !msg->env->newsgroups)
6908 +  {
6909 +    mutt_error _("No newsgroup specified.");
6910 +    goto main_loop;
6911 +  }
6912 +#endif
6913  
6914    if (msg->content->next)
6915      msg->content = mutt_make_multipart (msg->content);
6916 @@ -1739,7 +1873,12 @@ full_fcc:
6917      }
6918    }
6919    else if (!option (OPTNOCURSES) && ! (flags & SENDMAILX))
6920 -    mutt_message (i == 0 ? _("Mail sent.") : _("Sending in background."));
6921 +    mutt_message (i != 0 ? _("Sending in background.") :
6922 +#ifdef USE_NNTP
6923 +                 (flags & SENDNEWS) ? _("Article posted.") : _("Mail sent."));
6924 +#else
6925 +                 _("Mail sent."));
6926 +#endif
6927  
6928    if (WithCrypto && (msg->security & ENCRYPT))
6929      FREE (&pgpkeylist);
6930 diff -udprP mutt-1.5.13.orig/sendlib.c mutt-1.5.13/sendlib.c
6931 --- mutt-1.5.13.orig/sendlib.c  2006-07-18 21:16:24.000000000 +0300
6932 +++ mutt-1.5.13/sendlib.c       2006-08-15 13:04:56.000000000 +0300
6933 @@ -45,6 +45,10 @@
6934  #include <sys/wait.h>
6935  #include <fcntl.h>
6936  
6937 +#ifdef USE_NNTP
6938 +#include <nntp.h>
6939 +#endif
6940 +
6941  #ifdef HAVE_SYSEXITS_H
6942  #include <sysexits.h>
6943  #else /* Make sure EX_OK is defined <philiph@pobox.com> */
6944 @@ -1496,7 +1500,7 @@ void mutt_write_address_list (ADDRESS *a
6945  /* need to write the list in reverse because they are stored in reverse order
6946   * when parsed to speed up threading
6947   */
6948 -static void write_references (LIST *r, FILE *f)
6949 +void mutt_write_references (LIST *r, FILE *f)
6950  {
6951    LIST **ref = NULL;
6952    int refcnt = 0, refmax = 0;
6953 @@ -1541,6 +1545,9 @@ int mutt_write_rfc822_header (FILE *fp, 
6954    LIST *tmp = env->userhdrs;
6955    int has_agent = 0; /* user defined user-agent header field exists */
6956    
6957 +#ifdef USE_NNTP
6958 +  if (!option (OPTNEWSSEND))
6959 +#endif
6960    if (mode == 0 && !privacy)
6961      fputs (mutt_make_date (buffer, sizeof(buffer)), fp);
6962  
6963 @@ -1560,6 +1567,9 @@ int mutt_write_rfc822_header (FILE *fp, 
6964      mutt_write_address_list (env->to, fp, 4, 0);
6965    }
6966    else if (mode > 0)
6967 +#ifdef USE_NNTP
6968 +  if (!option (OPTNEWSSEND))
6969 +#endif
6970      fputs ("To: \n", fp);
6971  
6972    if (env->cc)
6973 @@ -1568,6 +1578,9 @@ int mutt_write_rfc822_header (FILE *fp, 
6974      mutt_write_address_list (env->cc, fp, 4, 0);
6975    }
6976    else if (mode > 0)
6977 +#ifdef USE_NNTP
6978 +  if (!option (OPTNEWSSEND))
6979 +#endif
6980      fputs ("Cc: \n", fp);
6981  
6982    if (env->bcc)
6983 @@ -1579,8 +1592,28 @@ int mutt_write_rfc822_header (FILE *fp, 
6984      }
6985    }
6986    else if (mode > 0)
6987 +#ifdef USE_NNTP
6988 +  if (!option (OPTNEWSSEND))
6989 +#endif
6990      fputs ("Bcc: \n", fp);
6991  
6992 +#ifdef USE_NNTP
6993 +  if (env->newsgroups)
6994 +    fprintf (fp, "Newsgroups: %s\n", env->newsgroups);
6995 +  else if (mode == 1 && option (OPTNEWSSEND))
6996 +    fputs ("Newsgroups: \n", fp);
6997 +
6998 +  if (env->followup_to)
6999 +    fprintf (fp, "Followup-To: %s\n", env->followup_to);
7000 +  else if (mode == 1 && option (OPTNEWSSEND))
7001 +    fputs ("Followup-To: \n", fp);
7002 +
7003 +  if (env->x_comment_to)
7004 +    fprintf (fp, "X-Comment-To: %s\n", env->x_comment_to);
7005 +  else if (mode == 1 && option (OPTNEWSSEND) && option (OPTXCOMMENTTO))
7006 +    fputs ("X-Comment-To: \n", fp);
7007 +#endif
7008 +
7009    if (env->subject)
7010      fprintf (fp, "Subject: %s\n", env->subject);
7011    else if (mode == 1)
7012 @@ -1599,6 +1632,9 @@ int mutt_write_rfc822_header (FILE *fp, 
7013      fputs ("Reply-To: \n", fp);
7014  
7015    if (env->mail_followup_to)
7016 +#ifdef USE_NNTP
7017 +  if (!option (OPTNEWSSEND))
7018 +#endif
7019    {
7020      fputs ("Mail-Followup-To: ", fp);
7021      mutt_write_address_list (env->mail_followup_to, fp, 18, 0);
7022 @@ -1609,7 +1645,7 @@ int mutt_write_rfc822_header (FILE *fp, 
7023      if (env->references)
7024      {
7025        fputs ("References:", fp);
7026 -      write_references (env->references, fp);
7027 +      mutt_write_references (env->references, fp);
7028        fputc('\n', fp);
7029      }
7030  
7031 @@ -1621,7 +1657,7 @@ int mutt_write_rfc822_header (FILE *fp, 
7032    if (env->in_reply_to)
7033    {
7034      fputs ("In-Reply-To:", fp);
7035 -    write_references (env->in_reply_to, fp);
7036 +    mutt_write_references (env->in_reply_to, fp);
7037      fputc ('\n', fp);
7038    }
7039    
7040 @@ -1921,11 +1957,30 @@ mutt_invoke_sendmail (ADDRESS *from,    /* 
7041                  const char *msg, /* file containing message */
7042                  int eightbit) /* message contains 8bit chars */
7043  {
7044 -  char *ps = NULL, *path = NULL, *s = safe_strdup (Sendmail), *childout = NULL;
7045 +  char *ps = NULL, *path = NULL, *s = NULL, *childout = NULL;
7046    char **args = NULL;
7047    size_t argslen = 0, argsmax = 0;
7048    int i;
7049  
7050 +#ifdef USE_NNTP
7051 +  if (option (OPTNEWSSEND))
7052 +  {
7053 +    char cmd[LONG_STRING];
7054 +
7055 +    mutt_FormatString (cmd, sizeof (cmd), NONULL (Inews), nntp_format_str, 0, 0);
7056 +    if (!*cmd)
7057 +    {
7058 +      i = nntp_post (msg);
7059 +      unlink (msg);
7060 +      return i;
7061 +    }
7062 +
7063 +    s = safe_strdup (cmd);
7064 +  }
7065 +  else
7066 +#endif
7067 +    s = safe_strdup (Sendmail);
7068 +
7069    ps = s;
7070    i = 0;
7071    while ((ps = strtok (ps, " ")))
7072 @@ -1949,6 +2004,10 @@ mutt_invoke_sendmail (ADDRESS *from,     /* 
7073      i++;
7074    }
7075  
7076 +#ifdef USE_NNTP
7077 +  if (!option (OPTNEWSSEND))
7078 +  {
7079 +#endif
7080    if (eightbit && option (OPTUSE8BITMIME))
7081      args = add_option (args, &argslen, &argsmax, "-B8BITMIME");
7082  
7083 @@ -1980,6 +2039,9 @@ mutt_invoke_sendmail (ADDRESS *from,      /* 
7084    args = add_args (args, &argslen, &argsmax, to);
7085    args = add_args (args, &argslen, &argsmax, cc);
7086    args = add_args (args, &argslen, &argsmax, bcc);
7087 +#ifdef USE_NNTP
7088 +  }
7089 +#endif
7090  
7091    if (argslen == argsmax)
7092      safe_realloc (&args, sizeof (char *) * (++argsmax));
7093 @@ -2112,6 +2174,9 @@ void mutt_prepare_envelope (ENVELOPE *en
7094    rfc2047_encode_adrlist (env->reply_to, "Reply-To");
7095  
7096    if (env->subject)
7097 +#ifdef USE_NNTP
7098 +  if (!option (OPTNEWSSEND) || option (OPTMIMESUBJECT))
7099 +#endif
7100    {
7101      rfc2047_encode_string (&env->subject);
7102    }
7103 @@ -2211,6 +2276,10 @@ int mutt_bounce_message (FILE *fp, HEADE
7104    }
7105    rfc822_write_address (resent_from, sizeof (resent_from), from, 0);
7106  
7107 +#ifdef USE_NNTP
7108 +  unset_option (OPTNEWSSEND);
7109 +#endif
7110 +
7111    ret = _mutt_bounce_message (fp, h, to, resent_from, from);
7112  
7113    rfc822_free_address (&from);
7114 diff -udprP mutt-1.5.13.orig/sort.c mutt-1.5.13/sort.c
7115 --- mutt-1.5.13.orig/sort.c     2005-09-18 11:22:22.000000000 +0300
7116 +++ mutt-1.5.13/sort.c  2006-08-15 13:04:56.000000000 +0300
7117 @@ -149,6 +149,15 @@ int compare_order (const void *a, const 
7118    HEADER **ha = (HEADER **) a;
7119    HEADER **hb = (HEADER **) b;
7120  
7121 +#ifdef USE_NNTP
7122 +  if ((*ha)->article_num && (*hb)->article_num)
7123 +  {
7124 +    int result = (*ha)->article_num - (*hb)->article_num;
7125 +    AUXSORT(result,a,b);
7126 +    return (SORTCODE (result));
7127 +  }
7128 +  else
7129 +#endif
7130    /* no need to auxsort because you will never have equality here */
7131    return (SORTCODE ((*ha)->index - (*hb)->index));
7132  }
7133 diff -udprP mutt-1.5.13.orig/url.c mutt-1.5.13/url.c
7134 --- mutt-1.5.13.orig/url.c      2005-09-18 11:22:22.000000000 +0300
7135 +++ mutt-1.5.13/url.c   2006-08-15 13:04:56.000000000 +0300
7136 @@ -39,6 +39,8 @@ static struct mapping_t UrlMap[] =
7137    { "imaps",   U_IMAPS },
7138    { "pop",     U_POP  },
7139    { "pops",    U_POPS  },
7140 +  { "nntp",    U_NNTP },
7141 +  { "nntps",   U_NNTPS },
7142    { "mailto",  U_MAILTO },
7143    { NULL,      U_UNKNOWN}
7144  };
7145 diff -udprP mutt-1.5.13.orig/url.h mutt-1.5.13/url.h
7146 --- mutt-1.5.13.orig/url.h      2004-07-20 01:00:05.000000000 +0300
7147 +++ mutt-1.5.13/url.h   2006-08-15 13:04:56.000000000 +0300
7148 @@ -8,6 +8,8 @@ typedef enum url_scheme
7149    U_POPS,
7150    U_IMAP,
7151    U_IMAPS,
7152 +  U_NNTP,
7153 +  U_NNTPS,
7154    U_MAILTO,
7155    U_UNKNOWN
7156  }
7157 diff -udprP mutt-1.5.13.orig/Makefile.am mutt-1.5.13/Makefile.am
7158 --- mutt-1.5.13.orig/Makefile.am        2006-08-14 16:47:23.000000000 +0300
7159 +++ mutt-1.5.13/Makefile.am     2006-08-15 13:04:56.000000000 +0300
7160 @@ -63,6 +63,7 @@ EXTRA_mutt_SOURCES = account.c md5c.c mu
7161         browser.h mbyte.h remailer.h url.h \
7162         crypt-mod-pgp-classic.c crypt-mod-smime-classic.c \
7163         pgppacket.c mutt_idna.h hcache.h hcache.c bcache.c bcache.h mutt_ssl_gnutls.c \
7164 +       nntp.c newsrc.c \
7165         crypt-gpgme.c crypt-mod-pgp-gpgme.c crypt-mod-smime-gpgme.c
7166  
7167  EXTRA_DIST = COPYRIGHT GPL OPS OPS.PGP OPS.CRYPT OPS.SMIME TODO UPDATING \
7168 @@ -73,6 +74,7 @@ EXTRA_DIST = COPYRIGHT GPL OPS OPS.PGP O
7169         mutt_regex.h mutt_sasl.h mutt_socket.h mutt_ssl.h mutt_tunnel.h \
7170         mx.h pager.h pgp.h pop.h protos.h rfc1524.h rfc2047.h \
7171         rfc2231.h rfc822.h sha1.h sort.h mime.types VERSION prepare \
7172 +       nntp.h ChangeLog.nntp \
7173         _regex.h OPS.MIX README.SECURITY remailer.c remailer.h browser.h \
7174         mbyte.h lib.h extlib.c pgpewrap.c smime_keys.pl pgplib.h Muttrc.head Muttrc \
7175         makedoc.c stamp-doc-rc README.SSL smime.h\
7176 diff -udprP mutt-1.5.13.orig/Makefile.in mutt-1.5.13/Makefile.in
7177 --- mutt-1.5.13.orig/Makefile.in        2006-08-14 17:09:29.000000000 +0300
7178 +++ mutt-1.5.13/Makefile.in     2006-08-15 13:04:56.000000000 +0300
7179 @@ -325,6 +325,7 @@ EXTRA_mutt_SOURCES = account.c md5c.c mu
7180         browser.h mbyte.h remailer.h url.h \
7181         crypt-mod-pgp-classic.c crypt-mod-smime-classic.c \
7182         pgppacket.c mutt_idna.h hcache.h hcache.c bcache.c bcache.h mutt_ssl_gnutls.c \
7183 +       nntp.c newsrc.c \
7184         crypt-gpgme.c crypt-mod-pgp-gpgme.c crypt-mod-smime-gpgme.c
7185  
7186  EXTRA_DIST = COPYRIGHT GPL OPS OPS.PGP OPS.CRYPT OPS.SMIME TODO UPDATING \
7187 @@ -335,6 +336,7 @@ EXTRA_DIST = COPYRIGHT GPL OPS OPS.PGP O
7188         mutt_regex.h mutt_sasl.h mutt_socket.h mutt_ssl.h mutt_tunnel.h \
7189         mx.h pager.h pgp.h pop.h protos.h rfc1524.h rfc2047.h \
7190         rfc2231.h rfc822.h sha1.h sort.h mime.types VERSION prepare \
7191 +       nntp.h ChangeLog.nntp \
7192         _regex.h OPS.MIX README.SECURITY remailer.c remailer.h browser.h \
7193         mbyte.h lib.h extlib.c pgpewrap.c smime_keys.pl pgplib.h Muttrc.head Muttrc \
7194         makedoc.c stamp-doc-rc README.SSL smime.h\
7195 @@ -550,6 +552,8 @@ distclean-compile:
7196  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mutt_tunnel.Po@am__quote@
7197  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/muttlib.Po@am__quote@
7198  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mx.Po@am__quote@
7199 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/newsrc.Po@am__quote@
7200 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nntp.Po@am__quote@
7201  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pager.Po@am__quote@
7202  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/parse.Po@am__quote@
7203  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/patchlist.Po@am__quote@
7204 diff -udprP mutt-1.5.13.orig/Muttrc mutt-1.5.13/Muttrc
7205 --- mutt-1.5.13.orig/Muttrc     2006-08-14 17:09:47.000000000 +0300
7206 +++ mutt-1.5.13/Muttrc  2006-08-15 13:04:56.000000000 +0300
7207 @@ -220,6 +220,28 @@ attachments   -I message/external-body
7208  # editing the body of an outgoing message.
7209  # 
7210  # 
7211 +# set ask_follow_up=no
7212 +#
7213 +# Name: ask_follow_up
7214 +# Type: boolean
7215 +# Default: no
7216 +# 
7217 +# 
7218 +# If set, Mutt will prompt you for follow-up groups before editing
7219 +# the body of an outgoing message.
7220 +# 
7221 +# 
7222 +# set ask_x_comment_to=no
7223 +#
7224 +# Name: ask_x_comment_to
7225 +# Type: boolean
7226 +# Default: no
7227 +# 
7228 +# 
7229 +# If set, Mutt will prompt you for x-comment-to field before editing
7230 +# the body of an outgoing message.
7231 +# 
7232 +# 
7233  # set attach_format="%u%D%I %t%4n %T%.40d%> [%.7m/%.10M, %.6e%?C?, %C?, %s] "
7234  #
7235  # Name: attach_format
7236 @@ -376,6 +398,17 @@ attachments   -I message/external-body
7237  # visual terminals don't permit making the cursor invisible.
7238  # 
7239  # 
7240 +# set catchup_newsgroup=ask-yes
7241 +#
7242 +# Name: catchup_newsgroup
7243 +# Type: quadoption
7244 +# Default: ask-yes
7245 +# 
7246 +# 
7247 +# If this variable is set, Mutt will mark all articles in newsgroup
7248 +# as read when you quit the newsgroup (catchup newsgroup).
7249 +# 
7250 +# 
7251  # set charset=""
7252  #
7253  # Name: charset
7254 @@ -862,6 +895,19 @@ attachments   -I message/external-body
7255  # of the same email for you.
7256  # 
7257  # 
7258 +# set followup_to_poster=ask-yes
7259 +#
7260 +# Name: followup_to_poster
7261 +# Type: quadoption
7262 +# Default: ask-yes
7263 +# 
7264 +# 
7265 +# If this variable is set and the keyword "poster" is present in
7266 +# Followup-To header, follow-up to newsgroup function is not
7267 +# permitted.  The message will be mailed to the submitter of the
7268 +# message via mail.
7269 +# 
7270 +# 
7271  # set force_name=no
7272  #
7273  # Name: force_name
7274 @@ -959,6 +1005,28 @@ attachments   -I message/external-body
7275  # "Franklin" to "Franklin, Steve".
7276  # 
7277  # 
7278 +# set group_index_format="%4C %M%N %5s  %-45.45f %d"
7279 +#
7280 +# Name: group_index_format
7281 +# Type: string
7282 +# Default: "%4C %M%N %5s  %-45.45f %d"
7283 +# 
7284 +# 
7285 +# This variable allows you to customize the newsgroup browser display to
7286 +# your personal taste.  This string is similar to ``index_format'', but
7287 +# has its own set of printf()-like sequences:
7288 +# 
7289 +# %C      current newsgroup number
7290 +# %d      description of newsgroup (becomes from server)
7291 +# %f      newsgroup name
7292 +# %M      - if newsgroup not allowed for direct post (moderated for example)
7293 +# %N      N if newsgroup is new, u if unsubscribed, blank otherwise
7294 +# %n      number of new articles in newsgroup
7295 +# %s      number of unread articles in newsgroup
7296 +# %>X     right justify the rest of the string and pad with character "X"
7297 +# %|X     pad to the end of the line with character "X"
7298 +# 
7299 +# 
7300  # set hdrs=yes
7301  #
7302  # Name: hdrs
7303 @@ -1394,6 +1462,7 @@ attachments   -I message/external-body
7304  # %E      number of messages in current thread
7305  # %f      entire From: line (address + real name)
7306  # %F      author name, or recipient name if the message is from you
7307 +# %g      newsgroup name (if compiled with nntp support)
7308  # %H      spam attribute(s) of this message
7309  # %i      message-id of the current message
7310  # %l      number of lines in the message (does not work with maildir,
7311 @@ -1413,6 +1482,7 @@ attachments   -I message/external-body
7312  # %T      the appropriate character from the $to_chars string
7313  # %u      user (login) name of the author
7314  # %v      first name of the author, or the recipient if the message is from you
7315 +# %W      name of organization of author (`organization:' field)
7316  # %X      number of attachments
7317  #         (please see the ``attachments'' section for possible speed effects)
7318  # %y      `x-label:' field, if present
7319 @@ -1438,6 +1508,22 @@ attachments   -I message/external-body
7320  # See also: ``$to_chars''.
7321  # 
7322  # 
7323 +# set inews=""
7324 +#
7325 +# Name: inews
7326 +# Type: path
7327 +# Default: ""
7328 +# 
7329 +# 
7330 +# If set, specifies the program and arguments used to deliver news posted
7331 +# by Mutt.  Otherwise, mutt posts article using current connection to
7332 +# news server.  The following printf-style sequence is understood:
7333 +# 
7334 +# %s      newsserver name
7335 +# 
7336 +# Example: set inews="/usr/local/bin/inews -hS"
7337 +# 
7338 +# 
7339  # set ispell="/usr/bin/ispell"
7340  #
7341  # Name: ispell
7342 @@ -1781,6 +1867,18 @@ attachments   -I message/external-body
7343  # be attached to the newly composed message if this option is set.
7344  # 
7345  # 
7346 +# set mime_subject=yes
7347 +#
7348 +# Name: mime_subject
7349 +# Type: boolean
7350 +# Default: yes
7351 +# 
7352 +# 
7353 +# If unset, 8-bit ``subject:'' line in article header will not be
7354 +# encoded according to RFC2047 to base64.  This is useful when message
7355 +# is Usenet article, because MIME for news is nonstandard feature.
7356 +# 
7357 +# 
7358  # set mix_entry_format="%4n %c %-16s %a"
7359  #
7360  # Name: mix_entry_format
7361 @@ -1873,6 +1971,118 @@ attachments   -I message/external-body
7362  # See also ``$read_inc'' and ``$write_inc''.
7363  # 
7364  # 
7365 +# set news_cache_dir="~/.mutt"
7366 +#
7367 +# Name: news_cache_dir
7368 +# Type: path
7369 +# Default: "~/.mutt"
7370 +# 
7371 +# 
7372 +# This variable pointing to directory where Mutt will save cached news
7373 +# articles headers in. If unset, headers will not be saved at all
7374 +# and will be reloaded each time when you enter to newsgroup.
7375 +# 
7376 +# 
7377 +# set news_server=""
7378 +#
7379 +# Name: news_server
7380 +# Type: string
7381 +# Default: ""
7382 +# 
7383 +# 
7384 +# This variable specifies domain name or address of NNTP server. It
7385 +# defaults to the newsserver specified in the environment variable
7386 +# $NNTPSERVER or contained in the file /etc/nntpserver.  You can also
7387 +# specify username and an alternative port for each newsserver, ie:
7388 +# 
7389 +# [nntp[s]://][username[:password]@]newsserver[:port]
7390 +# 
7391 +# 
7392 +# set newsrc="~/.newsrc"
7393 +#
7394 +# Name: newsrc
7395 +# Type: path
7396 +# Default: "~/.newsrc"
7397 +# 
7398 +# 
7399 +# The file, containing info about subscribed newsgroups - names and
7400 +# indexes of read articles.  The following printf-style sequence
7401 +# is understood:
7402 +# 
7403 +# %s      newsserver name
7404 +# 
7405 +# 
7406 +# set nntp_context=1000
7407 +#
7408 +# Name: nntp_context
7409 +# Type: number
7410 +# Default: 1000
7411 +# 
7412 +# 
7413 +# This variable defines number of articles which will be in index when
7414 +# newsgroup entered.  If active newsgroup have more articles than this
7415 +# number, oldest articles will be ignored.  Also controls how many
7416 +# articles headers will be saved in cache when you quit newsgroup.
7417 +# 
7418 +# 
7419 +# set nntp_load_description=yes
7420 +#
7421 +# Name: nntp_load_description
7422 +# Type: boolean
7423 +# Default: yes
7424 +# 
7425 +# 
7426 +# This variable controls whether or not descriptions for each newsgroup
7427 +# must be loaded when newsgroup is added to list (first time list
7428 +# loading or new newsgroup adding).
7429 +# 
7430 +# 
7431 +# set nntp_user=""
7432 +#
7433 +# Name: nntp_user
7434 +# Type: string
7435 +# Default: ""
7436 +# 
7437 +# 
7438 +# Your login name on the NNTP server.  If unset and NNTP server requires
7439 +# authentification, Mutt will prompt you for your account name when you
7440 +# connect to newsserver.
7441 +# 
7442 +# 
7443 +# set nntp_pass=""
7444 +#
7445 +# Name: nntp_pass
7446 +# Type: string
7447 +# Default: ""
7448 +# 
7449 +# 
7450 +# Your password for NNTP account.
7451 +# 
7452 +# 
7453 +# set nntp_poll=60
7454 +#
7455 +# Name: nntp_poll
7456 +# Type: number
7457 +# Default: 60
7458 +# 
7459 +# 
7460 +# The time in seconds until any operations on newsgroup except post new
7461 +# article will cause recheck for new news.  If set to 0, Mutt will
7462 +# recheck newsgroup on each operation in index (stepping, read article,
7463 +# etc.).
7464 +# 
7465 +# 
7466 +# set nntp_reconnect=ask-yes
7467 +#
7468 +# Name: nntp_reconnect
7469 +# Type: quadoption
7470 +# Default: ask-yes
7471 +# 
7472 +# 
7473 +# Controls whether or not Mutt will try to reconnect to newsserver when
7474 +# connection lost.
7475 +# 
7476 +# 
7477  # set pager="builtin"
7478  #
7479  # Name: pager
7480 @@ -3076,6 +3286,19 @@ attachments   -I message/external-body
7481  # string after the inclusion of a message which is being replied to.
7482  # 
7483  # 
7484 +# set post_moderated=ask-yes
7485 +#
7486 +# Name: post_moderated
7487 +# Type: quadoption
7488 +# Default: ask-yes
7489 +# 
7490 +# 
7491 +# If set to yes, Mutt will post article to newsgroup that have
7492 +# not permissions to posting (e.g. moderated).  Note: if newsserver
7493 +# does not support posting to that newsgroup or totally read-only, that
7494 +# posting will not have an effect.
7495 +# 
7496 +# 
7497  # set postpone=ask-yes
7498  #
7499  # Name: postpone
7500 @@ -3588,6 +3811,41 @@ attachments   -I message/external-body
7501  # shell from /etc/passwd is used.
7502  # 
7503  # 
7504 +# set save_unsubscribed=no
7505 +#
7506 +# Name: save_unsubscribed
7507 +# Type: boolean
7508 +# Default: no
7509 +# 
7510 +# 
7511 +# When set, info about unsubscribed newsgroups will be saved into
7512 +# ``newsrc'' file and into cache.
7513 +# 
7514 +# 
7515 +# set show_new_news=yes
7516 +#
7517 +# Name: show_new_news
7518 +# Type: boolean
7519 +# Default: yes
7520 +# 
7521 +# 
7522 +# If set, newsserver will be asked for new newsgroups on entering
7523 +# the browser.  Otherwise, it will be done only once for a newsserver.
7524 +# Also controls whether or not number of new articles of subscribed
7525 +# newsgroups will be then checked.
7526 +# 
7527 +# 
7528 +# set show_only_unread=no
7529 +#
7530 +# Name: show_only_unread
7531 +# Type: boolean
7532 +# Default: no
7533 +# 
7534 +# 
7535 +# If set, only subscribed newsgroups that contain unread articles
7536 +# will be displayed in browser.
7537 +# 
7538 +# 
7539  # set sig_dashes=yes
7540  #
7541  # Name: sig_dashes
7542 @@ -4236,3 +4494,14 @@ attachments   -I message/external-body
7543  # messages to be sent.  Exim users may wish to unset this.
7544  # 
7545  # 
7546 +# set x_comment_to=no
7547 +#
7548 +# Name: x_comment_to
7549 +# Type: boolean
7550 +# Default: no
7551 +# 
7552 +# 
7553 +# If set, Mutt will add ``X-Comment-To:'' field (that contains full
7554 +# name of original article author) to article that followuped to newsgroup.
7555 +# 
7556 +# 
7557 diff -udprP mutt-1.5.13.orig/configure mutt-1.5.13/configure
7558 --- mutt-1.5.13.orig/configure  2006-08-14 17:09:30.000000000 +0300
7559 +++ mutt-1.5.13/configure       2006-08-15 13:04:56.000000000 +0300
7560 @@ -859,6 +859,7 @@ Optional Features:
7561                            Force use of an external dotlock program
7562    --enable-pop            Enable POP3 support
7563    --enable-imap           Enable IMAP support
7564 +  --enable-nntp           Enable NNTP support
7565    --enable-debug          Enable debugging support
7566    --enable-flock          Use flock() to lock files
7567    --disable-fcntl         Do NOT use fcntl() to lock files
7568 @@ -11740,6 +11741,20 @@ fi
7569  fi
7570  done
7571  
7572 +# Check whether --enable-nntp or --disable-nntp was given.
7573 +if test "${enable_nntp+set}" = set; then
7574 +  enableval="$enable_nntp"
7575 +       if test x$enableval = xyes ; then
7576 +               cat >>confdefs.h <<\_ACEOF
7577 +#define USE_NNTP 1
7578 +_ACEOF
7579 +
7580 +               MUTT_LIB_OBJECTS="$MUTT_LIB_OBJECTS nntp.o newsrc.o"
7581 +               need_socket="yes"
7582 +       fi
7583 +
7584 +fi;
7585 +
7586  
7587  
7588  for ac_func in strftime
This page took 0.921721 seconds and 4 git commands to generate.