mirror of
				https://bitbucket.org/jsuto/piler.git
				synced 2025-10-31 05:22:26 +01:00 
			
		
		
		
	code cleanup #2
This commit is contained in:
		| @@ -15,6 +15,7 @@ | ||||
| #define ERR_SETGID "ERR: setgid()" | ||||
| #define ERR_SELECT "ERR: select()" | ||||
| #define ERR_CHDIR "ERR: chdir() to working directory failed" | ||||
| #define ERR_DAEMON "ERR: daemon()" | ||||
| #define ERR_OPEN_TMP_FILE "ERR: opening a tempfile" | ||||
| #define ERR_TIMED_OUT "ERR: timed out" | ||||
| #define ERR_FORK_FAILED "ERR: cannot fork()" | ||||
|   | ||||
							
								
								
									
										14
									
								
								src/imap.c
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								src/imap.c
									
									
									
									
									
								
							| @@ -101,7 +101,7 @@ int process_imap_folder(int sd, int *seq, char *folder, struct session_data *sda | ||||
|  | ||||
|    snprintf(buf, sizeof(buf)-1, "A%d SELECT %s\r\n", *seq, folder); | ||||
|  | ||||
|    n = write1(sd, buf, strlen(buf), use_ssl, data->ssl); | ||||
|    write1(sd, buf, strlen(buf), use_ssl, data->ssl); | ||||
|    if(read_response(sd, buf, sizeof(buf), seq, data, use_ssl) == 0){ | ||||
|       trimBuffer(buf); | ||||
|       printf("select cmd error: %s\n", buf); | ||||
| @@ -161,7 +161,7 @@ int process_imap_folder(int sd, int *seq, char *folder, struct session_data *sda | ||||
|       } | ||||
|  | ||||
|  | ||||
|       n = write1(sd, buf, strlen(buf), use_ssl, data->ssl); | ||||
|       write1(sd, buf, strlen(buf), use_ssl, data->ssl); | ||||
|  | ||||
|       readlen = 0; | ||||
|       nreads = 0; | ||||
| @@ -264,7 +264,7 @@ int process_imap_folder(int sd, int *seq, char *folder, struct session_data *sda | ||||
|  | ||||
|          if(data->import->remove_after_import == 1 && dryrun == 0){ | ||||
|             snprintf(buf, sizeof(buf)-1, "A%d STORE %d +FLAGS.SILENT (\\Deleted)\r\n", *seq, i); | ||||
|             n = write1(sd, buf, strlen(buf), use_ssl, data->ssl); | ||||
|             write1(sd, buf, strlen(buf), use_ssl, data->ssl); | ||||
|             read_response(sd, buf, sizeof(buf), seq, data, use_ssl); | ||||
|          } | ||||
|  | ||||
| @@ -275,12 +275,12 @@ int process_imap_folder(int sd, int *seq, char *folder, struct session_data *sda | ||||
|             tagoklen = strlen(tagok); | ||||
|  | ||||
|             snprintf(buf, sizeof(buf)-1, "A%d COPY %d %s\r\n", *seq, i, data->import->move_folder); | ||||
|             n = write1(sd, buf, strlen(buf), use_ssl, data->ssl); | ||||
|             write1(sd, buf, strlen(buf), use_ssl, data->ssl); | ||||
|             read_response(sd, buf, sizeof(buf), seq, data, use_ssl); | ||||
|  | ||||
|             if(strncmp(buf, tagok, tagoklen) == 0){ | ||||
|                snprintf(buf, sizeof(buf)-1, "A%d STORE %d +FLAGS.SILENT (\\Deleted)\r\n", *seq, i); | ||||
|                n = write1(sd, buf, strlen(buf), use_ssl, data->ssl); | ||||
|                write1(sd, buf, strlen(buf), use_ssl, data->ssl); | ||||
|                read_response(sd, buf, sizeof(buf), seq, data, use_ssl); | ||||
|  | ||||
|             } | ||||
| @@ -296,7 +296,7 @@ int process_imap_folder(int sd, int *seq, char *folder, struct session_data *sda | ||||
|  | ||||
|    if((data->import->remove_after_import == 1 || data->import->move_folder) && dryrun == 0){ | ||||
|       snprintf(buf, sizeof(buf)-1, "A%d EXPUNGE\r\n", *seq); | ||||
|       n = write1(sd, buf, strlen(buf), use_ssl, data->ssl); | ||||
|       write1(sd, buf, strlen(buf), use_ssl, data->ssl); | ||||
|       read_response(sd, buf, sizeof(buf), seq, data, use_ssl); | ||||
|    } | ||||
|  | ||||
| @@ -351,7 +351,7 @@ int connect_to_imap_server(int sd, int *seq, char *username, char *password, int | ||||
|    } | ||||
|  | ||||
|  | ||||
|    n = recvtimeoutssl(sd, buf, sizeof(buf), data->import->timeout, use_ssl, data->ssl); | ||||
|    recvtimeoutssl(sd, buf, sizeof(buf), data->import->timeout, use_ssl, data->ssl); | ||||
|  | ||||
|  | ||||
|    /* imap cmd: LOGIN */ | ||||
|   | ||||
| @@ -220,12 +220,14 @@ time_t parse_date_header(char *datestr, struct __config *cfg){ | ||||
|          if((len == 5 && (*s == '+' || *s == '-')) || (len == 8 && (strncmp(s, "GMT+", 4) == 0 || strncmp(s, "GMT-", 4) == 0))){ | ||||
|             offset = 0; | ||||
|             tz = strpbrk(s, "+-"); | ||||
|             memset(tzh, 0, 4); | ||||
|             memset(tzm, 0, 3); | ||||
|             strncpy(tzh, tz, 3); | ||||
|             strncpy(tzm, tz+3, 2); | ||||
|             offset += atoi(tzh) * 3600; | ||||
|             offset += atoi(tzm) * 60; | ||||
|             if(tz){ | ||||
|                memset(tzh, 0, 4); | ||||
|                memset(tzm, 0, 3); | ||||
|                strncpy(tzh, tz, 3); | ||||
|                strncpy(tzm, tz+3, 2); | ||||
|                offset += atoi(tzh) * 3600; | ||||
|                offset += atoi(tzm) * 60; | ||||
|             } | ||||
|             continue; | ||||
|          } | ||||
|  | ||||
| @@ -351,7 +353,7 @@ void fixupEncodedHeaderLine(char *buf, int buflen){ | ||||
|          if(start){ | ||||
|             *start = '\0'; | ||||
|             if(strlen(p) > 0){ | ||||
|                strncat(puf, p, sizeof(puf)-1); | ||||
|                strncat(puf, p, sizeof(puf)-strlen(puf)-1); | ||||
|             } | ||||
|  | ||||
|             start++; | ||||
| @@ -386,27 +388,27 @@ void fixupEncodedHeaderLine(char *buf, int buflen){ | ||||
|                   } | ||||
|  | ||||
|                   if(need_encoding == 1 && ret == OK) | ||||
|                      strncat(puf, tmpbuf, sizeof(puf)-1); | ||||
|                      strncat(puf, tmpbuf, sizeof(puf)-strlen(puf)-1); | ||||
|                   else  | ||||
|                      strncat(puf, s+3, sizeof(puf)-1); | ||||
|                      strncat(puf, s+3, sizeof(puf)-strlen(puf)-1); | ||||
|  | ||||
|                   p = end + 2; | ||||
|                } | ||||
|             } | ||||
|             else { | ||||
|                strncat(puf, start, sizeof(puf)-1); | ||||
|                strncat(puf, start, sizeof(puf)-strlen(puf)-1); | ||||
|  | ||||
|                break; | ||||
|             } | ||||
|          } | ||||
|          else { | ||||
|             strncat(puf, p, sizeof(puf)-1); | ||||
|             strncat(puf, p, sizeof(puf)-strlen(puf)-1); | ||||
|             break; | ||||
|          } | ||||
|  | ||||
|       } while(p); | ||||
|  | ||||
|       if(q) strncat(puf, " ", sizeof(puf)-1); | ||||
|       if(q) strncat(puf, " ", sizeof(puf)-strlen(puf)-1); | ||||
|  | ||||
|    } while(q); | ||||
|  | ||||
| @@ -450,7 +452,7 @@ void fixupBase64EncodedLine(char *buf, struct parser_state *state){ | ||||
|    if(strlen(state->miscbuf) > 0){ | ||||
|       memset(puf, 0, sizeof(puf)); | ||||
|       strncpy(puf, state->miscbuf, sizeof(puf)-1); | ||||
|       strncat(puf, buf, sizeof(puf)-1); | ||||
|       strncat(puf, buf, sizeof(puf)-strlen(puf)-1); | ||||
|  | ||||
|       memset(buf, 0, MAXBUFSIZE); | ||||
|       memcpy(buf, puf, MAXBUFSIZE); | ||||
| @@ -539,7 +541,7 @@ void markHTML(char *buf, struct parser_state *state){ | ||||
|    } | ||||
|  | ||||
|    //printf("append last in line:*%s*, html=+%s+, j=%d\n", puf, html, j); | ||||
|    if(j > 0){ k += appendHTMLTag(puf, html, pos, state); } | ||||
|    if(j > 0){ appendHTMLTag(puf, html, pos, state); } | ||||
|  | ||||
|    strcpy(buf, puf); | ||||
| } | ||||
|   | ||||
| @@ -104,7 +104,7 @@ int remove_attachments(char *in, struct session_data *sdata, struct __data *data | ||||
|    char filename[SMALLBUFSIZE]; | ||||
|    char *a, buf[BIGBUFSIZE-300], update_meta_sql[BIGBUFSIZE], delete_attachment_stmt[BIGBUFSIZE]; | ||||
|    char piler_id[SMALLBUFSIZE], i[BUFLEN]; | ||||
|    int n=0, len, attachment_id; | ||||
|    int n=0, len, attachment_id=0; | ||||
| #ifdef HAVE_SUPPORT_FOR_COMPAT_STORAGE_LAYOUT | ||||
|    struct stat st; | ||||
| #endif | ||||
| @@ -149,6 +149,11 @@ int remove_attachments(char *in, struct session_data *sdata, struct __data *data | ||||
|  | ||||
|    while(p_fetch_results(data->stmt_select_non_referenced_attachments) == OK){ | ||||
|  | ||||
|       if(strlen(piler_id) != RND_STR_LEN || attachment_id <= 0){ | ||||
|          printf("invalid piler_id: '%s.a%d'\n", piler_id, attachment_id); | ||||
|          continue; | ||||
|       } | ||||
|  | ||||
|       snprintf(filename, sizeof(filename)-1, "%s/%02x/%c%c%c/%c%c/%c%c/%s.a%d", cfg->queuedir, cfg->server_id, piler_id[8], piler_id[9], piler_id[10], piler_id[RND_STR_LEN-4], piler_id[RND_STR_LEN-3], piler_id[RND_STR_LEN-2], piler_id[RND_STR_LEN-1], piler_id, attachment_id); | ||||
|    #ifdef HAVE_SUPPORT_FOR_COMPAT_STORAGE_LAYOUT | ||||
|       if(stat(filename, &st)){ | ||||
|   | ||||
							
								
								
									
										18
									
								
								src/pop3.c
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								src/pop3.c
									
									
									
									
									
								
							| @@ -75,19 +75,19 @@ int connect_to_pop3_server(int sd, char *username, char *password, int port, str | ||||
|    } | ||||
|  | ||||
|  | ||||
|    n = recvtimeoutssl(sd, buf, sizeof(buf), data->import->timeout, use_ssl, data->ssl); | ||||
|    recvtimeoutssl(sd, buf, sizeof(buf), data->import->timeout, use_ssl, data->ssl); | ||||
|  | ||||
|  | ||||
|    snprintf(buf, sizeof(buf)-1, "USER %s\r\n", username); | ||||
|  | ||||
|    write1(sd, buf, strlen(buf), use_ssl, data->ssl); | ||||
|    n = recvtimeoutssl(sd, buf, sizeof(buf), data->import->timeout, use_ssl, data->ssl); | ||||
|    recvtimeoutssl(sd, buf, sizeof(buf), data->import->timeout, use_ssl, data->ssl); | ||||
|  | ||||
|  | ||||
|    snprintf(buf, sizeof(buf)-1, "PASS %s\r\n", password); | ||||
|  | ||||
|    write1(sd, buf, strlen(buf), use_ssl, data->ssl); | ||||
|    n = recvtimeoutssl(sd, buf, sizeof(buf), data->import->timeout, use_ssl, data->ssl); | ||||
|    recvtimeoutssl(sd, buf, sizeof(buf), data->import->timeout, use_ssl, data->ssl); | ||||
|  | ||||
|    if(strncmp(buf, "+OK", 3) == 0) return OK; | ||||
|  | ||||
| @@ -106,9 +106,9 @@ int process_pop3_emails(int sd, struct session_data *sdata, struct __data *data, | ||||
|    data->import->total_messages = 0; | ||||
|  | ||||
|    snprintf(buf, sizeof(buf)-1, "STAT\r\n"); | ||||
|    n = write1(sd, buf, strlen(buf), use_ssl, data->ssl); | ||||
|    write1(sd, buf, strlen(buf), use_ssl, data->ssl); | ||||
|  | ||||
|    n = recvtimeoutssl(sd, buf, sizeof(buf), data->import->timeout, use_ssl, data->ssl); | ||||
|    recvtimeoutssl(sd, buf, sizeof(buf), data->import->timeout, use_ssl, data->ssl); | ||||
|  | ||||
|    if(strncmp(buf, "+OK ", 4) == 0){ | ||||
|       p = strchr(&buf[4], ' '); | ||||
| @@ -140,7 +140,7 @@ int process_pop3_emails(int sd, struct session_data *sdata, struct __data *data, | ||||
|          return rc; | ||||
|       } | ||||
|  | ||||
|       n = write1(sd, buf, strlen(buf), use_ssl, data->ssl); | ||||
|       write1(sd, buf, strlen(buf), use_ssl, data->ssl); | ||||
|  | ||||
|       readlen = 0; | ||||
|       pos = 0; | ||||
| @@ -203,8 +203,8 @@ int process_pop3_emails(int sd, struct session_data *sdata, struct __data *data, | ||||
|  | ||||
|       if(dryrun == 0 && rc == OK && data->import->remove_after_import == 1){ | ||||
|          snprintf(buf, sizeof(buf)-1, "DELE %d\r\n", i); | ||||
|          n = write1(sd, buf, strlen(buf), use_ssl, data->ssl); | ||||
|          n = recvtimeoutssl(sd, buf, sizeof(buf), data->import->timeout, use_ssl, data->ssl); | ||||
|          write1(sd, buf, strlen(buf), use_ssl, data->ssl); | ||||
|          recvtimeoutssl(sd, buf, sizeof(buf), data->import->timeout, use_ssl, data->ssl); | ||||
|       } | ||||
|  | ||||
|       if(i % 100 == 0){ | ||||
| @@ -224,7 +224,7 @@ int process_pop3_emails(int sd, struct session_data *sdata, struct __data *data, | ||||
|  | ||||
|  | ||||
|    snprintf(buf, sizeof(buf)-1, "QUIT\r\n"); | ||||
|    n = write1(sd, buf, strlen(buf), use_ssl, data->ssl); | ||||
|    write1(sd, buf, strlen(buf), use_ssl, data->ssl); | ||||
|  | ||||
|    if(data->quiet == 0) printf("\n"); | ||||
|  | ||||
|   | ||||
| @@ -121,6 +121,8 @@ struct rule *create_rule_item(struct rule_cond *rule_cond, struct __data *data){ | ||||
|    char empty = '\0'; | ||||
|    int len; | ||||
|  | ||||
|    if(rule_cond == NULL) return NULL; | ||||
|  | ||||
|    if((h = malloc(sizeof(struct rule))) == NULL) | ||||
|       return NULL; | ||||
|  | ||||
|   | ||||
| @@ -300,7 +300,7 @@ int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){ | ||||
|                if(puf[n-2] != '\r' && puf[n-1] != '\n'){ | ||||
|                   memmove(puf, puf+pos, n-pos); | ||||
|                   memset(puf+n-pos, 0, MAXBUFSIZE-n+pos); | ||||
|                   i = recvtimeout(new_sd, buf, MAXBUFSIZE, TIMEOUT); | ||||
|                   recvtimeout(new_sd, buf, MAXBUFSIZE, TIMEOUT); | ||||
|                   strncat(puf, buf, MAXBUFSIZE-1-n+pos); | ||||
|                   if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: partial read: %s", sdata.ttmpfile, puf); | ||||
|                   pos = 0; | ||||
| @@ -356,7 +356,7 @@ AFTER_PERIOD: | ||||
|  | ||||
|          if(strncasecmp(buf, SMTP_CMD_HELO, strlen(SMTP_CMD_HELO)) == 0){ | ||||
|             if(protocol_state == SMTP_STATE_INIT) protocol_state = SMTP_STATE_HELO; | ||||
|             strncat(resp, SMTP_RESP_250_OK, sizeof(resp)-1); | ||||
|             strncat(resp, SMTP_RESP_250_OK, sizeof(resp)-strlen(resp)-1); | ||||
|             continue; | ||||
|          } | ||||
|  | ||||
| @@ -399,7 +399,7 @@ AFTER_PERIOD: | ||||
|  | ||||
|  | ||||
|          if(strncasecmp(buf, SMTP_CMD_NOOP, strlen(SMTP_CMD_NOOP)) == 0){ | ||||
|             strncat(resp, SMTP_RESP_250_OK, sizeof(resp)-1); | ||||
|             strncat(resp, SMTP_RESP_250_OK, sizeof(resp)-strlen(resp)-1); | ||||
|             continue; | ||||
|          } | ||||
|  | ||||
| @@ -413,7 +413,7 @@ AFTER_PERIOD: | ||||
|          /* by default send 502 command not implemented message */ | ||||
|  | ||||
|          syslog(LOG_PRIORITY, "%s: invalid command: *%s*", sdata.ttmpfile, buf); | ||||
|          strncat(resp, SMTP_RESP_502_ERR, sizeof(resp)-1); | ||||
|          strncat(resp, SMTP_RESP_502_ERR, sizeof(resp)-strlen(resp)-1); | ||||
|       } while(p); | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -48,7 +48,7 @@ int store_file(struct session_data *sdata, char *filename, int startpos, int len | ||||
|  | ||||
|    EVP_CIPHER_CTX ctx; | ||||
|    unsigned char *outbuf=NULL; | ||||
|    int outlen, writelen, tmplen; | ||||
|    int outlen=0, writelen, tmplen; | ||||
|  | ||||
|    struct timezone tz; | ||||
|    struct timeval tv1, tv2; | ||||
| @@ -118,7 +118,7 @@ int store_file(struct session_data *sdata, char *filename, int startpos, int len | ||||
|  | ||||
|    if(p){ | ||||
|       *p = '.'; | ||||
|       strncat(s, p, sizeof(s)-1); | ||||
|       strncat(s, p, sizeof(s)-strlen(s)-1); | ||||
|    } | ||||
|  | ||||
|  | ||||
| @@ -131,9 +131,9 @@ int store_file(struct session_data *sdata, char *filename, int startpos, int len | ||||
|       p2 = strrchr(s, '/'); if(!p2) goto ENDE; | ||||
|       *p2 = '\0'; | ||||
|  | ||||
|       rc = mkdir(s, 0750); | ||||
|       mkdir(s, 0750); | ||||
|       *p2 = '/'; | ||||
|       rc = mkdir(s, 0750); | ||||
|       mkdir(s, 0750); | ||||
|       *p1 = '/'; | ||||
|       rc = mkdir(s, 0770); if(rc == -1) syslog(LOG_PRIORITY, "%s: mkdir %s: error=%s", sdata->ttmpfile, s, strerror(errno)); | ||||
|    } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user