Exemplo n.º 1
0
Arquivo: mail.c Projeto: 91D2/pvpgn
static void mail_func_send(t_connection * c, const char * str) {
   int i;
   char *dest;
   char const *p,*myname;   
   t_account * recv;
   t_mailbox * mailbox;
   
   if (c==NULL) {
      eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");
      return;
   }
   if (str==NULL) {
      eventlog(eventlog_level_error,__FUNCTION__,"got NULL command string");
      return;
   }
   for(i=0;str[i]==' ';i++); /* skip any spaces */
   if (str[i]=='\0') { /* the %mail send command has no receiver */
      message_send_text(c,message_type_error,c,"You must specify the receiver");
      message_send_text(c,message_type_error,c,"Syntax: /mail send <receiver> <message>");
      return;
   }
   p=str+i; /* set ip at the start of receiver string */
   for(i=1;p[i]!=' ' && p[i]!='\0';i++); /* skip the receiver string */
   if (p[i]=='\0') { /* it seems user forgot to write any message */
      message_send_text(c,message_type_error,c,"Your message is empty!");
      message_send_text(c,message_type_error,c,"Syntax: /mail send <receiver> <message>");
      return;
   }
   dest=xmalloc(i+1);
   memmove(dest,p,i); dest[i]='\0'; /* copy receiver in his separate string */
   if ((recv=accountlist_find_account(dest))==NULL) { /* is dest a valid account on this server ? */
      message_send_text(c,message_type_error,c,"Receiver UNKNOWN!");
      xfree(dest);
      return;
   }
   xfree(dest); /* free dest here, the sooner the better */
   if ((mailbox=mailbox_open(recv, mbox_mode_write))==NULL) {
      message_send_text(c,message_type_error,c,"There was an error completing your request!");
      return;
   }
   if (get_mail_quota(recv)<=mailbox_count(mailbox)) { /* check quota */
      message_send_text(c,message_type_error,c,"Receiver has reached his mail quota. Your message will NOT be sent.");
      mailbox_close(mailbox);
      return;
   }
   myname=conn_get_username(c); /* who am i ? */
   if (mailbox_deliver(mailbox,myname,p+i+1)<0)
     message_send_text(c,message_type_error,c,"There was an error completing your request!");
   else 
     message_send_text(c,message_type_info,c,"Your mail has been sent successfully.");
   mailbox_close(mailbox);
}
Exemplo n.º 2
0
Arquivo: tasks.c Projeto: layeka/2can
u8 send_to_task(u8 taskid, u8 code, u8 payload_len, u8 *payload)
{
    task_t *task = get_task_by_id(taskid);

    if (task)
    {
        return mailbox_deliver(&(task->mailbox), code, payload_len, payload);
    }
    else
    {
        return 2;
    }
}