~ubuntu-branches/ubuntu/quantal/kdepimlibs/quantal-proposed

« back to all changes in this revision

Viewing changes to kmime/kmime_headers.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2011-07-08 00:32:40 UTC
  • mfrom: (1.1.63 upstream)
  • Revision ID: package-import@ubuntu.com-20110708003240-0gzufcu25rui82r1
Tags: 4:4.6.90-0ubuntu1
* New upstream release candidate
  - Bump build-dep on libakonadi-dev
  - update install files with new library versions
  - update libkcal4.install
  - refresh libakonadi-kde4.symbols, libkcalcore4.symbols,
    libkholidays4.symbols and libkimap4.symbols
  - exclude kde-runtime not kdebase-runtime in rules.
  - Update Vcs links for new location

Show diffs side-by-side

added added

removed removed

Lines of Context:
995
995
{
996
996
  Q_D(Ident);
997
997
  d->msgIdList.clear();
 
998
  d->cachedIdentifier.clear();
998
999
}
999
1000
 
1000
1001
bool Ident::isEmpty() const
1013
1014
  // msg-id   := angle-addr
1014
1015
 
1015
1016
  d->msgIdList.clear();
 
1017
  d->cachedIdentifier.clear();
1016
1018
 
1017
1019
  while ( scursor != send ) {
1018
1020
    eatCFWS( scursor, send, isCRLF );
1087
1089
  if ( d_func()->msgIdList.isEmpty() ) {
1088
1090
    return QByteArray();
1089
1091
  }
1090
 
  const Types::AddrSpec &addr = d_func()->msgIdList.first();
1091
 
  return addr.asString().toLatin1(); // FIXME change parsing to create QByteArrays
 
1092
 
 
1093
  if ( d_func()->cachedIdentifier.isEmpty() ) {
 
1094
    const Types::AddrSpec &addr = d_func()->msgIdList.first();
 
1095
    d_func()->cachedIdentifier = addr.asString().toLatin1(); // FIXME change parsing to create QByteArrays
 
1096
  }
 
1097
 
 
1098
  return d_func()->cachedIdentifier;
1092
1099
}
1093
1100
 
1094
1101
void SingleIdent::setIdentifier( const QByteArray &id )
1095
1102
{
1096
1103
  Q_D(SingleIdent);
1097
1104
  d->msgIdList.clear();
 
1105
  d->cachedIdentifier.clear();
1098
1106
  appendIdentifier( id );
1099
1107
}
1100
1108
 
1694
1702
  Q_D(ContentType);
1695
1703
  d->category = CCsingle;
1696
1704
  d->mimeType.clear();
1697
 
  d->mimeSubType.clear();
1698
1705
  Parametrized::clear();
1699
1706
}
1700
1707
 
1720
1727
QByteArray ContentType::mimeType() const
1721
1728
{
1722
1729
  Q_D(const ContentType);
1723
 
  QByteArray mt;
1724
 
  mt.reserve( d->mimeType.size() + d->mimeSubType.size() + 1 );
1725
 
  mt.append( d->mimeType );
1726
 
  mt.append( '/' );
1727
 
  mt.append( d->mimeSubType );
1728
 
  return mt;
 
1730
  return d->mimeType;
1729
1731
}
1730
1732
 
1731
1733
QByteArray ContentType::mediaType() const
1732
1734
{
1733
 
  return d_func()->mimeType;
 
1735
  Q_D(const ContentType);
 
1736
  const int pos = d->mimeType.indexOf( '/' );
 
1737
  if ( pos < 0 )
 
1738
    return d->mimeType;
 
1739
  else
 
1740
    return d->mimeType.left( pos );
1734
1741
}
1735
1742
 
1736
1743
QByteArray ContentType::subType() const
1737
1744
{
1738
 
  return d_func()->mimeSubType;
 
1745
  Q_D(const ContentType);
 
1746
  const int pos = d->mimeType.indexOf( '/' );
 
1747
  if ( pos < 0 )
 
1748
    return QByteArray();
 
1749
  else
 
1750
    return d->mimeType.mid( pos + 1);
1739
1751
}
1740
1752
 
