/**********************************************************************
 * luc_forward.c -- forward transaction
 *
 * $Author: brlewis $
 * $Source: /afs/athena.mit.edu/astaff/project/lucydev/src/lib/RCS/luc_forward.c,v $
 * $Header: /afs/athena.mit.edu/astaff/project/lucydev/src/lib/RCS/luc_forward.c,v 1.3 91/10/15 16:45:03 brlewis Exp Locker: brlewis $
 *
 * Copyright 1991 by the Massachusetts Institute of Technology.
 *
 * For copying and distribution information, please see the file
 * <mit-copyright.h>.
 **********************************************************************/
#include <mit-copyright.h>

#ifndef lint
static char rcsid_luc_forward_c[] = "$Header: /afs/athena.mit.edu/astaff/project/lucydev/src/lib/RCS/luc_forward.c,v 1.3 91/10/15 16:45:03 brlewis Exp Locker: brlewis $";
#endif /* lint */

#include <stdio.h>
#include <strings.h>
#include <sys/errno.h>
#include <lucy/lucy.h>

/**********************************************************************
 * luc_forward(lmeeting *mp, int n, char *rcpt)
 *	caller sets mp (usually luv_curmtgp) to specify meeting
 *	caller sets n to specify transaction number
 *	caller sets rcpt to email address
 *
 * - returns error code
 **********************************************************************/

long
luc_forward(mp, n, rcpt)
     LMEETING *mp;
     int n;
     char *rcpt;
{
  long code;
  char buf[BUFSIZ];
  int n2;
  ltrn *trninfo;

  /* Mark the trn to be forwarded */
  if (code = luc_mark(mp, n, LUCY_WANT_FORWARD)) {
    sprintf(luv_context, "%d", n);
    return(code);
  }

  /* mark first trn in chain */
  if (code=luc_trn_info(mp, n, &trninfo)) {
    sprintf(luv_context, "%d", n);
    return(code);
  }
  if (code = luc_mark(mp, trninfo->fref, LUCY_WANT_FORWARD)) {
    sprintf(luv_context, "%d", n);
    return(code);
  }

  /* Add transaction requesting forwarding */
  sprintf(buf, "forw %d %s", n, rcpt);
  if (code = luc_add_trn(mp, "/dev/null", buf,
			 luc_fullname(mp->nb.user_id), n, &n2)) {
    sprintf(luv_context, "%d", n);
    return(code);
  }
  if (code = luc_mark(mp, n2, LUCY_WANT_FORWARD)) {
    sprintf(luv_context, "%d", n2);
    return(code);
  }

  /* let the lucyd server do the rest of the work */
  return(luc_parse(n2));
}
