modified the code for readability.
authorHiroyuki Yamamoto <hiro-y@kcn.ne.jp>
Mon, 14 May 2001 09:32:34 +0000 (09:32 +0000)
committerHiroyuki Yamamoto <hiro-y@kcn.ne.jp>
Mon, 14 May 2001 09:32:34 +0000 (09:32 +0000)
ChangeLog.claws
src/send.c
src/textview.c

index e3d2cbd4f8e9570be4ff036aaa895e3041198632..c3a30c3ff9dede6caa74c4bdf8dbf992ae890da5 100644 (file)
@@ -1,3 +1,8 @@
+2001-05-14 [hiroyuki]
+
+       * src/send.c: fixed some weird indentations.
+       * src/textview.c: get_email_part(): modified the code for readability.
+
 2001-05-14 [hiroyuki]
 
        * src/md5global.h
index 0154c26262a5556ccee7d7b985af43fc8f0fd787..41e3682ab8389f46f173a9b7681794ce7b055fdc 100644 (file)
@@ -88,25 +88,20 @@ gint send_message(const gchar *file, PrefsAccount *ac_prefs, GSList *to_list)
                return -1;
        }
 
-       if (ac_prefs->protocol == A_LOCAL && ac_prefs->use_mail_command)
-               {
-                       val = send_message_with_command(to_list,
-                                                       ac_prefs->mail_command,
-                                                       fp);
-               }
-       else
-               {
-                       port = ac_prefs->set_smtpport
-                               ? ac_prefs->smtpport : SMTP_PORT;
-                       domain = ac_prefs->set_domain
-                               ? ac_prefs->domain : NULL;
-                       
-                       val = send_message_smtp(to_list, ac_prefs->address,
-                                               ac_prefs->smtp_server, port,
-                                               domain, ac_prefs->userid,
-                                               ac_prefs->passwd,
-                                               ac_prefs->use_smtp_auth, fp);
-               }
+       if (ac_prefs->protocol == A_LOCAL && ac_prefs->use_mail_command) {
+               val = send_message_with_command(to_list,
+                                               ac_prefs->mail_command,
+                                               fp);
+       } else {
+               port = ac_prefs->set_smtpport ? ac_prefs->smtpport : SMTP_PORT;
+               domain = ac_prefs->set_domain ? ac_prefs->domain : NULL;
+
+               val = send_message_smtp(to_list, ac_prefs->address,
+                                       ac_prefs->smtp_server, port,
+                                       domain, ac_prefs->userid,
+                                       ac_prefs->passwd,
+                                       ac_prefs->use_smtp_auth, fp);
+       }
 
        fclose(fp);
        return val;