1741
1753
void ContentType::setMimeType( const QByteArray &mimeType )
1742
1754
{
1743
1755
  Q_D(ContentType);
1744
 
  int pos = mimeType.indexOf( '/' );
1745
 
  if ( pos < 0 ) {
1746
 
    d->mimeType = mimeType;
1747
 
    d->mimeSubType.clear();
1748
 
  } else {
1749
 
    d->mimeType = mimeType.left( pos );
1750
 
    d->mimeSubType = mimeType.mid( pos + 1 );
1751
 
  }
 
1756
  d->mimeType = mimeType;
1752
1757
  Parametrized::clear();
1753
1758
 
1754
1759
  if ( isMultipart() ) {
1760
1765
 
1761
1766
bool ContentType::isMediatype( const char *mediatype ) const
1762
1767
{
1763
 
  return strncasecmp( mediaType().constData(), mediatype, strlen( mediatype ) ) == 0;
 
1768
  Q_D(const ContentType);
 
1769
  const int len = strlen( mediatype );
 
1770
  return strncasecmp( d->mimeType.constData(), mediatype, len ) == 0 && (d->mimeType.at(len) == '/' || d->mimeType.size() == len);
1764
1771
}
1765
1772
 
1766
1773
bool ContentType::isSubtype( const char *subtype ) const
1767
1774
{
1768
 
  return strncasecmp( subType().constData(), subtype, strlen( subtype ) ) == 0;
 
1775
  Q_D(const ContentType);
 
1776
  const int pos = d->mimeType.indexOf( '/' );
 
1777
  if ( pos < 0 )
 
1778
    return false;
 
1779
  const int len = strlen( subtype );
 
1780
  return strncasecmp( d->mimeType.constData() + pos + 1, subtype, len ) == 0 && d->mimeType.size() == pos + len + 1;
1769
1781
}
1770
1782
 
1771
1783
bool ContentType::isText() const
1772
1784
{
1773
 
  return ( strncasecmp( mediaType().constData(), "text", 4 ) == 0
1774
 
          || isEmpty() );
 
1785
  return ( isMediatype( "text" ) || isEmpty() );
1775
1786
}
1776
1787
 
1777
1788
bool ContentType::isPlainText() const
1778
1789
{
1779
 
  return ( strcasecmp( mimeType().constData(), "text/plain" ) == 0
1780
 
          || isEmpty() );
 
1790
  return ( strcasecmp( d_func()->mimeType.constData(), "text/plain" ) == 0 || isEmpty() );
1781
1791
}
1782
1792
 
1783
1793
bool ContentType::isHTMLText() const
1784
1794
{
1785
 
  return strcasecmp( mimeType().constData(), "text/html" ) == 0;
 
1795
  return strcasecmp( d_func()->mimeType.constData(), "text/html" ) == 0;
1786
1796
}
1787
1797
 
1788
1798
bool ContentType::isImage() const
1789
1799
{
1790
 
  return strncasecmp( mediaType().constData(), "image", 5 ) == 0;
 
1800
  return isMediatype( "image" );
1791
1801
}
1792
1802
 
1793
1803
bool ContentType::isMultipart() const
1794
1804
{
1795
 
  return strncasecmp( mediaType().constData(), "multipart", 9 ) == 0;
 
1805
  return isMediatype( "multipart" );
1796
1806
}
1797
1807
 
1798
1808
bool ContentType::isPartial() const
1799
1809
{
1800
 
  return strcasecmp( mimeType().constData(), "message/partial" ) == 0;
 
1810
  return strcasecmp( d_func()->mimeType.constData(), "message/partial" ) == 0;
1801
1811
}
1802
1812
 
1803
1813
QByteArray ContentType::charset() const
1901
1911
  if ( !parseToken( scursor, send, maybeMimeType, false /* no 8Bit */ ) ) {
1902
1912
    return false;
1903
1913
  }
1904
 
  d->mimeType = QByteArray( maybeMimeType.first, maybeMimeType.second ).toLower();
1905
1914
 
1906
1915
  // subtype
1907
1916
  eatCFWS( scursor, send, isCRLF );
1918
1927
  if ( !parseToken( scursor, send, maybeSubType, false /* no 8bit */ ) ) {
1919
1928
    return false;
1920
1929
  }
1921
 
  d->mimeSubType = QByteArray( maybeSubType.first, maybeSubType.second ).toLower();
 
1930
 
 
1931
  d->mimeType.reserve( maybeMimeType.second + maybeSubType.second + 1 );
 
1932
  d->mimeType = QByteArray( maybeMimeType.first, maybeMimeType.second ).toLower()
 
1933
                + '/' + QByteArray( maybeSubType.first, maybeSubType.second ).toLower();
1922
1934
 
1923
1935
  // parameter list
1924
1936
  eatCFWS( scursor, send, isCRLF );
1963
1975
  {
1964
1976
    scursor = origscursor;
1965
1977
    d->msgIdList.clear();
 
1978
    d->cachedIdentifier.clear();
1966
1979
 
1967
1980
    while ( scursor != send )
1968
1981
    {