Article View: news.software.nntp
Article #67754Re: [mutt-nntp/NNTPPost] Replacement with authentification (long)
From: Andre Berger
Date: Sat, 24 Jan 2004 18:45
Date: Sat, 24 Jan 2004 18:45
307 lines
7892 bytes
7892 bytes
* Jeffrey M. Vinocur <jeff@litech.org>, 2004-01-24 19:15 +0100:
> In article <20040124085405.GA1794@hvk.local>,
> Andre Berger <andre.berger@web.de> wrote:
> >
> >I hope this is the right NG, if not please point me to it :)
>
> I think news.software.readers is better, crossposting there.
Thanks!
> >I'm running mutt-nntp 1.4.1 (Orjan Stromberg's patch to the mutt
> >email client). It comes with a very simple program, NNTPPost, which
> >does what you expect but doesn't support authenification.
> >Subsequently, I can't use mutt-nntp off-line.
> >
> >andre@hvk:~$ NNTPPost
> >usage: NNTPPost <spool_file> <nntp_host[:nntp_port]>
> >
> >Unfortunately, I need to authentify against my mail server. Could you
^^^^
news (of course)
> >think of any drop-in replacement for NNTPPost?
>
> I think any decent inews (maybe the one that comes with trn)
> should suffice, although you might have to wrap a little script
> around it to get the syntax to match exactly if that's necessary
> (I don't use mutt, so I don't know).
Isn't inews a server, and very hard to set up? Excuse my ignorance
please, I don't really want to run a news server if I can avoid it.
Or wait, maybe noffle if I can compile it (Mac OS X 10.3 Panther), I
used it on Debian/i386 and was very happy with it. Has anyone here
succeeded compiling noffle for OS X/fink?
> Alternatively, it probably wouldn't be too hard to patch
> NNTPPost.
Want to give it a try? That would be very nice, since I am by no
means a programmer...
nntppost.c comes here (264 lines):
/*
* Very simple NNTP poster implementation, should be sufficent...
* In case of bugs write to: kbryd@albedo.art.pl
*
* Byte-stuffing added by Orjan Stromberg, might as well send bug-reports
* to me instead, if you have this package. :) <connor@ing.umu.se>
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
static int sd = -1;
// ripped from pop.c
static int
s_gets (int fd, char *s, int len)
{
char ch;
int bytes = 0;
while (read (fd, &ch, 1) > 0)
{
*s++ = ch;
bytes++;
if (ch == '\n')
{
*s = 0;
return (bytes);
}
/* make sure not to overwrite the buffer */
if (bytes == len - 1)
{
*s = 0;
return bytes;
}
}
*s = 0;
return (-1);
}
static int
s_puts (const char *str, int fd)
{
int ret;
ret = send (fd, (char *) str, strlen (str), 0);
if (ret < 0)
return (ret);
return (0);
}
static int
s_printf (int sd, const char *format,...)
{
va_list ap;
int ret;
char buf[1024];
va_start (ap, format);
ret = vsprintf (buf, format, ap);
s_puts (buf, sd);
va_end (ap);
return ret;
}
static int
nntp_open (char *nntp_host, int nntp_port)
{
struct sockaddr_in sin;
struct hostent *he;
int sd, n;
char buf[255];
sd = socket (AF_INET, SOCK_STREAM, IPPROTO_IP);
memset ((char *) &sin, 0, sizeof (sin));
sin.sin_family = AF_INET;
sin.sin_port = htons (nntp_port);
if ((n = inet_addr (nntp_host)) == -1)
{
/* Must be a DNS name */
if ((he = gethostbyname (nntp_host)) == NULL)
{
printf ("Could not find address for host %s.\n", nntp_host);
return (-1);
}
memcpy ((void *) &sin.sin_addr, *(he->h_addr_list), he->h_length);
}
else
memcpy ((void *) &sin.sin_addr, (void *) &n, sizeof (n));
printf ("Connecting to %s\n", inet_ntoa (sin.sin_addr));
if (connect (sd, (struct sockaddr *) &sin, sizeof (struct sockaddr_in)) == -1)
{
perror ("connect");
return (-1);
}
s_gets (sd, buf, sizeof (buf));
s_printf (sd, "MODE READER\r\n");
s_gets (sd, buf, sizeof (buf));
if (atol (buf) != 200)
return (-1);
return (sd);
}
static void
nntp_close (int sd)
{
s_printf (sd, "QUIT\r\n");
close (sd);
}
static char *
striprc (char *s)
{
char *lfrc;
lfrc = strchr (s, '\r');
if (!lfrc)
lfrc = strchr (s, '\n');
if (lfrc)
*lfrc = 0;
return (s);
}
int
mutt_post_article (char *filename)
{
char *line;
FILE *fp;
s_printf (sd, "POST\r\n");
line = (char *) malloc (4096);
s_gets (sd, line, 4096);
if (atol (line) != 340)
{
printf ("Posting not allowed\n");
nntp_close (sd);
free (line);
return (0);
}
fp = fopen (filename, "r");
if (!fp)
return (-1);
while (fgets (line, 4096, fp))
{
if (line[0] == '.')
s_printf (sd, ".%s\r\n", striprc (line));
else
s_printf (sd, "%s\r\n", striprc (line));
}
s_puts (".\r\n", sd);
s_gets (sd, line, 4096);
printf(line);
free (line);
return (0);
}
void
process_mailbox (FILE * src)
{
char buf[1024];
int a = 0;
FILE *dest;
while (a != 1000)
{
for (a = 0; a < 800; a++)
{
if (!(fgets (buf, sizeof (buf), src)))
{
a = 999;
break;
}
dest = fopen ("letter.tmp", "w+");
// fputs (buf, dest);
while (1)
{
if (!(fgets (buf, sizeof (buf), src)))
{
a = 999;
break;
}
if ((strncasecmp (buf, "From ", 5) == 0))
break;
fputs (buf, dest);
}
fseek (src, -strlen (buf), SEEK_CUR);
fclose (dest);
mutt_post_article ("letter.tmp");
unlink ("letter.tmp");
}
}
}
int
main (int argc, char **argv)
{
char *str;
int port;
FILE *src;
if (argc < 3)
{
printf("usage: %s <spool_file> <nntp_host[:nntp_port]>\n", argv[0]);
exit (20);
}
str = strchr (argv[2], ':'); // get the port number
if (str)
{
port = atoi (str + 1);
*str = 0;
}
else
port = 119; // if not given then use default
sd = nntp_open (argv[2], port);
if (sd < 0)
{
printf ("Unable to connect to host\n");
return (0);
}
src = fopen (argv[1], "r");
if (src)
{
process_mailbox (src);
fclose (src);
}
nntp_close (sd);
return 0;
}
Technical Details
Message-ID:
<20040124184513.GC5906@hvk.local>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.20140922.mbox.gz!intern1.nntp.aus1.giganews.com!internal1.nntp.sjc.giganews.com!border2.nntp.sjc.giganews.com!border1.nntp.sjc.giganews.com!nntp.giganews.com!newshub.sdsu.edu!logbridge.uoregon.edu!news.maxwell.syr.edu!news.cis.ohio-state.edu!nntp.service.ohio-state.edu!not-for-mailReferences:
<20040124085405.GA1794@hvk.local> <buu51v$hcf$2@puck.litech.org>Show Full Headers
Complete Article Headers
Message-ID: <20040124184513.GC5906@hvk.local> Subject: Re: [mutt-nntp/NNTPPost] Replacement with authentification (long) Date: Sat, 24 Jan 2004 19:45:13 +0100 From: Andre Berger <andre.berger@web.de> References: <20040124085405.GA1794@hvk.local> <buu51v$hcf$2@puck.litech.org> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.20140922.mbox.gz!intern1.nntp.aus1.giganews.com!internal1.nntp.sjc.giganews.com!border2.nntp.sjc.giganews.com!border1.nntp.sjc.giganews.com!nntp.giganews.com!newshub.sdsu.edu!logbridge.uoregon.edu!news.maxwell.syr.edu!news.cis.ohio-state.edu!nntp.service.ohio-state.edu!not-for-mail Newsgroups: news.software.nntp,news.software.readers Organization: Not Organized Lines: 307 Sender: berger.150@dialin-212-144-032-216.arcor-ip.net NNTP-Posting-Host: dialin-212-144-032-216.arcor-ip.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: charm.magnus.acs.ohio-state.edu 1074969916 26682 212.144.32.216 (24 X-Complaints-To: abuse@osu.edu NNTP-Posting-Date: 24 Jan 2004 18:45:16 GMT Content-Disposition: inline User-Agent: Mutt/1.4.1i-nntp3 X-Accept-Language: de, pdf X-GPG-Fingerprint: 6991 DFD7 5BED A877 779F F7DE 9A56 EBBE 7FB4 C1A3 X-GPG-Key: 0x7FB4C1A3, fetch it from "www.keyserver.net" X-Homepage: <http://www.germanistik.uni-bonn.de/ab/> Mail-Copies-To: nobody