[GTER] Limite do Anexo

Lao DanTong danton at inexo.com.br
Thu Aug 2 11:00:18 -03 2007


On Thu, 2 Aug 2007, Marcelo Estanislau wrote:

> Como você faz para "discriminar" estes seus e-mails com grandes anexos e
> enviar quando há pouco tráfego?

neste caso estou usando o qmail, mas em processo de mudança para o exim. 
no qmail eu modifiquei o qmail-queue para que ele calcule esse peso e 
segure a mensagem numa fila especial (que chamei propriamente de "limbo") 
até que um processo externo (em crontab) tire essas mensagens do limbo 
para a fila normal.

o patch no qmail-queue é este:

--- qmail-queue-original.c	2003-08-20 09:13:50.000000000 -0300
+++ qmail-queue.c	2007-07-12 10:17:23.000000000 -0300
@@ -16,6 +16,7 @@
  #include "auto_uids.h"
  #include "date822fmt.h"
  #include "fmtqfn.h"
+#include "control.h"

  #define DEATH 86400 /* 24 hours; _must_ be below q-s's OSSIFIED (36 hours) */
  #define ADDR 1003
@@ -35,10 +36,14 @@
  char *messfn;
  char *todofn;
  char *intdfn;
+char *limbofn;
  int messfd;
  int intdfd;
  int flagmademess = 0;
  int flagmadeintd = 0;
+//int nrcpts = 0;
+int nrcpts=-1; // to discount Tclip.
+int threshold;

  void cleanup()
  {
@@ -159,6 +164,7 @@
   sig_blocknone();
   umask(033);
   if (chdir(auto_qmail) == -1) die(61);
+ if (control_readint(&threshold,"control/limbo-threshold") == -1) threshold=0;
   if (chdir("queue") == -1) die(62);

   mypid = getpid();
@@ -182,6 +188,8 @@
   messfn = fnnum("mess/",1);
   todofn = fnnum("todo/",0);
   intdfn = fnnum("intd/",0);
+ limbofn = fnnum("limbo/",0);
+

   if (link(pidfn,messfn) == -1) die(64);
   if (unlink(pidfn) == -1) die(63);
@@ -242,13 +250,20 @@
       if (!ch) break;
      }
     if (len >= ADDR) die(11);
+   nrcpts++;
    }

   if (substdio_flush(&ssout) == -1) die_write();
   if (fsync(intdfd) == -1) die_write();

- if (link(intdfn,todofn) == -1) die(66);
-
- triggerpull();
+/* checks the metric(size*nrcpts) against threshold and send message to limbo if higher */
+ if (stat(messfn,&pidst) == -1) die(63);
+ if (threshold && nrcpts*pidst.st_size > threshold) {
+  if (link(intdfn,limbofn) == -1) die(66);
+  if (unlink(intdfn) == -1) die(63);
+ } else {
+  if (link(intdfn,todofn) == -1) die(66);
+  triggerpull();
+ }
   die(0);
  }


e ainda tem que dar uma acertada no makefile para a coisa compilar.

o script do crontab é:

#!/bin/bash
#
#       rescues messages stuck at the limbo.
#
cd /var/qmail/queue
set -- limbo/*
test -e $1 || exit 0
mv $@ todo
echo -ne \\0 >lock/trigger


Quando mudar para o exim pretendo ter alguma coisa menos tudo-ou-nada e 
simplesmente priorizar as mensagens menores, tipo primeiro pulgas, depois 
os elefantes e, se sobrar algum recurso, baleias.



More information about the gter mailing list