aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/getfetchmail
blob: bcac9d3e6eb1c2dd3599febbd586857269dd87bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash 
RH=ftp.ccil.org
p=`\
echo dir /pub/esr/fetchmail/f\*src.rpm \
   | ftp $RH \
   | grep /pub/esr/fetchmail/fetchmail-[45] \
   | tail -1`
#p='-rw-r--r-- 1 23 wheel 478424 Dec 18 03:54 /pub/esr/fetchmail/fetchmail-4.7.1-1.src.rpm'
#echo $p | sed -e "s=^.^/pub=pub="
p1=`echo $p | sed -e "s=^.*/pub=pub="`
#echo $p1
#basename  $p1
#dirname $p1
d=`dirname $p1`
f=`basename $p1`
cd /work/incoming
email=$LOGNAME\@`hostname`
ftp -n <<ZZ
open $RH
user anonymous $email
cd /$d
get $f
bye
ZZ
rpm -K $f >/dev/null 2>&1 \
   || {
         rpm -K $f 2>&1 | mail $email -s "error getting $f"
         exit 
      }
rpm --rebuild  $f 2>&1 |\
   mail $email -s "Rebuilding $f"
redoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/* Copyright 1996 by Eric S. Raymond
 * All rights reserved.
 * For license terms, see the file COPYING in this directory.
 */

/***********************************************************************
  module:       imap.c
  project:      fetchmail
  programmer:   Eric S. Raymond
  description:  IMAP client code

 ***********************************************************************/

#include  <config.h>
#include  <stdio.h>
#include  <string.h>
#include  "socket.h"
#include  "fetchmail.h"

/*********************************************************************

 Method declarations for IMAP 

 *********************************************************************/

static int count, seen;

int imap_ok (socket, argbuf)
/* parse command response */
char *argbuf;
int socket;
{
    int ok;
    char buf [POPBUFSIZE+1];
    char *bufp;
    int n;

    seen = 0;
    do {
	if (SockGets(socket, buf, sizeof(buf)) < 0)
	    return(PS_SOCKET);

	if (outlevel == O_VERBOSE)
	    fprintf(stderr,"%s\n",buf);

	/* interpret untagged status responses */
	if (strstr(buf, "EXISTS"))
	    count = atoi(buf+2);
	if (strstr(buf, "FLAGS"))
	    seen = (strstr(buf, "Seen") != (char *)NULL);
    } while
	(tag[0] != '\0' && strncmp(buf, tag, strlen(tag)));

    if (tag[0] == '\0')
    {
	strcpy(argbuf, buf);
	return(0); 
    }
    else
    {
	char	*cp;

	/* skip the tag */
	for (cp = buf; !isspace(*cp); cp++)
	    continue;
	while (isspace(*cp))
	    cp++;

	if (strncmp(cp, "OK", 2) == 0)
	{
	    strcpy(argbuf, cp);
	    return(0);
	}
	else if (strncmp(cp, "BAD", 2) == 0)
	    return(PS_ERROR);
	else
	    return(PS_PROTOCOL);
    }
}

int imap_getauth(socket, queryctl, buf)
/* apply for connection authorization */
int socket;
struct hostrec *queryctl;
char *buf;
{
    /* try to get authorized */
    return(gen_transact(socket,
		  "LOGIN %s %s",
		  queryctl->remotename, queryctl->password));
}

static imap_getrange(socket, queryctl, countp)
/* get range of messages to be fetched */
int socket;
struct hostrec *queryctl;
int *countp;
{
    int ok;

    /* find out how many messages are waiting */
    ok = gen_transact(socket,
		  "SELECT %s",
		  queryctl->remotefolder[0] ? queryctl->remotefolder : "INBOX");
    if (ok != 0)
	return(ok);

    *countp = count;

    return(0);
}

static imap_is_old(socket, queryctl, num)
int socket;
struct hostrec *queryctl;
int num;
{
    char buf [POPBUFSIZE+1];
    int ok;

    if ((ok = gen_transact(socket, "FETCH %d FLAGS", num)) != 0)
	exit(PS_ERROR);

    return(seen);
}

static int imap_fetch(socket, number, lenp)
/* request nth message */
int socket;
int number;
int *lenp; 
{
    char buf [POPBUFSIZE+1];
    int	num;

    gen_send(socket, "FETCH %d RFC822", number);

    /* looking for FETCH response */
    do {
	if (SockGets(socket, buf,sizeof(buf)) < 0)
	    return(PS_SOCKET);
    } while
	    (sscanf(buf+2, "%d FETCH (RFC822 {%d}", &num, lenp) != 2);

    if (num != number)
	return(PS_ERROR);
    else
	return(0);
}

static imap_trail(socket, queryctl, number)
/* discard tail of FETCH response */
int socket;
struct hostrec *queryctl;
int number;
{
    char buf [POPBUFSIZE+1];

    if (SockGets(socket, buf,sizeof(buf)) < 0)
	return(PS_SOCKET);
    else
	return(0);
}

static imap_delete(socket, queryctl, number)
/* set delete flag for given message */
int socket;
struct hostrec *queryctl;
int number;
{
    return(gen_transact(socket, "STORE %d +FLAGS (\\Deleted)", number));
}

const static struct method imap =
{
    "IMAP",		/* Internet Message Access Protocol */
    143,		/* standard IMAP2bis/IMAP4 port */
    1,			/* this is a tagged protocol */
    0,			/* no message delimiter */
    imap_ok,		/* parse command response */
    imap_getauth,	/* get authorization */
    imap_getrange,	/* query range of messages */
    imap_is_old,	/* no UID check */
    imap_fetch,		/* request given message */
    imap_trail,		/* eat message trailer */
    imap_delete,	/* set IMAP delete flag */
    "EXPUNGE",		/* the IMAP expunge command */
    "LOGOUT",		/* the IMAP exit command */
};

int doIMAP (queryctl)
/* retrieve messages using IMAP Version 2bis or Version 4 */
struct hostrec *queryctl;
{
    return(do_protocol(queryctl, &imap));
}