Commit a1a54fce a1a54fce7937ebd9292d66fd431358edbbfbe300 by Sergey Poznyakoff

changed mktime() calls to mu_mktime().

use imap_parse_date_time() in util_parse_internal_date0() (Proposed by Sam)
1 parent a4b81a49
...@@ -671,87 +671,27 @@ add2set (size_t **set, int *n, unsigned long val) ...@@ -671,87 +671,27 @@ add2set (size_t **set, int *n, unsigned long val)
671 return 0; 671 return 0;
672 } 672 }
673 673
674 static const char *months[] = 674 extern int imap_parse_date_time __P((const char **p, struct tm *tm, int *tz));
675 { 675 extern time_t mu_mktime __P((struct tm *timeptr, int tz));
676 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
677 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
678 };
679
680 #define c2d(c) (c-'0')
681 676
682 int 677 int
683 util_parse_internal_date0 (char *date, time_t *timep, char **endp) 678 util_parse_internal_date0 (char *date, time_t *timep, char **endp)
684 { 679 {
685 struct tm tm; 680 struct tm tm;
686 int n, i; 681 int tz;
687 int year, day, hour, min, sec;
688 char mon[4];
689 char tzs[6];
690 time_t time; 682 time_t time;
691 int off; 683 char **datep = &date;
692
693 memset (&tm, 0, sizeof (tm));
694 n = sscanf (date, "%2d-%3s-%4d %2d:%2d:%2d %5s%n\n",
695 &day, mon, &year,
696 &hour, &min, &sec, tzs, &off);
697 684
698 switch (n) 685 if (imap_parse_date_time((const char **)datep, &tm, &tz))
699 {
700 case 3:
701 case 6:
702 if (endp)
703 return 1; 686 return 1;
704 /*FALLTHRU*/
705 case 7:
706 break;
707 default:
708 return 1;
709 }
710
711 tm.tm_mday = day;
712 for (i = 0; i < 11; i++)
713 if (strncmp (months[i], mon, 3) == 0)
714 break;
715 if (i == 12)
716 return 1;
717 tm.tm_mon = i;
718 tm.tm_year = (year < 1900) ? year : year - 1900;
719
720 if (n >= 6)
721 {
722 tm.tm_hour = hour;
723 tm.tm_min = min;
724 tm.tm_sec = sec;
725 }
726 687
727 tm.tm_isdst = -1; /* unknown. */ 688 time = mu_mktime (&tm, tz);
728
729 time = mktime (&tm);
730 if (time == (time_t) -1) 689 if (time == (time_t) -1)
731 return 2; 690 return 2;
732 691
733 if (n == 7)
734 {
735 int tz;
736
737 if (strlen (tzs) != 5)
738 return 3;
739
740 for (i = 1; i <= 4; i++)
741 if (!isdigit (tzs[i]))
742 return 3;
743
744 tz = (c2d (tzs[1])*10 + c2d (tzs[2]))*60 +
745 c2d (tzs[3])*10 + c2d (tzs[4]);
746 if (tzs[0] == '-')
747 tz = -tz;
748 else if (tzs[0] != '+')
749 return 4;
750 time -= tz*60;
751 }
752 *timep = time; 692 *timep = time;
753 if (endp) 693 if (endp)
754 *endp = date + off; 694 *endp = *datep;
755 return 0; 695 return 0;
756 } 696 }
757 697
...@@ -769,12 +709,18 @@ util_parse_822_date (char *date, time_t *timep) ...@@ -769,12 +709,18 @@ util_parse_822_date (char *date, time_t *timep)
769 709
770 if (parse822_date_time(&date, date+strlen(date), &tm) == 0) 710 if (parse822_date_time(&date, date+strlen(date), &tm) == 0)
771 { 711 {
772 *timep = mktime (&tm); 712 *timep = mu_mktime (&tm, 0);
773 return 0; 713 return 0;
774 } 714 }
775 return 1; 715 return 1;
776 } 716 }
777 717
718 static const char *months[] =
719 {
720 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
721 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
722 };
723
778 int 724 int
779 util_parse_ctime_date (char *date, time_t *timep) 725 util_parse_ctime_date (char *date, time_t *timep)
780 { 726 {
...@@ -789,7 +735,6 @@ util_parse_ctime_date (char *date, time_t *timep) ...@@ -789,7 +735,6 @@ util_parse_ctime_date (char *date, time_t *timep)
789 wday[0] = '\0'; 735 wday[0] = '\0';
790 day = mon = year = hour = min = sec = offt = 0; 736 day = mon = year = hour = min = sec = offt = 0;
791 737
792 /* RFC822 Date: format. */
793 if (sscanf (date, "%3s %3s %2d %2d:%2d:%2d %d\n", wday, month, &day, 738 if (sscanf (date, "%3s %3s %2d %2d:%2d:%2d %d\n", wday, month, &day,
794 &hour, &min, &sec, &year) != 7) 739 &hour, &min, &sec, &year) != 7)
795 return 1; 740 return 1;
...@@ -810,8 +755,8 @@ util_parse_ctime_date (char *date, time_t *timep) ...@@ -810,8 +755,8 @@ util_parse_ctime_date (char *date, time_t *timep)
810 tm.tm_yday = 0; /* unknown. */ 755 tm.tm_yday = 0; /* unknown. */
811 tm.tm_wday = 0; /* unknown. */ 756 tm.tm_wday = 0; /* unknown. */
812 tm.tm_isdst = -1; /* unknown. */ 757 tm.tm_isdst = -1; /* unknown. */
813 /* What to do the timezone? */ 758 /* MOTE: UTC */
814 *timep = mktime (&tm); 759 *timep = mu_mktime (&tm, 0);
815 return 0; 760 return 0;
816 } 761 }
817 762
......