@@ -135,28 +130,26 @@ static gint send_message_with_command(GSList *to_list, gchar * mailcmd,
        cmdline = g_new(gchar, len + 1);
        strcpy(cmdline, mailcmd);
 
-       for (cur = to_list; cur != NULL; cur = cur->next)
-               {
-                       cmdline = strncat(cmdline, " ", len);
-                       cmdline = strncat(cmdline, (gchar *)cur->data, len);
-               }
+       for (cur = to_list; cur != NULL; cur = cur->next) {
+               cmdline = strncat(cmdline, " ", len);
+               cmdline = strncat(cmdline, (gchar *)cur->data, len);
+       }
 
        log_message(_("Using command to send mail: %s ...\n"), cmdline);
 
        p = popen(cmdline, "w");
-       if (p != NULL)
-               {
-                       while (fgets(buf, sizeof(buf), fp) != NULL) {
-                               strretchomp(buf);
-                               
-                               /* escape when a dot appears on the top */
-                               if (buf[0] == '.')
-                                       fputs(".", p);
-                               
-                               fputs(buf, p);
-                               fputs("\n", p);
-                       }
+       if (p != NULL) {
+               while (fgets(buf, sizeof(buf), fp) != NULL) {
+                       strretchomp(buf);
+
+                       /* escape when a dot appears on the top */
+                       if (buf[0] == '.')
+                               fputs(".", p);
+
+                       fputs(buf, p);
+                       fputs("\n", p);
                }
+       }
        pclose(p);
 
        log_message(_("Mail sent successfully ...\n"));
index 4fc6bfbfecb18f5850def3971d5842065f8813f6..87151fb45c0e99db279ebc8d54edde06cea4eec7 100644 (file)
@@ -483,6 +483,12 @@ static gboolean get_email_part(const gchar *start, const gchar *scanpos,
        const gchar *bp_ = NULL;
        const gchar *ep_ = NULL;
 
+       /* the informative part of the email address (describing the name
+        * of the email address owner) may contain quoted parts. the
+        * closure stack stores the last encountered quotes. */
+       gchar closure_stack[128];
+       gchar *ptr = closure_stack;
+
        g_return_val_if_fail(start != NULL, FALSE);
        g_return_val_if_fail(scanpos != NULL, FALSE);
        g_return_val_if_fail(bp != NULL, FALSE);
@@ -514,62 +520,57 @@ static gboolean get_email_part(const gchar *start, const gchar *scanpos,
                }
        }
 
+       if (!result) return FALSE;
+
        /* we now have at least the address. now see if this is <bracketed>; in this
         * case we also scan for the informative part. we could make this a useful
         * function because it tries to parse out an email address backwards. :) */
-       if (result) {
-               if ( ((bp_ - 1 > start) && *(bp_ - 1) == '<') &&  (*ep_ == '>')) {
-                       
-                       /* the informative part of the email address (describing the name
-                        * of the email address owner) may contain quoted parts. the
-                        * closure stack stores the last encountered quotes. */
-                       gchar   closure_stack[128];
-                       gchar   *ptr = closure_stack;
-#define FULL_STACK()   ((size_t) (ptr - closure_stack) >= sizeof closure_stack) 
-#define IN_STACK()             (ptr > closure_stack)
+       if (bp_ - 1 <= start || *(bp_ - 1) != '<' || *ep_ != '>')
+               return TRUE;
+
+#define FULL_STACK()   ((size_t) (ptr - closure_stack) >= sizeof closure_stack)
+#define IN_STACK()     (ptr > closure_stack)
 /* has underrun check */
-#define POP_STACK()            if(IN_STACK()) --ptr            
+#define POP_STACK()    if(IN_STACK()) --ptr
 /* has overrun check */
-#define PUSH_STACK(c)  if(!FULL_STACK()) *ptr++ = (c); else return TRUE 
+#define PUSH_STACK(c)  if(!FULL_STACK()) *ptr++ = (c); else return TRUE
 /* has underrun check */
 #define PEEK_STACK()   (IN_STACK() ? *(ptr - 1) : 0)
 
-                       ep_++;
-
-                       /* scan for the informative part. */
-                       
-                       for (bp_ -= 2; bp_ >= start; bp_--) {
-                               /* if closure on the stack keep scanning */
-                               if (PEEK_STACK() == *bp_) {
-                                       POP_STACK();
-                               }                                       
-                               else {
-                                       if (*bp_ == '\'' || *bp_ == '"')  {
-                                               PUSH_STACK(*bp_);
-                                       }                                               
-                                       else {
-                                               /* if nothing in the closure stack, do the special conditions
-                                                * the following if..else expression simply checks whether 
-                                                * a token is acceptable. if not acceptable, the clause
-                                                * should terminate the loop with a 'break' */
-                                               if (!PEEK_STACK()) {
-                                                       if ( *bp_ == '-' 
-                                                       &&   (((bp_ - 1) >= start) && isalnum(*(bp_ - 1))) 
-                                                       &&   (((bp_ + 1) < ep_)    && isalnum(*(bp_ + 1))) ) {
-                                                               /* hyphens are allowed, but only in between alnums */
-                                                       }
-                                                       else if ( !ispunct(*bp_) ) {
-                                                               /* but anything not being a punctiation is ok */
-                                                       }
-                                                       else {
-                                                               break; /* anything else is rejected */
-                                                       }
-                                               }
-                                       }
-                               }
+       ep_++;
+
+       /* scan for the informative part. */
+       for (bp_ -= 2; bp_ >= start; bp_--) {
+               /* if closure on the stack keep scanning */
+               if (PEEK_STACK() == *bp_) {
+                       POP_STACK();
+                       continue;
+               }
+               if (*bp_ == '\'' || *bp_ == '"') {
+                       PUSH_STACK(*bp_);
+                       continue;
+               }
+
+               /* if nothing in the closure stack, do the special conditions
+                * the following if..else expression simply checks whether 
+                * a token is acceptable. if not acceptable, the clause
+                * should terminate the loop with a 'break' */
+               if (!PEEK_STACK()) {
+                       if (*bp_ == '-'
+                       && (((bp_ - 1) >= start) && isalnum(*(bp_ - 1)))
+                       && (((bp_ + 1) < ep_)    && isalnum(*(bp_ + 1)))) {
+                               /* hyphens are allowed, but only in
+                                  between alnums */
+                       } else if (!ispunct(*bp_)) {
+                               /* but anything not being a punctiation
+                                  is ok */
+                       } else {
+                               break; /* anything else is rejected */
                        }
-                       
-                       bp_++;
+               }
+       }
+
+       bp_++;
 
 #undef PEEK_STACK
 #undef PUSH_STACK
@@ -577,14 +578,13 @@ static gboolean get_email_part(const gchar *start, const gchar *scanpos,
 #undef IN_STACK
 #undef FULL_STACK
 
-                       /* scan forward (should start with an alnum) */
-                       for (; *bp_ != '<' && isspace(*bp_) && *bp_ != '"'; bp_++)
-                               ;
+       /* scan forward (should start with an alnum) */
+       for (; *bp_ != '<' && isspace(*bp_) && *bp_ != '"'; bp_++)
+               ;
+
+       *ep = ep_;
+       *bp = bp_;
 
-                       *ep = ep_;
-                       *bp = bp_;
-               }
-       }
        return result;
 }